From 6a048dffb166f9f28b6dbab97381d54f0841f1cf Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Wed, 13 Sep 2023 21:59:38 +0900 Subject: [PATCH 1/3] Expose the Patterns menu to the Classic theme --- src/wp-admin/menu.php | 6 ++++-- src/wp-admin/site-editor.php | 17 ++++++++++------- src/wp-includes/functions.php | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/wp-admin/menu.php b/src/wp-admin/menu.php index 6a90772155a54..00d3f98b63544 100644 --- a/src/wp-admin/menu.php +++ b/src/wp-admin/menu.php @@ -202,10 +202,12 @@ if ( wp_is_block_theme() ) { $submenu['themes.php'][6] = array( _x( 'Editor', 'site editor menu item' ), 'edit_theme_options', 'site-editor.php' ); +} else { + $submenu['themes.php'][6] = array( __( 'Patterns', 'site editor menu item' ), 'edit_theme_options', 'edit.php?post_type=wp_block' ); } if ( ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ) ) { - $submenu['themes.php'][6] = array( + $submenu['themes.php'][7] = array( __( 'Template Parts' ), 'edit_theme_options', 'site-editor.php?path=/wp_template_part/all', @@ -217,7 +219,7 @@ // Hide Customize link on block themes unless a plugin or theme // is using 'customize_register' to add a setting. if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) { - $position = ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) ? 7 : 6; + $position = ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ) ? 8 : 7; $submenu['themes.php'][ $position ] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' ); } diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 2da7222d7c8ff..0f71213d1c874 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -19,16 +19,19 @@ ); } -if ( ! ( current_theme_supports( 'block-template-parts' ) || wp_is_block_theme() ) ) { - wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); -} - $is_template_part = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] ); $is_template_part_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] ); $is_template_part_editor = $is_template_part || $is_template_part_path; - -if ( ! wp_is_block_theme() && ! $is_template_part_editor ) { - wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); +$is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] ); +$is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] ); +$is_patterns_editor = $is_patterns || $is_patterns_path; + +if ( ! wp_is_block_theme() ) { + if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) { + wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); + } elseif ( ! $is_patterns_editor ) { + wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); + } } // Used in the HTML title tag. diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 28975154c382c..f3ca035293ce5 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -5357,7 +5357,7 @@ function wp_widgets_add_menu() { if ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) { $submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); } else { - $submenu['themes.php'][7] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); + $submenu['themes.php'][8] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); } ksort( $submenu['themes.php'], SORT_NUMERIC ); From 879cb3b744971791b580bcde968fa0e0281dd8f1 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Thu, 14 Sep 2023 19:39:26 +0900 Subject: [PATCH 2/3] Update if conditional statement --- src/wp-admin/site-editor.php | 2 +- src/wp-content/themes/twentytwentyone/functions.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 0f71213d1c874..a0c405337fca7 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -29,7 +29,7 @@ if ( ! wp_is_block_theme() ) { if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) { wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); - } elseif ( ! $is_patterns_editor ) { + } elseif ( ! $is_patterns_editor && ! $is_template_part_editor ) { wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); } } diff --git a/src/wp-content/themes/twentytwentyone/functions.php b/src/wp-content/themes/twentytwentyone/functions.php index f163e394df734..e160850b5b827 100644 --- a/src/wp-content/themes/twentytwentyone/functions.php +++ b/src/wp-content/themes/twentytwentyone/functions.php @@ -27,6 +27,7 @@ * @return void */ function twenty_twenty_one_setup() { + add_theme_support( 'block-template-parts' ); // Add default posts and comments RSS feed links to head. add_theme_support( 'automatic-feed-links' ); From 2b5a2b94ef5a1e40c7915e4d6c4f6c0d5784954d Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:36:59 +0900 Subject: [PATCH 3/3] Update src/wp-content/themes/twentytwentyone/functions.php Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> --- src/wp-content/themes/twentytwentyone/functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-content/themes/twentytwentyone/functions.php b/src/wp-content/themes/twentytwentyone/functions.php index e160850b5b827..f163e394df734 100644 --- a/src/wp-content/themes/twentytwentyone/functions.php +++ b/src/wp-content/themes/twentytwentyone/functions.php @@ -27,7 +27,6 @@ * @return void */ function twenty_twenty_one_setup() { - add_theme_support( 'block-template-parts' ); // Add default posts and comments RSS feed links to head. add_theme_support( 'automatic-feed-links' );