Skip to content

Commit 6238ad4

Browse files
authored
Merge pull request #206 from cloudinary/hotfix/v2.2.1
Hotfix/v2.2.1
2 parents 2f95c30 + 442f9de commit 6238ad4

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
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.2.0
6+
* Version: 2.2.1
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ public function get_upload_options( $attachment_id ) {
17261726
*/
17271727
public function maybe_overwrite_featured_image( $attachment_id ) {
17281728
$overwrite = false;
1729-
if ( $this->doing_featured_image && $this->doing_featured_image === $attachment_id ) {
1729+
if ( $this->doing_featured_image && $this->doing_featured_image === (int) $attachment_id ) {
17301730
$overwrite = (bool) $this->get_post_meta( get_the_ID(), Global_Transformations::META_FEATURED_IMAGE_KEY, true );
17311731
}
17321732

@@ -1740,7 +1740,7 @@ public function maybe_overwrite_featured_image( $attachment_id ) {
17401740
* @param int $attachment_id The thumbnail ID.
17411741
*/
17421742
public function set_doing_featured( $post_id, $attachment_id ) {
1743-
$this->doing_featured_image = $attachment_id;
1743+
$this->doing_featured_image = (int) $attachment_id;
17441744
add_action( 'end_fetch_post_thumbnail_html', function () {
17451745
$this->doing_featured_image = false;
17461746
} );
@@ -1812,7 +1812,7 @@ public function setup() {
18121812
* @return array
18131813
*/
18141814
public function match_file_name_with_cloudinary_source( $image_meta, $attachment_id ) {
1815-
if ( $this->has_public_id( $attachment_id ) ) {
1815+
if ( ! empty( $image_meta['file'] ) && $this->has_public_id( $attachment_id ) ) {
18161816
$cld_file = 'v' . $this->get_cloudinary_version( $attachment_id ) . '/' . $this->get_cloudinary_id( $attachment_id );
18171817
if ( false === strpos( $image_meta['file'], $cld_file ) ) {
18181818
$image_meta['file'] = $cld_file;

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,19 @@ public function pre_filter_rest_content( $response, $post, $request ) {
548548
$content = $data['content']['raw'];
549549
$data['content']['raw'] = $this->filter_out_local( $content );
550550

551+
// Handle meta if missing due to custom-fields not being supported.
552+
if ( ! isset( $data['meta'] ) ) {
553+
$data['meta'] = $request->get_param( 'meta' );
554+
if ( null === $data['meta'] ) {
555+
// If null, meta param doesn't exist, so it's not a save edit, but a load edit.
556+
$disable = get_post_meta( $post->ID, Global_Transformations::META_FEATURED_IMAGE_KEY, true );
557+
// Add the value to the data meta.
558+
$data['meta'][ Global_Transformations::META_FEATURED_IMAGE_KEY ] = $disable;
559+
} else {
560+
// If the param was found, its a save edit, to update the meta data.
561+
update_post_meta( $post->ID, Global_Transformations::META_FEATURED_IMAGE_KEY, (bool) $data['meta'][ Global_Transformations::META_FEATURED_IMAGE_KEY ] );
562+
}
563+
}
551564
$response->set_data( $data );
552565
}
553566

@@ -692,6 +705,24 @@ public function filter_image_block_pre_render( $block, $source_block ) {
692705
return $block;
693706
}
694707

708+
709+
/**
710+
* Add filters for Rest API handling.
711+
*/
712+
public function init_rest_filters() {
713+
// Gutenberg compatibility.
714+
add_filter( 'rest_prepare_attachment', array( $this, 'filter_attachment_for_rest' ) );
715+
$types = get_post_types_by_support( 'editor' );
716+
foreach ( $types as $type ) {
717+
$post_type = get_post_type_object( $type );
718+
// Check if this is a rest supported type.
719+
if ( true === $post_type->show_in_rest ) {
720+
// Add filter only to rest supported types.
721+
add_filter( 'rest_prepare_' . $type, array( $this, 'pre_filter_rest_content' ), 10, 3 );
722+
}
723+
}
724+
}
725+
695726
/**
696727
* Setup hooks for the filters.
697728
*/
@@ -710,16 +741,8 @@ public function setup_hooks() {
710741
// Filter video codes.
711742
add_filter( 'media_send_to_editor', array( $this, 'filter_video_embeds' ), 10, 3 );
712743

713-
// Gutenberg compatibility.
714-
add_filter( 'rest_prepare_attachment', array( $this, 'filter_attachment_for_rest' ) );
715-
$types = get_post_types_by_support( 'editor' );
716-
$filter = $this;
717-
array_map(
718-
function ( $type ) use ( $filter ) {
719-
add_filter( 'rest_prepare_' . $type, array( $filter, 'pre_filter_rest_content' ), 10, 3 );
720-
},
721-
$types
722-
);
744+
// Enable Rest filters.
745+
add_action( 'rest_api_init', array( $this, 'init_rest_filters' ) );
723746

724747
// Remove editors to prevent users from manually editing images in WP.
725748
add_filter( 'wp_image_editors', array( $this, 'disable_editors_maybe' ) );

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ public function maybe_disable_connect( $field, $slug ) {
103103
$field['description'] = sprintf(
104104
// translators: Placeholders are <a> tags.
105105
__( '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' ),
106-
'<a href="https://support.cloudinary.com/hc/en-us/requests/new" target="_blank">',
106+
sprintf(
107+
'<a href="%s">',
108+
add_query_arg( 'page', 'cld_sync_media', admin_url( 'admin.php' ) )
109+
),
107110
'</a>'
108111
);
109112
$field['disabled'] = true;

0 commit comments

Comments
 (0)