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.2.0
* Version: 2.2.1
* 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 @@ -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 );
}

Expand All @@ -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;
} );
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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.
*/
Expand All @@ -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' ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public function maybe_disable_connect( $field, $slug ) {
$field['description'] = sprintf(
// translators: Placeholders are <a> 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' ),
'<a href="https://support.cloudinary.com/hc/en-us/requests/new" target="_blank">',
sprintf(
'<a href="%s">',
add_query_arg( 'page', 'cld_sync_media', admin_url( 'admin.php' ) )
),
'</a>'
);
$field['disabled'] = true;
Expand Down