From e9bb57459b682239d24b2cc903628859f8f24466 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 13 Feb 2025 09:51:15 +0800 Subject: [PATCH] Editor: Conditionally enable the new default rendering mode for Pages (#69160) Co-authored-by: Mamaduka Co-authored-by: fabiankaegy Co-authored-by: audrasjb Co-authored-by: swissspidy --- backport-changelog/6.8/8123.md | 1 + lib/compat/wordpress-6.8/post.php | 23 ++++++++--------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/backport-changelog/6.8/8123.md b/backport-changelog/6.8/8123.md index 7955ec77416853..ec1b9f28f6f73d 100644 --- a/backport-changelog/6.8/8123.md +++ b/backport-changelog/6.8/8123.md @@ -2,3 +2,4 @@ https://github.com/WordPress/wordpress-develop/pull/8123 * https://github.com/WordPress/gutenberg/pull/68549 * https://github.com/WordPress/gutenberg/pull/68745 +* https://github.com/WordPress/gutenberg/pull/69160 diff --git a/lib/compat/wordpress-6.8/post.php b/lib/compat/wordpress-6.8/post.php index 2477e94f7393c6..b205e9dc81b894 100644 --- a/lib/compat/wordpress-6.8/post.php +++ b/lib/compat/wordpress-6.8/post.php @@ -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' );