Skip to content

Commit

Permalink
Editor: Conditionally enable the new default rendering mode for Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 12, 2025
1 parent a507759 commit 63ed010
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/compat/wordpress-6.8/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@
* Set the default editor mode for the page post type to `template-locked`.
*
* Note: This backports into `create_initial_post_types` in WordPress Core.
*
* @param array $args Array of post type arguments.
* @return array Updated array of post type arguments.
*/
function gutenberg_update_page_editor_support( $args ) {
if ( empty( $args['supports'] ) ) {
return $args;
function gutenberg_update_page_editor_support() {
// Avoid enabling the editor for pages when it's not supported.
// This is plugin specific safeguard.
if ( ! post_type_supports( 'page', 'editor' ) ) {
return;
}

$editor_support_key = array_search( 'editor', $args['supports'], true );
if ( false !== $editor_support_key ) {
unset( $args['supports'][ $editor_support_key ] );
$args['supports']['editor'] = array(
'default-mode' => 'template-locked',
);
if ( wp_is_block_theme() ) {
add_post_type_support( 'page', 'editor', array( 'default-mode' => 'template-locked' ) );
}

return $args;
}
add_action( 'register_page_post_type_args', 'gutenberg_update_page_editor_support' );
add_action( 'init', 'gutenberg_update_page_editor_support' );

0 comments on commit 63ed010

Please sign in to comment.