From 3c6a695dc7b83337596df7c28fc7f05db2b0a504 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Fri, 18 Jun 2021 10:51:49 +0200 Subject: [PATCH 1/2] check if is synced --- php/class-delivery.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index fc999708d..effaa2b55 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -10,6 +10,7 @@ use Cloudinary\Component\Setup; use Cloudinary\Media\Filter; use Cloudinary\Media\Global_Transformations; +use \Cloudinary\Sync; use Cloudinary\String_Replace; use Cloudinary\UI\Component\HTML; use WP_Post; @@ -40,6 +41,13 @@ class Delivery implements Setup { */ protected $filter; + /** + * Holds the Sync component. + * + * @var Sync + */ + protected $sync; + /** * The meta data cache key to store URLS. * @@ -79,6 +87,8 @@ public function clear_cache() { */ public function setup() { $this->filter = $this->media->filter; + $this->sync = $this->media->sync; + // Add filters. add_action( 'save_post', array( $this, 'remove_replace_cache' ) ); add_action( 'cloudinary_string_replace', array( $this, 'catch_urls' ) ); @@ -177,7 +187,9 @@ public function find_attachment_size_urls( $urls ) { $results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared if ( $results ) { foreach ( $results as $result ) { - $found = array_merge( $found, $this->get_attachment_size_urls( $result->post_id ) ); + if ( $this->sync->is_synced( $result->post_id ) ) { + $found = array_merge( $found, $this->get_attachment_size_urls( $result->post_id ) ); + } } } $cached = $found; @@ -208,7 +220,7 @@ public function convert_tags( $content ) { $attachment_ids = array(); foreach ( $tags as $element ) { $attachment_id = $this->filter->get_id_from_tag( $element ); - if ( empty( $attachment_id ) ) { + if ( empty( $attachment_id ) || ! $this->sync->is_synced( $attachment_id ) ) { continue; } // Register replacement. From 9081e4b92a249a8937ba4cb5ad61e578a8b621bc Mon Sep 17 00:00:00 2001 From: David Cramer Date: Fri, 18 Jun 2021 12:18:27 +0200 Subject: [PATCH 2/2] cleanup --- php/class-delivery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index effaa2b55..67b65fb4a 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -10,7 +10,7 @@ use Cloudinary\Component\Setup; use Cloudinary\Media\Filter; use Cloudinary\Media\Global_Transformations; -use \Cloudinary\Sync; +use Cloudinary\Sync; use Cloudinary\String_Replace; use Cloudinary\UI\Component\HTML; use WP_Post;