Skip to content

Commit 919b7ba

Browse files
author
dugajean
authored
Merge pull request #45 from cloudinary/fix/CLOUD-368
2 parents 2324221 + 63a9750 commit 919b7ba

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Cloudinary
44
* Plugin URI: https://cloudinary.com/documentation/wordpress_integration
55
* Description: With the Cloudinary plugin, you can upload and manage your media assets in the cloud, then deliver them to your users through a fast content delivery network, improving your website’s loading speed and overall user experience. Apply multiple transformations and take advantage of a full digital asset management solution without leaving WordPress.
6-
* Version: 2.0.0-RC1
6+
* Version: 2.0.0
77
* Author: Cloudinary Ltd., XWP
88
* Author URI: https://cloudinary.com/
99
* License: GPLv2+

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function get_id_from_sync_key( $sync_key ) {
216216

217217
$meta_query = array(
218218
array(
219-
'key' => md5( $sync_key ),
219+
'key' => '_' . md5( $sync_key ),
220220
'compare' => 'EXISTS',
221221
),
222222
);
@@ -946,7 +946,7 @@ private function create_attachment( $asset, $public_id ) {
946946
update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] );
947947
}
948948
// create a trackable key in post meta.
949-
update_post_meta( $attachment_id, md5( $sync_key ), true );
949+
update_post_meta( $attachment_id, '_' . md5( $sync_key ), true );
950950
// record a base to ensure primary isn't deleted.
951951
update_post_meta( $attachment_id, '_' . md5( $public_id ), true );
952952
// Capture the ALT Text.

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,19 @@ public function filter_out_local( $content ) {
290290
$assets = $this->get_media_tags( $content, 'img' );
291291
foreach ( $assets as $asset ) {
292292

293-
$url = $this->get_url_from_tag( $asset );
293+
$url = $this->get_url_from_tag( $asset );
294+
$attachment_id = $this->get_id_from_tag( $asset );
294295

295296
// Check if this is not already a cloudinary url.
296297
if ( $this->media->is_cloudinary_url( $url ) ) {
297-
continue; // Already a cloudinary URL. Possibly from a previous version. Will correct on post update.
298-
}
298+
// Is a content based ID. If has a cloudinary ID, it's from an older plugin version.
299+
// Check if has an ID, and push update to reset.
300+
if ( ! empty( $attachment_id ) && ! $this->media->plugin->components['sync']->is_synced( $attachment_id ) ) {
301+
$this->media->cloudinary_id( $attachment_id ); // Start an on-demand sync.
302+
}
299303

300-
$attachment_id = $this->get_id_from_tag( $asset );
304+
continue; // Already a cloudinary URL. Possibly from a previous version. Will correct on post update after synced.
305+
}
301306

302307
if ( false === $attachment_id ) {
303308
$attachment_id = $this->media->get_id_from_url( $url );

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,14 @@ public function push_attachments( $attachments ) {
578578
$meta = wp_get_attachment_metadata( $attachment->ID, true );
579579
$meta[ Sync::META_KEYS['cloudinary'] ] = $meta_data;
580580
wp_update_attachment_metadata( $attachment->ID, $meta );
581+
// Search and update link references in content.
582+
$content_search = new \WP_Query( array( 's' => 'wp-image-' . $attachment->ID, 'fields' => 'ids', 'posts_per_page' => 1000 ) );
583+
if ( ! empty( $content_search->found_posts ) ) {
584+
$content_posts = array_unique( $content_search->get_posts() ); // ensure post only gets updated once.
585+
foreach ( $content_posts as $content_id ) {
586+
wp_update_post( array( 'ID' => $content_id ) ); // Trigger an update, internal filters will filter out remote URLS.
587+
}
588+
}
581589
}
582590

583591
$stats['processed'] += 1;

0 commit comments

Comments
 (0)