Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions php/class-delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +41,13 @@ class Delivery implements Setup {
*/
protected $filter;

/**
* Holds the Sync component.
*
* @var Sync
*/
protected $sync;

/**
* Hold the Post ID.
*
Expand Down Expand Up @@ -118,6 +126,8 @@ public function get_current_post_id() {
*/
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' ) );
Expand Down Expand Up @@ -218,7 +228,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;
Expand Down Expand Up @@ -251,7 +263,7 @@ public function convert_tags( $content ) {
$attachment_id = $this->filter->get_id_from_tag( $element );
$this->current_post_id = $this->filter->get_id_from_tag( $element, 'wp-post-' );

if ( empty( $attachment_id ) ) {
if ( empty( $attachment_id ) || ! $this->sync->is_synced( $attachment_id ) ) {
continue;
}
// Register replacement.
Expand Down