Editor: Show the patterns page for classic themes.

Block themes and classic themes with template parts support 
can already access the patterns list within the site editor.
This adds a "Patterns" menu item under Appearance for classic themes
without template parts support.

Props wildworks, kevin940726, aaronrobertshaw, fabiankaegy, swissspidy, get_dave, kebbet.
Fixes #58827.
Built from https://develop.svn.wordpress.org/trunk@57543


git-svn-id: http://core.svn.wordpress.org/trunk@57044 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
youknowriad 2024-02-06 19:42:13 +00:00
parent b342d5c7b8
commit cb6c706152
4 changed files with 15 additions and 10 deletions

View File

@ -205,10 +205,12 @@ if ( ! is_multisite() && current_user_can( 'update_themes' ) ) {
if ( wp_is_block_theme() ) { if ( wp_is_block_theme() ) {
$submenu['themes.php'][6] = array( _x( 'Editor', 'site editor menu item' ), 'edit_theme_options', 'site-editor.php' ); $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' ) ) { if ( ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ) ) {
$submenu['themes.php'][6] = array( $submenu['themes.php'][7] = array(
__( 'Template Parts' ), __( 'Template Parts' ),
'edit_theme_options', 'edit_theme_options',
'site-editor.php?path=/wp_template_part/all', 'site-editor.php?path=/wp_template_part/all',
@ -220,7 +222,7 @@ $customize_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_remova
// Hide Customize link on block themes unless a plugin or theme // Hide Customize link on block themes unless a plugin or theme
// is using 'customize_register' to add a setting. // is using 'customize_register' to add a setting.
if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) { 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' ); $submenu['themes.php'][ $position ] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' );
} }

View File

@ -19,16 +19,19 @@ if ( ! current_user_can( 'edit_theme_options' ) ) {
); );
} }
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 = 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_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] );
$is_template_part_editor = $is_template_part || $is_template_part_path; $is_template_part_editor = $is_template_part || $is_template_part_path;
$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() && ! $is_template_part_editor ) { if ( ! wp_is_block_theme() ) {
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); 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 && ! $is_template_part_editor ) {
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
}
} }
// Used in the HTML title tag. // Used in the HTML title tag.

View File

@ -5395,7 +5395,7 @@ function wp_widgets_add_menu() {
if ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) { if ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) {
$submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); $submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
} else { } 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 ); ksort( $submenu['themes.php'], SORT_NUMERIC );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.5-alpha-57542'; $wp_version = '6.5-alpha-57543';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.