From 229cb23d9e350aa736faea3dde26b2efa7d737b8 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 20 Oct 2022 15:09:47 +0400 Subject: [PATCH] Don't use the custom 'Template Parts' page with WP 6.1 and above --- .../wordpress-6.1/template-parts-screen.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 93b68436764b3a..d9b785100b8d99 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -24,6 +24,24 @@ function gutenberg_template_parts_screen_menu() { return; } + global $submenu; + if ( ! isset( $submenu['themes.php'] ) ) { + return; + } + + $needs_custom_page = true; + foreach ( $submenu['themes.php'] as $menu_item ) { + if ( str_contains( $menu_item[2], 'site-editor.php?postType=wp_template_part' ) ) { + $needs_custom_page = false; + break; + } + } + + // Don't use the custom 'Template Parts' page with WP 6.1 and above. + if ( ! $needs_custom_page ) { + return; + } + add_theme_page( __( 'Template Parts', 'gutenberg' ), __( 'Template Parts', 'gutenberg' ),