Skip to content

Commit 7a71339

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@57543 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b7027a8 commit 7a71339

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/wp-admin/menu.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@
205205

206206
if ( wp_is_block_theme() ) {
207207
$submenu['themes.php'][6] = array( _x( 'Editor', 'site editor menu item' ), 'edit_theme_options', 'site-editor.php' );
208+
} else {
209+
$submenu['themes.php'][6] = array( __( 'Patterns', 'site editor menu item' ), 'edit_theme_options', 'edit.php?post_type=wp_block' );
208210
}
209211

210212
if ( ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ) ) {
211-
$submenu['themes.php'][6] = array(
213+
$submenu['themes.php'][7] = array(
212214
__( 'Template Parts' ),
213215
'edit_theme_options',
214216
'site-editor.php?path=/wp_template_part/all',
@@ -220,7 +222,7 @@
220222
// Hide Customize link on block themes unless a plugin or theme
221223
// is using 'customize_register' to add a setting.
222224
if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) {
223-
$position = ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) ? 7 : 6;
225+
$position = ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ) ? 8 : 7;
224226

225227
$submenu['themes.php'][ $position ] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' );
226228
}

src/wp-admin/site-editor.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919
);
2020
}
2121

22-
if ( ! ( current_theme_supports( 'block-template-parts' ) || wp_is_block_theme() ) ) {
23-
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
24-
}
25-
2622
$is_template_part = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] );
2723
$is_template_part_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] );
2824
$is_template_part_editor = $is_template_part || $is_template_part_path;
29-
30-
if ( ! wp_is_block_theme() && ! $is_template_part_editor ) {
31-
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
25+
$is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] );
26+
$is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] );
27+
$is_patterns_editor = $is_patterns || $is_patterns_path;
28+
29+
if ( ! wp_is_block_theme() ) {
30+
if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) {
31+
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
32+
} elseif ( ! $is_patterns_editor && ! $is_template_part_editor ) {
33+
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
34+
}
3235
}
3336

3437
// Used in the HTML title tag.

src/wp-includes/functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5395,7 +5395,7 @@ function wp_widgets_add_menu() {
53955395
if ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) {
53965396
$submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
53975397
} else {
5398-
$submenu['themes.php'][7] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
5398+
$submenu['themes.php'][8] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
53995399
}
54005400

54015401
ksort( $submenu['themes.php'], SORT_NUMERIC );

0 commit comments

Comments
 (0)