Skip to content

Commit 3c6a695

Browse files
committed
check if is synced
1 parent 1bdffcc commit 3c6a695

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

php/class-delivery.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Cloudinary\Component\Setup;
1111
use Cloudinary\Media\Filter;
1212
use Cloudinary\Media\Global_Transformations;
13+
use \Cloudinary\Sync;
1314
use Cloudinary\String_Replace;
1415
use Cloudinary\UI\Component\HTML;
1516
use WP_Post;
@@ -40,6 +41,13 @@ class Delivery implements Setup {
4041
*/
4142
protected $filter;
4243

44+
/**
45+
* Holds the Sync component.
46+
*
47+
* @var Sync
48+
*/
49+
protected $sync;
50+
4351
/**
4452
* The meta data cache key to store URLS.
4553
*
@@ -79,6 +87,8 @@ public function clear_cache() {
7987
*/
8088
public function setup() {
8189
$this->filter = $this->media->filter;
90+
$this->sync = $this->media->sync;
91+
8292
// Add filters.
8393
add_action( 'save_post', array( $this, 'remove_replace_cache' ) );
8494
add_action( 'cloudinary_string_replace', array( $this, 'catch_urls' ) );
@@ -177,7 +187,9 @@ public function find_attachment_size_urls( $urls ) {
177187
$results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
178188
if ( $results ) {
179189
foreach ( $results as $result ) {
180-
$found = array_merge( $found, $this->get_attachment_size_urls( $result->post_id ) );
190+
if ( $this->sync->is_synced( $result->post_id ) ) {
191+
$found = array_merge( $found, $this->get_attachment_size_urls( $result->post_id ) );
192+
}
181193
}
182194
}
183195
$cached = $found;
@@ -208,7 +220,7 @@ public function convert_tags( $content ) {
208220
$attachment_ids = array();
209221
foreach ( $tags as $element ) {
210222
$attachment_id = $this->filter->get_id_from_tag( $element );
211-
if ( empty( $attachment_id ) ) {
223+
if ( empty( $attachment_id ) || ! $this->sync->is_synced( $attachment_id ) ) {
212224
continue;
213225
}
214226
// Register replacement.

0 commit comments

Comments
 (0)