@@ -558,7 +558,7 @@ public function pre_filter_rest_content( $response, $post, $request ) {
558558 $ data ['meta ' ][ Global_Transformations::META_FEATURED_IMAGE_KEY ] = $ disable ;
559559 } else {
560560 // 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 ' ] );
561+ update_post_meta ( $ post ->ID , Global_Transformations::META_FEATURED_IMAGE_KEY , (bool ) $ data ['meta ' ][ Global_Transformations:: META_FEATURED_IMAGE_KEY ] );
562562 }
563563 }
564564 $ response ->set_data ( $ data );
@@ -705,6 +705,24 @@ public function filter_image_block_pre_render( $block, $source_block ) {
705705 return $ block ;
706706 }
707707
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+
708726 /**
709727 * Setup hooks for the filters.
710728 */
@@ -723,21 +741,8 @@ public function setup_hooks() {
723741 // Filter video codes.
724742 add_filter ( 'media_send_to_editor ' , array ( $ this , 'filter_video_embeds ' ), 10 , 3 );
725743
726- // Gutenberg compatibility.
727- add_filter ( 'rest_prepare_attachment ' , array ( $ this , 'filter_attachment_for_rest ' ) );
728- $ types = get_post_types_by_support ( 'editor ' );
729- $ filter = $ this ;
730- array_map (
731- function ( $ type ) use ( $ filter ) {
732- $ post_type = get_post_type_object ( $ type );
733- // Check if this is a rest supported type.
734- if ( true === $ post_type ->show_in_rest ) {
735- // Add filter only to rest supported types.
736- add_filter ( 'rest_prepare_ ' . $ type , array ( $ filter , 'pre_filter_rest_content ' ), 10 , 3 );
737- }
738- },
739- $ types
740- );
744+ // Enable Rest filters.
745+ add_action ( 'rest_api_init ' , array ( $ this , 'init_rest_filters ' ) );
741746
742747 // Remove editors to prevent users from manually editing images in WP.
743748 add_filter ( 'wp_image_editors ' , array ( $ this , 'disable_editors_maybe ' ) );
0 commit comments