@@ -156,7 +156,7 @@ protected function register_hooks() {
156156		add_filter ( 'cloudinary_asset_state ' , array ( $ this 'filter_asset_state '  ), 10 , 2  );
157157		add_filter ( 'cloudinary_set_usable_asset ' , array ( $ this 'check_usable_asset '  ) );
158158		// Actions. 
159- 		add_action ( 'cloudinary_init_settings ' , array ( $ this 'setup '  ) );
159+ 		add_action ( 'cloudinary_ready ' , array ( $ this 'setup '  ) );
160160		add_action ( 'cloudinary_thread_queue_details_query ' , array ( $ this 'connect_post_type '  ) );
161161		add_action ( 'cloudinary_build_queue_query ' , array ( $ this 'connect_post_type '  ) );
162162		add_action ( 'cloudinary_string_replace ' , array ( $ this 'add_url_replacements '  ), 20  );
@@ -441,6 +441,7 @@ public function update_asset_paths() {
441441					// Check and update version if needed. 
442442					if  ( $ this media ->get_post_meta ( $ asset_pathID , Sync::META_KEYS ['version ' ], true  ) !== $ version
443443						$ this media ->update_post_meta ( $ asset_pathID , Sync::META_KEYS ['version ' ], $ version
444+ 						$ this sync_parent ( $ asset_pathID  );
444445					}
445446				}
446447			}
@@ -538,11 +539,12 @@ public function create_asset_parent( $path, $version ) {
538539	}
539540
540541	/** 
541- 	 * Purge a single asset  parent. 
542+ 	 * Process all child assets of a  parent with a given callback . 
542543	 * 
543- 	 * @param int $parent_id The Asset parent to purge. 
544+ 	 * @param int      $parent_id The Asset parent to process. 
545+ 	 * @param callable $callback  The callback function to execute on each post. 
544546	 */ 
545- 	public  function  purge_parent ( $ parent_id
547+ 	private  function  process_parent_assets ( $ parent_id,  $ callback 
546548		$ query_argsarray (
547549			'post_type '               => self ::POST_TYPE_SLUG ,
548550			'posts_per_page '          => 100 ,
@@ -554,11 +556,13 @@ public function purge_parent( $parent_id ) {
554556		);
555557		$ querynew  \WP_Query ( $ query_args
556558		$ previous_total$ queryfound_posts ;
559+ 
557560		do  {
558561			$ this lock_assets ();
559562			$ posts$ queryget_posts ();
563+ 
560564			foreach  ( $ postsas  $ post_id
561- 				wp_delete_post (  $ post_id
565+ 				call_user_func (  $ callback ,  $ post_id
562566			}
563567
564568			$ query_args$ queryquery_vars ;
@@ -569,6 +573,40 @@ public function purge_parent( $parent_id ) {
569573		} while  ( $ queryhave_posts () );
570574	}
571575
576+ 	/** 
577+ 	 * Sync the assets of a parent. 
578+ 	 * 
579+ 	 * @param int $parent_id The Asset parent to sync. 
580+ 	 */ 
581+ 	public  function  sync_parent ( $ parent_id
582+ 		$ this process_parent_assets (
583+ 			$ parent_id
584+ 			function  ( $ post_id
585+ 				if  ( empty ( $ this media ->sync  ) || ! $ this media ->sync ->can_sync ( $ post_id
586+ 					return ;
587+ 				}
588+ 
589+ 				$ this media ->sync ->set_signature_item ( $ post_id'file ' , ''  );
590+ 				$ this media ->sync ->set_signature_item ( $ post_id'cld_asset '  );
591+ 				$ this media ->sync ->add_to_sync ( $ post_id
592+ 			}
593+ 		);
594+ 	}
595+ 
596+ 	/** 
597+ 	 * Purge a single asset parent. 
598+ 	 * 
599+ 	 * @param int $parent_id The Asset parent to purge. 
600+ 	 */ 
601+ 	public  function  purge_parent ( $ parent_id
602+ 		$ this process_parent_assets (
603+ 			$ parent_id
604+ 			function  ( $ post_id
605+ 				wp_delete_post ( $ post_id
606+ 			}
607+ 		);
608+ 	}
609+ 
572610	/** 
573611	 * Lock asset creation for performing things like purging that require no changes. 
574612	 */ 
0 commit comments