1515use Cloudinary \Sync \Push_Sync ;
1616use Cloudinary \Sync \Sync_Queue ;
1717use Cloudinary \Sync \Upload_Sync ;
18+ use WP_Error ;
1819
1920/**
2021 * Class Sync
@@ -244,13 +245,7 @@ public function can_sync( $attachment_id, $type = 'file' ) {
244245 }
245246
246247 // Can sync only syncable delivery types.
247- if (
248- ! in_array (
249- $ this ->managers ['media ' ]->get_media_delivery ( $ attachment_id ),
250- $ this ->managers ['media ' ]->get_syncable_delivery_types (),
251- true
252- )
253- ) {
248+ if ( ! $ this ->is_syncable ( $ attachment_id ) ) {
254249 $ can = false ;
255250 }
256251
@@ -304,6 +299,18 @@ public function get_signature( $attachment_id, $cached = true ) {
304299 $ return = wp_parse_args ( $ signature , $ this ->sync_types );
305300 }
306301
302+ /**
303+ * Filter the get signature of the asset.
304+ *
305+ * @hook cloudinary_get_signature
306+ *
307+ * @param $signature {array} The attachment signature.
308+ * @param $attachment_id {int} The attachment ID.
309+ *
310+ * @return {array}
311+ */
312+ $ return = apply_filters ( 'cloudinary_get_signature ' , $ signatures [ $ attachment_id ], $ attachment_id );
313+
307314 return $ return ;
308315 }
309316
@@ -328,6 +335,29 @@ public function generate_public_id( $attachment_id ) {
328335 return ltrim ( $ public_id , '/ ' );
329336 }
330337
338+ /**
339+ * Is syncable asset.
340+ *
341+ * @param int $attachment_id The attachment ID.
342+ *
343+ * @return bool
344+ */
345+ public function is_syncable ( $ attachment_id ) {
346+ $ syncable = false ;
347+ if (
348+ $ this ->managers ['media ' ]->is_media ( $ attachment_id )
349+ && in_array (
350+ $ this ->managers ['media ' ]->get_media_delivery ( $ attachment_id ),
351+ $ this ->managers ['media ' ]->get_syncable_delivery_types (),
352+ true
353+ )
354+ ) {
355+ $ syncable = true ;
356+ }
357+
358+ return $ syncable ;
359+ }
360+
331361 /**
332362 * Register a new sync type.
333363 *
@@ -856,6 +886,23 @@ public function filter_get_cloudinary_folder( $value, $slug ) {
856886 return $ value ;
857887 }
858888
889+ /**
890+ * Filter the signature.
891+ *
892+ * @param array $signature The signature array.
893+ * @param int $attachment_id The attachment ID.
894+ *
895+ * @return array|bool|string|WP_Error
896+ */
897+ public function get_signature_syncable_type ( $ signature , $ attachment_id ) {
898+
899+ if ( ! $ this ->is_syncable ( $ attachment_id ) ) {
900+ $ signature = $ this ->generate_signature ( $ attachment_id );
901+ }
902+
903+ return $ signature ;
904+ }
905+
859906 /**
860907 * Checks if auto sync feature is enabled.
861908 *
@@ -916,6 +963,7 @@ public function setup() {
916963 $ this ->managers ['queue ' ]->setup ( $ this );
917964
918965 add_filter ( 'cloudinary_setting_get_value ' , array ( $ this , 'filter_get_cloudinary_folder ' ), 10 , 2 );
966+ add_filter ( 'cloudinary_get_signature ' , array ( $ this , 'get_signature_syncable_type ' ), 10 , 2 );
919967 }
920968 }
921969
0 commit comments