Skip to content

Commit

Permalink
Back Compat: Add Patterns submenu for WordPress 6.4 (#60804)
Browse files Browse the repository at this point in the history
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
4 people authored Apr 18, 2024
1 parent 219beef commit 4e9f1c3
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/compat/wordpress-6.5/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,42 @@ function gutenberg_add_use_customizer_site_logo_url_flag() {
}

add_action( 'admin_init', 'gutenberg_add_use_customizer_site_logo_url_flag' );

/**
* Add a Patterns submenu (wp-admin/edit.php?post_type=wp_block) under the Appearance menu
* for the Classic theme. This function should not be backported to core, and should be
* removed when the required WP core version for Gutenberg is >= 6.5.0.
*
* @global array $submenu
*/
function gutenberg_add_patterns_page_submenu_item() {
if ( ! is_wp_version_compatible( '6.5' ) && ! wp_is_block_theme() ) {
// Move the Themes submenu forward and inject a Patterns submenu.
global $submenu;
$submenu['themes.php'][4] = $submenu['themes.php'][5];
$submenu['themes.php'][5] = array( __( 'Patterns', 'gutenberg' ), 'edit_theme_options', 'edit.php?post_type=wp_block' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
}
}
add_action( 'admin_init', 'gutenberg_add_patterns_page_submenu_item' );

/**
* Filter the `wp_die_handler` to allow access to the Site Editor's Patterns page
* (wp-admin/site-editor.php?path=%2Fpatterns) internally for the Classic theme. This
* function should not be backported to core, and should be removed when the required
* WP core version for Gutenberg is >= 6.5.0.
*
* @param callable $default_handler The default handler.
* @return callable The default handler or a custom handler.
*/
function gutenberg_patterns_page_wp_die_handler( $default_handler ) {
if ( ! is_wp_version_compatible( '6.5' ) && ! wp_is_block_theme() && str_contains( $_SERVER['REQUEST_URI'], 'site-editor.php' ) ) {
$is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] );
$is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] );
if ( $is_patterns || $is_patterns_path ) {
return '__return_false';
}
}
return $default_handler;
}
add_filter( 'wp_die_handler', 'gutenberg_patterns_page_wp_die_handler' );

1 comment on commit 4e9f1c3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4e9f1c3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8740675248
📝 Reported issues:

Please sign in to comment.