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 feb8cf906..af7d1a8a7 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.2.0
+ * Version: 2.2.1
* Author: Cloudinary Ltd., XWP
* Author URI: https://cloudinary.com/
* License: GPLv2+
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 7cf4a4dde..84e49ac7f 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
@@ -1726,7 +1726,7 @@ public function get_upload_options( $attachment_id ) {
*/
public function maybe_overwrite_featured_image( $attachment_id ) {
$overwrite = false;
- if ( $this->doing_featured_image && $this->doing_featured_image === $attachment_id ) {
+ if ( $this->doing_featured_image && $this->doing_featured_image === (int) $attachment_id ) {
$overwrite = (bool) $this->get_post_meta( get_the_ID(), Global_Transformations::META_FEATURED_IMAGE_KEY, true );
}
@@ -1740,7 +1740,7 @@ public function maybe_overwrite_featured_image( $attachment_id ) {
* @param int $attachment_id The thumbnail ID.
*/
public function set_doing_featured( $post_id, $attachment_id ) {
- $this->doing_featured_image = $attachment_id;
+ $this->doing_featured_image = (int) $attachment_id;
add_action( 'end_fetch_post_thumbnail_html', function () {
$this->doing_featured_image = false;
} );
@@ -1812,7 +1812,7 @@ public function setup() {
* @return array
*/
public function match_file_name_with_cloudinary_source( $image_meta, $attachment_id ) {
- if ( $this->has_public_id( $attachment_id ) ) {
+ if ( ! empty( $image_meta['file'] ) && $this->has_public_id( $attachment_id ) ) {
$cld_file = 'v' . $this->get_cloudinary_version( $attachment_id ) . '/' . $this->get_cloudinary_id( $attachment_id );
if ( false === strpos( $image_meta['file'], $cld_file ) ) {
$image_meta['file'] = $cld_file;
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 dcd9ee20a..580a87644 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
@@ -548,6 +548,19 @@ public function pre_filter_rest_content( $response, $post, $request ) {
$content = $data['content']['raw'];
$data['content']['raw'] = $this->filter_out_local( $content );
+ // Handle meta if missing due to custom-fields not being supported.
+ if ( ! isset( $data['meta'] ) ) {
+ $data['meta'] = $request->get_param( 'meta' );
+ if ( null === $data['meta'] ) {
+ // If null, meta param doesn't exist, so it's not a save edit, but a load edit.
+ $disable = get_post_meta( $post->ID, Global_Transformations::META_FEATURED_IMAGE_KEY, true );
+ // Add the value to the data meta.
+ $data['meta'][ Global_Transformations::META_FEATURED_IMAGE_KEY ] = $disable;
+ } else {
+ // If the param was found, its a save edit, to update the meta data.
+ update_post_meta( $post->ID, Global_Transformations::META_FEATURED_IMAGE_KEY, (bool) $data['meta'][ Global_Transformations::META_FEATURED_IMAGE_KEY ] );
+ }
+ }
$response->set_data( $data );
}
@@ -692,6 +705,24 @@ public function filter_image_block_pre_render( $block, $source_block ) {
return $block;
}
+
+ /**
+ * Add filters for Rest API handling.
+ */
+ public function init_rest_filters() {
+ // Gutenberg compatibility.
+ add_filter( 'rest_prepare_attachment', array( $this, 'filter_attachment_for_rest' ) );
+ $types = get_post_types_by_support( 'editor' );
+ foreach ( $types as $type ) {
+ $post_type = get_post_type_object( $type );
+ // Check if this is a rest supported type.
+ if ( true === $post_type->show_in_rest ) {
+ // Add filter only to rest supported types.
+ add_filter( 'rest_prepare_' . $type, array( $this, 'pre_filter_rest_content' ), 10, 3 );
+ }
+ }
+ }
+
/**
* Setup hooks for the filters.
*/
@@ -710,16 +741,8 @@ public function setup_hooks() {
// Filter video codes.
add_filter( 'media_send_to_editor', array( $this, 'filter_video_embeds' ), 10, 3 );
- // Gutenberg compatibility.
- add_filter( 'rest_prepare_attachment', array( $this, 'filter_attachment_for_rest' ) );
- $types = get_post_types_by_support( 'editor' );
- $filter = $this;
- array_map(
- function ( $type ) use ( $filter ) {
- add_filter( 'rest_prepare_' . $type, array( $filter, 'pre_filter_rest_content' ), 10, 3 );
- },
- $types
- );
+ // Enable Rest filters.
+ add_action( 'rest_api_init', array( $this, 'init_rest_filters' ) );
// Remove editors to prevent users from manually editing images in WP.
add_filter( 'wp_image_editors', array( $this, 'disable_editors_maybe' ) );
diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-storage.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-storage.php
index f2bb63527..0d69186f4 100644
--- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-storage.php
+++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-storage.php
@@ -103,7 +103,10 @@ public function maybe_disable_connect( $field, $slug ) {
$field['description'] = sprintf(
// translators: Placeholders are tags.
__( 'You can’t currently change your environment variable as your storage setting is set to "Cloudinary only". Update your %1$s storage settings %2$s and sync your assets to WordPress storage to enable this setting.', 'cloudinary' ),
- '',
+ sprintf(
+ '',
+ add_query_arg( 'page', 'cld_sync_media', admin_url( 'admin.php' ) )
+ ),
''
);
$field['disabled'] = true;