@@ -329,8 +329,12 @@ public function generate_signature( $attachment_id ) {
329329 if ( ! $ sql ) {
330330 $ sql = Utils::get_table_sql ();
331331 }
332+ $ public_id = null ;
333+ $ relationship = Relationship::get_relationship ( $ attachment_id );
334+ if ( $ relationship instanceof Relationship ) {
335+ $ public_id = $ relationship ->public_id ;
336+ }
332337 $ sizes = $ this ->get_sized ( $ attachment_id );
333- $ public_id = $ this ->media ->has_public_id ( $ attachment_id ) ? $ this ->media ->get_public_id ( $ attachment_id ) : null ;
334338 $ settings_signature = self ::get_settings_signature ();
335339 $ relation_signature = $ this ->media ->get_post_meta ( $ attachment_id , Sync::META_KEYS ['relationship ' ], true );
336340
@@ -480,8 +484,6 @@ public function unsync_size_relationship( $attachment_id ) {
480484 self ::update_size_relations_public_id ( $ attachment_id , null );
481485 self ::update_size_relations_state ( $ attachment_id , 'disable ' );
482486 self ::update_size_relations_transformations ( $ attachment_id , null );
483-
484- do_action ( 'cloudinary_flush_cache ' );
485487 }
486488
487489 /**
@@ -521,12 +523,13 @@ public function get_sized( $attachment_id ) {
521523 */
522524 public static function update_size_relations_public_id ( $ attachment_id , $ public_id ) {
523525 $ relationship = Relationship::get_relationship ( $ attachment_id );
524- $ relationship ->public_id = $ public_id ;
525- $ relationship ->public_hash = md5 ( $ public_id );
526- $ relationship ->signature = self ::get_settings_signature ();
527- $ relationship ->save ();
528526
529- do_action ( 'cloudinary_flush_cache ' );
527+ if ( $ relationship instanceof Relationship ) {
528+ $ relationship ->public_id = $ public_id ;
529+ $ relationship ->public_hash = md5 ( $ public_id );
530+ $ relationship ->signature = self ::get_settings_signature ();
531+ $ relationship ->save ();
532+ }
530533 }
531534
532535 /**
@@ -537,8 +540,11 @@ public static function update_size_relations_public_id( $attachment_id, $public_
537540 */
538541 public static function update_size_relations_state ( $ attachment_id , $ state ) {
539542 $ relationship = Relationship::get_relationship ( $ attachment_id );
540- $ relationship ->post_state = $ state ;
541- $ relationship ->save ();
543+
544+ if ( $ relationship instanceof Relationship ) {
545+ $ relationship ->post_state = $ state ;
546+ $ relationship ->save ();
547+ }
542548
543549 do_action ( 'cloudinary_flush_cache ' );
544550 }
@@ -551,7 +557,6 @@ public static function update_size_relations_state( $attachment_id, $state ) {
551557 */
552558 public static function update_size_relations_transformations ( $ attachment_id , $ transformations ) {
553559 Relate::update_transformations ( $ attachment_id , $ transformations );
554- do_action ( 'cloudinary_flush_cache ' );
555560 }
556561
557562 /**
@@ -700,11 +705,16 @@ public function clear_cache() {
700705 /**
701706 * Delete cached metadata.
702707 *
708+ * @param bool $hard Whether to hard flush the cache.
709+ *
703710 * @hook cloudinary_flush_cache
704711 */
705- public function do_clear_cache () {
712+ public function do_clear_cache ( $ hard = true ) {
706713 delete_post_meta_by_key ( self ::META_CACHE_KEY );
707- wp_cache_flush ();
714+
715+ if ( $ hard ) {
716+ wp_cache_flush ();
717+ }
708718 }
709719
710720 /**
0 commit comments