Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
);
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down