Skip to content

Commit

Permalink
Editor: Show the patterns page for classic themes.
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://develop.svn.wordpress.org/trunk@57543 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
youknowriad committed Feb 6, 2024
1 parent b7027a8 commit 7a71339
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/wp-admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,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',
Expand All @@ -220,7 +222,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' );
}
Expand Down
17 changes: 10 additions & 7 deletions src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 && ! $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.
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5395,7 +5395,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 );
Expand Down

0 comments on commit 7a71339

Please sign in to comment.