Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back Compat: Add Patterns submenu for WordPress 6.4 #60804

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );
Loading