Skip to content

Commit

Permalink
WPCS and fallback fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Dec 12, 2024
1 parent 89d5ec5 commit dd643fe
Showing 1 changed file with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@
* @return void
*/
function gutenberg_editor_rendering_mode_field() {
register_rest_field( 'type', 'default_rendering_mode', array(
'get_callback' => static function( $object ) {
$post_type_object = get_post_type_object( $object['slug'] );
register_rest_field(
'type',
'default_rendering_mode',
array(
'get_callback' => static function ( $object ) {
$post_type_object = get_post_type_object( $object['slug'] );

// Property will only exist if the post type supports the block editor.
if ( ! $post_type_object || ! isset( $post_type_object->default_rendering_mode ) ) {
return '';
}
// Property will only exist if the post type supports the block editor.
if ( ! $post_type_object || ! isset( $post_type_object->default_rendering_mode ) ) {
return 'post-only';
}

// Validate the filtered rendering mode.
if ( ! in_array( $post_type_object->default_rendering_mode, gutenberg_post_type_rendering_modes(), true ) ) {
return 'post-only';
}
// Validate the filtered rendering mode.
if ( ! in_array( $post_type_object->default_rendering_mode, gutenberg_post_type_rendering_modes(), true ) ) {
return 'post-only';
}

return $post_type_object->default_rendering_mode;
},
'schema' => array(
'description' => __( 'The rendering mode for the editor.', 'gutenberg' ),
'type' => 'string',
'enum' => array( 'post-only', 'template-locked' ),
'context' => array( 'edit' ),
'readonly' => true,
),
) );
return $post_type_object->default_rendering_mode;
},
'schema' => array(
'description' => __( 'The rendering mode for the editor.', 'gutenberg' ),
'type' => 'string',
'enum' => array( 'post-only', 'template-locked' ),
'context' => array( 'edit' ),
'readonly' => true,
),
)
);
}
add_action( 'rest_api_init', 'gutenberg_editor_rendering_mode_field' );

0 comments on commit dd643fe

Please sign in to comment.