Skip to content

Commit e6fd502

Browse files
author
Marco Pereirinha
committed
Filter get signature
1 parent 7c98a74 commit e6fd502

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

php/class-sync.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Cloudinary\Sync\Push_Sync;
1616
use Cloudinary\Sync\Sync_Queue;
1717
use Cloudinary\Sync\Upload_Sync;
18+
use WP_Error;
1819

1920
/**
2021
* Class Sync
@@ -298,6 +299,18 @@ public function get_signature( $attachment_id, $cached = true ) {
298299
$return = wp_parse_args( $signature, $this->sync_types );
299300
}
300301

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+
301314
return $return;
302315
}
303316

@@ -873,6 +886,23 @@ public function filter_get_cloudinary_folder( $value, $slug ) {
873886
return $value;
874887
}
875888

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+
876906
/**
877907
* Checks if auto sync feature is enabled.
878908
*
@@ -933,6 +963,7 @@ public function setup() {
933963
$this->managers['queue']->setup( $this );
934964

935965
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 );
936967
}
937968
}
938969

0 commit comments

Comments
 (0)