From a5375d390d5a7a83eb0e0ac9c00ad6b9b5815e0a Mon Sep 17 00:00:00 2001 From: David Cramer Date: Fri, 6 Mar 2020 05:06:08 +0200 Subject: [PATCH 1/2] version bump --- .../cloudinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php index 4ada51137..a036384a1 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php @@ -3,7 +3,7 @@ * Plugin Name: Cloudinary * Plugin URI: https://cloudinary.com/documentation/wordpress_integration * 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. - * Version: 2.0.0-RC1 + * Version: 2.0.0 * Author: Cloudinary Ltd., XWP * Author URI: https://cloudinary.com/ * License: GPLv2+ From 63a97508ce4c0e03c715f95d8344fda394e2d7b1 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 19 Mar 2020 06:17:15 +0200 Subject: [PATCH 2/2] do a content search and update after up sync --- .../php/class-media.php | 4 ++-- .../php/media/class-filter.php | 13 +++++++++---- .../php/sync/class-push-sync.php | 8 ++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index 4260283d3..3c654d76c 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -216,7 +216,7 @@ public function get_id_from_sync_key( $sync_key ) { $meta_query = array( array( - 'key' => md5( $sync_key ), + 'key' => '_' . md5( $sync_key ), 'compare' => 'EXISTS', ), ); @@ -946,7 +946,7 @@ private function create_attachment( $asset, $public_id ) { update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] ); } // create a trackable key in post meta. - update_post_meta( $attachment_id, md5( $sync_key ), true ); + update_post_meta( $attachment_id, '_' . md5( $sync_key ), true ); // record a base to ensure primary isn't deleted. update_post_meta( $attachment_id, '_' . md5( $public_id ), true ); // Capture the ALT Text. diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php index 306137dc2..e225300d0 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php @@ -290,14 +290,19 @@ public function filter_out_local( $content ) { $assets = $this->get_media_tags( $content, 'img' ); foreach ( $assets as $asset ) { - $url = $this->get_url_from_tag( $asset ); + $url = $this->get_url_from_tag( $asset ); + $attachment_id = $this->get_id_from_tag( $asset ); // Check if this is not already a cloudinary url. if ( $this->media->is_cloudinary_url( $url ) ) { - continue; // Already a cloudinary URL. Possibly from a previous version. Will correct on post update. - } + // Is a content based ID. If has a cloudinary ID, it's from an older plugin version. + // Check if has an ID, and push update to reset. + if ( ! empty( $attachment_id ) && ! $this->media->plugin->components['sync']->is_synced( $attachment_id ) ) { + $this->media->cloudinary_id( $attachment_id ); // Start an on-demand sync. + } - $attachment_id = $this->get_id_from_tag( $asset ); + continue; // Already a cloudinary URL. Possibly from a previous version. Will correct on post update after synced. + } if ( false === $attachment_id ) { $attachment_id = $this->media->get_id_from_url( $url ); diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php index 9c54f27dc..fe98e4448 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php @@ -578,6 +578,14 @@ public function push_attachments( $attachments ) { $meta = wp_get_attachment_metadata( $attachment->ID, true ); $meta[ Sync::META_KEYS['cloudinary'] ] = $meta_data; wp_update_attachment_metadata( $attachment->ID, $meta ); + // Search and update link references in content. + $content_search = new \WP_Query( array( 's' => 'wp-image-' . $attachment->ID, 'fields' => 'ids', 'posts_per_page' => 1000 ) ); + if ( ! empty( $content_search->found_posts ) ) { + $content_posts = array_unique( $content_search->get_posts() ); // ensure post only gets updated once. + foreach ( $content_posts as $content_id ) { + wp_update_post( array( 'ID' => $content_id ) ); // Trigger an update, internal filters will filter out remote URLS. + } + } } $stats['processed'] += 1;