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 @@ -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 @@ -558,7 +558,7 @@ public function pre_filter_rest_content( $response, $post, $request ) {
$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'] );
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 @@ -705,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 @@ -723,21 +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 ) {
$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( $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