From 91c37c16981fe708dd36cb8b0754351337197988 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 26 Jul 2022 14:56:30 +0400 Subject: [PATCH 01/14] WIP: Block-based template parts --- .../wordpress-6.1/template-parts-screen.php | 208 ++++++++++++++++++ lib/load.php | 1 + packages/edit-site/src/style.scss | 1 + 3 files changed, 210 insertions(+) create mode 100644 lib/compat/wordpress-6.1/template-parts-screen.php diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php new file mode 100644 index 00000000000000..24a8fa7884053a --- /dev/null +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -0,0 +1,208 @@ + 'wp_template_part' ), + admin_url( 'themes.php?page=gutenberg-template-parts' ) + ); + wp_safe_redirect( $redirect_url ); + exit; + } +} +add_action( 'load-appearance_page_gutenberg-template-parts', 'gutenberg_template_parts_screen_permissions' ); + +/** + * Initialize the editor for the screen. Most of this is copied from `site-editor.php`. + * + * Note: Parts that need to be ported back should have inline comments. + * + * @param string $hook Current page hook. + * @return void + */ +function gutenberg_template_parts_screen_init( $hook ) { + global $current_screen, $editor_styles; + + if ( 'appearance_page_gutenberg-template-parts' !== $hook ) { + return; + } + + // Flag that we're loading the block editor. + $current_screen->is_block_editor( true ); + + // Default to is-fullscreen-mode to avoid jumps in the UI. + add_filter( + 'admin_body_class', + static function( $classes ) { + return "$classes is-fullscreen-mode"; + } + ); + + $indexed_template_types = array(); + foreach ( get_default_block_template_types() as $slug => $template_type ) { + $template_type['slug'] = (string) $slug; + $indexed_template_types[] = $template_type; + } + + $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); + $custom_settings = array( + 'siteUrl' => site_url(), + 'postsPerPage' => get_option( 'posts_per_page' ), + 'styles' => get_block_editor_theme_styles(), + 'defaultTemplateTypes' => $indexed_template_types, + 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), + 'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(), + 'supportsTemplatePartsMode' => current_theme_supports( 'block-template-parts' ), + '__unstableHomeTemplate' => gutenberg_resolve_home_template(), + ); + + /** + * We don't need home template resolution when block template parts are supported. + * Set the value to true to satisfy the editor initialization guard clause. + * + * @todo replace with actual check. + */ + if ( $custom_settings['supportsTemplatePartsMode'] ) { + $custom_settings['__unstableHomeTemplate'] = true; + } + + // Add additional back-compat patterns registered by `current_screen` et al. + $custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); + $custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); + + $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); + + if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { + $post_type = get_post_type_object( $_GET['postType'] ); + if ( ! $post_type ) { + wp_die( __( 'Invalid post type.' ) ); + } + } + + $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); + $active_theme = wp_get_theme()->get_stylesheet(); + $preload_paths = array( + array( '/wp/v2/media', 'OPTIONS' ), + '/wp/v2/types?context=view', + '/wp/v2/types/wp_template?context=edit', + '/wp/v2/types/wp_template-part?context=edit', + '/wp/v2/templates?context=edit&per_page=-1', + '/wp/v2/template-parts?context=edit&per_page=-1', + '/wp/v2/themes?context=edit&status=active', + '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', + '/wp/v2/global-styles/' . $active_global_styles_id, + '/wp/v2/global-styles/themes/' . $active_theme, + ); + + block_editor_rest_api_preload( $preload_paths, $block_editor_context ); + + wp_add_inline_script( + 'wp-edit-site', + sprintf( + 'wp.domReady( function() { + wp.editSite.initializeEditor( "site-editor", %s ); + } );', + wp_json_encode( $editor_settings ) + ) + ); + + // Preload server-registered block schemas. + wp_add_inline_script( + 'wp-blocks', + 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' + ); + + wp_add_inline_script( + 'wp-blocks', + sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ), + 'after' + ); + + wp_enqueue_script( 'wp-edit-site' ); + wp_enqueue_script( 'wp-format-library' ); + wp_enqueue_style( 'wp-edit-site' ); + wp_enqueue_style( 'wp-format-library' ); + wp_enqueue_media(); + + if ( + current_theme_supports( 'wp-block-styles' ) || + ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) + ) { + wp_enqueue_style( 'wp-block-library-theme' ); + } +} +add_action( 'admin_enqueue_scripts', 'gutenberg_template_parts_screen_init' ); + +/** + * The main entry point for the screen. + * + * @return void + */ +function gutenberg_template_parts_screen_render() { + echo '
'; +} + +/** + * Register the new theme feature. + * + * Migrates into `create_initial_theme_features` method. + * + * @return void + */ +function getunberg_register_template_parts_theme_feature() { + register_theme_feature( + 'block-template-parts', + array( + 'description' => __( 'Whether a theme uses block-based template parts.', 'gutenberg' ), + 'show_in_rest' => true, + ) + ); +} +add_action( 'setup_theme', 'getunberg_register_template_parts_theme_feature', 5 ); diff --git a/lib/load.php b/lib/load.php index cb2ad7721c3200..367e24fdc5e51d 100644 --- a/lib/load.php +++ b/lib/load.php @@ -91,6 +91,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.1/date-settings.php'; require __DIR__ . '/compat/wordpress-6.1/block-patterns.php'; require __DIR__ . '/compat/wordpress-6.1/edit-form-blocks.php'; +require __DIR__ . '/compat/wordpress-6.1/template-parts-screen.php'; require __DIR__ . '/compat/wordpress-6.1/theme.php'; // Experimental features. diff --git a/packages/edit-site/src/style.scss b/packages/edit-site/src/style.scss index 5e555c8657d83c..c2abb6ef1ea7cb 100644 --- a/packages/edit-site/src/style.scss +++ b/packages/edit-site/src/style.scss @@ -26,6 +26,7 @@ html.wp-toolbar { background: $white; } +body.appearance_page_gutenberg-template-parts, body.site-editor-php { @include wp-admin-reset(".edit-site"); } From 4322444b8e78cf928f0dfa673ba30a68d1837746 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 26 Jul 2022 15:05:49 +0400 Subject: [PATCH 02/14] Only display template parts menu --- .../navigation-panel/index.js | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js b/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js index 558106d6af28fa..2838d0a225ec55 100644 --- a/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js +++ b/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js @@ -40,22 +40,23 @@ function NavLink( { params, replace, ...props } ) { } const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => { - const { homeTemplate, isNavigationOpen, siteTitle } = useSelect( - ( select ) => { + const { homeTemplate, isNavigationOpen, isTemplatePartsMode, siteTitle } = + useSelect( ( select ) => { const { getEntityRecord } = select( coreDataStore ); const { getSettings, isNavigationOpened } = select( editSiteStore ); const siteData = getEntityRecord( 'root', '__unstableBase', undefined ) || {}; + const { supportsTemplatePartsMode, __unstableHomeTemplate } = + getSettings(); return { siteTitle: siteData.name, - homeTemplate: getSettings().__unstableHomeTemplate, + homeTemplate: __unstableHomeTemplate, isNavigationOpen: isNavigationOpened(), + isTemplatePartsMode: supportsTemplatePartsMode, }; - }, - [] - ); + }, [] ); const { setIsNavigationPanelOpened } = useDispatch( editSiteStore ); const closeOnEscape = ( event ) => { @@ -91,24 +92,29 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => { - - + { ! isTemplatePartsMode && ( + <> + + + + ) } Date: Wed, 27 Jul 2022 13:36:08 +0400 Subject: [PATCH 03/14] pinking shears --- lib/compat/wordpress-6.1/template-parts-screen.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 24a8fa7884053a..9f8a1f3ff229b0 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -106,8 +106,6 @@ static function( $classes ) { /** * We don't need home template resolution when block template parts are supported. * Set the value to true to satisfy the editor initialization guard clause. - * - * @todo replace with actual check. */ if ( $custom_settings['supportsTemplatePartsMode'] ) { $custom_settings['__unstableHomeTemplate'] = true; @@ -122,7 +120,7 @@ static function( $classes ) { if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { $post_type = get_post_type_object( $_GET['postType'] ); if ( ! $post_type ) { - wp_die( __( 'Invalid post type.' ) ); + wp_die( __( 'Invalid post type.', 'gutenberg' ) ); } } From 4f08c67ff46531b30650908354c589a06c2257b1 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 11:50:15 +0400 Subject: [PATCH 04/14] Add enqueue_block_editor_assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fabian Kägy --- lib/compat/wordpress-6.1/template-parts-screen.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 9f8a1f3ff229b0..758618ea0c45eb 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -175,6 +175,9 @@ static function( $classes ) { ) { wp_enqueue_style( 'wp-block-library-theme' ); } + + /** This action is documented in wp-admin/edit-form-blocks.php */ + do_action( 'enqueue_block_editor_assets' ); } add_action( 'admin_enqueue_scripts', 'gutenberg_template_parts_screen_init' ); From 33aeb83dafb233661c5d47f02278c183d9c04c57 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 11:51:47 +0400 Subject: [PATCH 05/14] Remove whitespace --- lib/compat/wordpress-6.1/template-parts-screen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 758618ea0c45eb..f9744a7762aa5d 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -175,7 +175,7 @@ static function( $classes ) { ) { wp_enqueue_style( 'wp-block-library-theme' ); } - + /** This action is documented in wp-admin/edit-form-blocks.php */ do_action( 'enqueue_block_editor_assets' ); } From 401a457b7ad1db0b7206da639e9dec69ddc83e18 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 13:58:49 +0400 Subject: [PATCH 06/14] Hide Global Styles --- .../navigation-panel/index.js | 2 +- .../edit-site/src/components/sidebar/index.js | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js b/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js index 2838d0a225ec55..ae62f50517d449 100644 --- a/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js +++ b/packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js @@ -54,7 +54,7 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => { siteTitle: siteData.name, homeTemplate: __unstableHomeTemplate, isNavigationOpen: isNavigationOpened(), - isTemplatePartsMode: supportsTemplatePartsMode, + isTemplatePartsMode: !! supportsTemplatePartsMode, }; }, [] ); const { setIsNavigationPanelOpened } = useDispatch( editSiteStore ); diff --git a/packages/edit-site/src/components/sidebar/index.js b/packages/edit-site/src/components/sidebar/index.js index 049db1e9dbf65f..b0237052adaafa 100644 --- a/packages/edit-site/src/components/sidebar/index.js +++ b/packages/edit-site/src/components/sidebar/index.js @@ -19,6 +19,7 @@ import { STORE_NAME } from '../../store/constants'; import SettingsHeader from './settings-header'; import TemplateCard from './template-card'; import { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from './constants'; +import { store as editSiteStore } from '../../store'; const { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill( 'EditSiteSidebarInspector' @@ -26,25 +27,27 @@ const { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill( export const SidebarInspectorFill = InspectorFill; export function SidebarComplementaryAreaFills() { - const { sidebar, isEditorSidebarOpened, hasBlockSelection } = useSelect( - ( select ) => { - const _sidebar = - select( interfaceStore ).getActiveComplementaryArea( - STORE_NAME - ); - const _isEditorSidebarOpened = [ - SIDEBAR_BLOCK, - SIDEBAR_TEMPLATE, - ].includes( _sidebar ); - return { - sidebar: _sidebar, - isEditorSidebarOpened: _isEditorSidebarOpened, - hasBlockSelection: - !! select( blockEditorStore ).getBlockSelectionStart(), - }; - }, - [] - ); + const { + sidebar, + isEditorSidebarOpened, + hasBlockSelection, + supportsGlobalStyles, + } = useSelect( ( select ) => { + const _sidebar = + select( interfaceStore ).getActiveComplementaryArea( STORE_NAME ); + const _isEditorSidebarOpened = [ + SIDEBAR_BLOCK, + SIDEBAR_TEMPLATE, + ].includes( _sidebar ); + const settings = select( editSiteStore ).getSettings(); + return { + sidebar: _sidebar, + isEditorSidebarOpened: _isEditorSidebarOpened, + hasBlockSelection: + !! select( blockEditorStore ).getBlockSelectionStart(), + supportsGlobalStyles: ! settings?.supportsTemplatePartsMode, + }; + }, [] ); const { enableComplementaryArea } = useDispatch( interfaceStore ); useEffect( () => { @@ -89,7 +92,7 @@ export function SidebarComplementaryAreaFills() { ) } - + { supportsGlobalStyles && } ); From b19b2a76be999377b7aed4f68d453087adf9899e Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 14:07:45 +0400 Subject: [PATCH 07/14] Disable template creation --- .../edit-site/src/components/list/header.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/edit-site/src/components/list/header.js b/packages/edit-site/src/components/list/header.js index 4f98ecf7843d5b..65e7f9dfe39954 100644 --- a/packages/edit-site/src/components/list/header.js +++ b/packages/edit-site/src/components/list/header.js @@ -9,10 +9,17 @@ import { __experimentalHeading as Heading } from '@wordpress/components'; * Internal dependencies */ import AddNewTemplate from '../add-new-template'; +import { store as editSiteStore } from '../../store'; export default function Header( { templateType } ) { - const postType = useSelect( - ( select ) => select( coreStore ).getPostType( templateType ), + const { canCreate, postType } = useSelect( + ( select ) => { + const settings = select( editSiteStore ).getSettings(); + return { + postType: select( coreStore ).getPostType( templateType ), + canCreate: ! settings?.supportsTemplatePartsMode, + }; + }, [ templateType ] ); @@ -26,9 +33,11 @@ export default function Header( { templateType } ) { { postType.labels?.name } -
- -
+ { canCreate && ( +
+ +
+ ) } ); } From 21dc6d06f4d109e45b6850eb68f0a2ff755b17e9 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 14:17:46 +0400 Subject: [PATCH 08/14] Disable make template part action for blocks --- .../convert-to-template-part.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js b/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js index e23e0addbf5613..91a6f0bc04da1c 100644 --- a/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js +++ b/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js @@ -6,7 +6,7 @@ import { kebabCase } from 'lodash'; /** * WordPress dependencies */ -import { useDispatch } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { BlockSettingsMenuControls, store as blockEditorStore, @@ -23,6 +23,7 @@ import { symbolFilled } from '@wordpress/icons'; * Internal dependencies */ import CreateTemplatePartModal from '../create-template-part-modal'; +import { store as editSiteStore } from '../../store'; export default function ConvertToTemplatePart( { clientIds, blocks } ) { const [ isModalOpen, setIsModalOpen ] = useState( false ); @@ -30,6 +31,17 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) { const { saveEntityRecord } = useDispatch( coreStore ); const { createSuccessNotice } = useDispatch( noticesStore ); + const { canCreate } = useSelect( ( select ) => { + const settings = select( editSiteStore ).getSettings(); + return { + canCreate: ! settings?.supportsTemplatePartsMode, + }; + }, [] ); + + if ( ! canCreate ) { + return null; + } + const onConvert = async ( { title, area } ) => { // Currently template parts only allow latin chars. // Fallback slug will receive suffix by default. From 1849a3793a5da1c5c89472b7d77c962733165767 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 22:59:17 +0400 Subject: [PATCH 09/14] Update lib/compat/wordpress-6.1/template-parts-screen.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sören Wrede --- lib/compat/wordpress-6.1/template-parts-screen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index f9744a7762aa5d..eee1d6ec6a8a68 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -197,7 +197,7 @@ function gutenberg_template_parts_screen_render() { * * @return void */ -function getunberg_register_template_parts_theme_feature() { +function gutenberg_register_template_parts_theme_feature() { register_theme_feature( 'block-template-parts', array( From 61182c15d65587f1cea068547dd7aa65999384a4 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 22:59:22 +0400 Subject: [PATCH 10/14] Update lib/compat/wordpress-6.1/template-parts-screen.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sören Wrede --- lib/compat/wordpress-6.1/template-parts-screen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index eee1d6ec6a8a68..56dfed2cc40024 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -206,4 +206,4 @@ function gutenberg_register_template_parts_theme_feature() { ) ); } -add_action( 'setup_theme', 'getunberg_register_template_parts_theme_feature', 5 ); +add_action( 'setup_theme', 'gutenberg_register_template_parts_theme_feature', 5 ); From 6bc79e819274bd55b86e8ce9646501747d9d8257 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 23:01:23 +0400 Subject: [PATCH 11/14] Update lib/compat/wordpress-6.1/template-parts-screen.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sören Wrede --- lib/compat/wordpress-6.1/template-parts-screen.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 56dfed2cc40024..581b04eef63896 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -160,7 +160,6 @@ static function( $classes ) { wp_add_inline_script( 'wp-blocks', sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ), - 'after' ); wp_enqueue_script( 'wp-edit-site' ); From dac54de66638755fda5774a0d1d18933898688ed Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 28 Jul 2022 23:20:44 +0400 Subject: [PATCH 12/14] Remove trailing comma --- lib/compat/wordpress-6.1/template-parts-screen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 581b04eef63896..26d38d0714d24b 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -159,7 +159,7 @@ static function( $classes ) { wp_add_inline_script( 'wp-blocks', - sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ), + sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ) ); wp_enqueue_script( 'wp-edit-site' ); From 1ff5e82c62b092df9d1457464993eeade458e1c7 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 22 Aug 2022 12:44:21 +0400 Subject: [PATCH 13/14] Make sure supportsTemplatePartsMode is false for block themes --- lib/compat/wordpress-6.1/template-parts-screen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 26d38d0714d24b..93b68436764b3a 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -99,7 +99,7 @@ static function( $classes ) { 'defaultTemplateTypes' => $indexed_template_types, 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(), - 'supportsTemplatePartsMode' => current_theme_supports( 'block-template-parts' ), + 'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), '__unstableHomeTemplate' => gutenberg_resolve_home_template(), ); From 666207d229bca0137351558e9301e294d78467dc Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 22 Aug 2022 12:58:12 +0400 Subject: [PATCH 14/14] pinking shears --- packages/edit-site/src/components/list/header.js | 5 +++-- .../template-part-converter/convert-to-template-part.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/edit-site/src/components/list/header.js b/packages/edit-site/src/components/list/header.js index 65e7f9dfe39954..91b9a13aeeb9c7 100644 --- a/packages/edit-site/src/components/list/header.js +++ b/packages/edit-site/src/components/list/header.js @@ -14,10 +14,11 @@ import { store as editSiteStore } from '../../store'; export default function Header( { templateType } ) { const { canCreate, postType } = useSelect( ( select ) => { - const settings = select( editSiteStore ).getSettings(); + const { supportsTemplatePartsMode } = + select( editSiteStore ).getSettings(); return { postType: select( coreStore ).getPostType( templateType ), - canCreate: ! settings?.supportsTemplatePartsMode, + canCreate: ! supportsTemplatePartsMode, }; }, [ templateType ] diff --git a/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js b/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js index 91a6f0bc04da1c..e5186140440154 100644 --- a/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js +++ b/packages/edit-site/src/components/template-part-converter/convert-to-template-part.js @@ -32,9 +32,10 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) { const { createSuccessNotice } = useDispatch( noticesStore ); const { canCreate } = useSelect( ( select ) => { - const settings = select( editSiteStore ).getSettings(); + const { supportsTemplatePartsMode } = + select( editSiteStore ).getSettings(); return { - canCreate: ! settings?.supportsTemplatePartsMode, + canCreate: ! supportsTemplatePartsMode, }; }, [] );