From 4c12c66c8a02260e1a98f695523d2d50bb1fbf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Wed, 7 Dec 2022 14:26:40 +0100 Subject: [PATCH 1/8] Add extra template slugs hook and object in the store --- lib/compat/wordpress-6.1/template-parts-screen.php | 3 +++ .../src/components/add-new-template/new-template.js | 7 +++++-- .../src/components/add-new-template/utils.js | 5 +++++ packages/edit-site/src/index.js | 1 + packages/editor/src/store/selectors.js | 11 +++++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index 1555b6ab1e250b..d9aedca5289a80 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -103,6 +103,8 @@ static function( $classes ) { } ); + $extra_template_slugs = apply_filters('extra_template_slugs', []); + $indexed_template_types = array(); foreach ( get_default_block_template_types() as $slug => $template_type ) { $template_type['slug'] = (string) $slug; @@ -114,6 +116,7 @@ static function( $classes ) { 'siteUrl' => site_url(), 'postsPerPage' => get_option( 'posts_per_page' ), 'styles' => get_block_editor_theme_styles(), + 'extraTemplateSlugs' => $extra_template_slugs, 'defaultTemplateTypes' => $indexed_template_types, 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 'supportsLayout' => wp_theme_has_theme_json(), diff --git a/packages/edit-site/src/components/add-new-template/new-template.js b/packages/edit-site/src/components/add-new-template/new-template.js index d8458246a8609b..20f3620bc671f0 100644 --- a/packages/edit-site/src/components/add-new-template/new-template.js +++ b/packages/edit-site/src/components/add-new-template/new-template.js @@ -42,6 +42,7 @@ import { usePostTypeMenuItems, useAuthorMenuItem, usePostTypeArchiveMenuItems, + useExtraTemplateSlugs, } from './utils'; import AddCustomGenericTemplateModal from './add-custom-generic-template-modal'; import TemplateActionsLoadingScreen from './template-actions-loading-screen'; @@ -269,13 +270,15 @@ function useMissingTemplates( ) { const existingTemplates = useExistingTemplates(); const defaultTemplateTypes = useDefaultTemplateTypes(); + const extraTemplateSlugs = useExtraTemplateSlugs(); const existingTemplateSlugs = ( existingTemplates || [] ).map( ( { slug } ) => slug ); const missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter( ( template ) => - DEFAULT_TEMPLATE_SLUGS.includes( template.slug ) && - ! existingTemplateSlugs.includes( template.slug ) + [ ...DEFAULT_TEMPLATE_SLUGS, ...extraTemplateSlugs ].includes( + template.slug + ) && ! existingTemplateSlugs.includes( template.slug ) ); const onClickMenuItem = ( _entityForSuggestions ) => { setShowCustomTemplateModal( true ); diff --git a/packages/edit-site/src/components/add-new-template/utils.js b/packages/edit-site/src/components/add-new-template/utils.js index 7309f2ff711ca9..3a3998ed53abd8 100644 --- a/packages/edit-site/src/components/add-new-template/utils.js +++ b/packages/edit-site/src/components/add-new-template/utils.js @@ -59,6 +59,11 @@ export const useDefaultTemplateTypes = () => { [] ); }; +export const useExtraTemplateSlugs = () => { + return useSelect( ( select ) => { + return select( editorStore ).__experimentalGetExtraTemplateSlugs(); + }, [] ); +}; const usePublicPostTypes = () => { const postTypes = useSelect( diff --git a/packages/edit-site/src/index.js b/packages/edit-site/src/index.js index 4b619f7aac9a97..aa632360aa48cb 100644 --- a/packages/edit-site/src/index.js +++ b/packages/edit-site/src/index.js @@ -84,6 +84,7 @@ export function reinitializeEditor( target, settings ) { dispatch( editorStore ).updateEditorSettings( { defaultTemplateTypes: settings.defaultTemplateTypes, defaultTemplatePartAreas: settings.defaultTemplatePartAreas, + extraTemplateSlugs: settings.extraTemplateSlugs, } ); } diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index da5b4700eb9fc8..ddde1dfcf9a893 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1549,6 +1549,17 @@ export function __experimentalGetDefaultTemplateTypes( state ) { return getEditorSettings( state )?.defaultTemplateTypes; } +/** + * Returns the extra template slugs. + * + * @param {Object} state Global application state. + * + * @return {Array} The template slugs. + */ +export function __experimentalGetExtraTemplateSlugs( state ) { + return getEditorSettings( state )?.extraTemplateSlugs; +} + /** * Returns the default template part areas. * From 224e96b1c5a9cc76163647bcab17631e3e40b6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Fri, 9 Dec 2022 10:20:26 +0100 Subject: [PATCH 2/8] Stop using only slugs, use the whole template object --- lib/compat/wordpress-6.1/template-parts-screen.php | 4 ++-- .../src/components/add-new-template/new-template.js | 10 +++++----- .../edit-site/src/components/add-new-template/utils.js | 4 ++-- packages/edit-site/src/index.js | 2 +- packages/editor/src/store/selectors.js | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php index d9aedca5289a80..a4c6e0a3d49e40 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -103,7 +103,7 @@ static function( $classes ) { } ); - $extra_template_slugs = apply_filters('extra_template_slugs', []); + $extra_template_types = apply_filters( 'extra_template_types', array() ); $indexed_template_types = array(); foreach ( get_default_block_template_types() as $slug => $template_type ) { @@ -116,7 +116,7 @@ static function( $classes ) { 'siteUrl' => site_url(), 'postsPerPage' => get_option( 'posts_per_page' ), 'styles' => get_block_editor_theme_styles(), - 'extraTemplateSlugs' => $extra_template_slugs, + 'extraTemplateTypes' => $extra_template_types, 'defaultTemplateTypes' => $indexed_template_types, 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 'supportsLayout' => wp_theme_has_theme_json(), diff --git a/packages/edit-site/src/components/add-new-template/new-template.js b/packages/edit-site/src/components/add-new-template/new-template.js index 20f3620bc671f0..8c422d73c45557 100644 --- a/packages/edit-site/src/components/add-new-template/new-template.js +++ b/packages/edit-site/src/components/add-new-template/new-template.js @@ -42,7 +42,7 @@ import { usePostTypeMenuItems, useAuthorMenuItem, usePostTypeArchiveMenuItems, - useExtraTemplateSlugs, + useExtraTemplateTypes, } from './utils'; import AddCustomGenericTemplateModal from './add-custom-generic-template-modal'; import TemplateActionsLoadingScreen from './template-actions-loading-screen'; @@ -270,15 +270,14 @@ function useMissingTemplates( ) { const existingTemplates = useExistingTemplates(); const defaultTemplateTypes = useDefaultTemplateTypes(); - const extraTemplateSlugs = useExtraTemplateSlugs(); + const extraTemplateTypes = useExtraTemplateTypes(); const existingTemplateSlugs = ( existingTemplates || [] ).map( ( { slug } ) => slug ); const missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter( ( template ) => - [ ...DEFAULT_TEMPLATE_SLUGS, ...extraTemplateSlugs ].includes( - template.slug - ) && ! existingTemplateSlugs.includes( template.slug ) + [ ...DEFAULT_TEMPLATE_SLUGS ].includes( template.slug ) && + ! existingTemplateSlugs.includes( template.slug ) ); const onClickMenuItem = ( _entityForSuggestions ) => { setShowCustomTemplateModal( true ); @@ -329,6 +328,7 @@ function useMissingTemplates( ...usePostTypeArchiveMenuItems(), ...postTypesMenuItems, ...taxonomiesMenuItems, + ...extraTemplateTypes, ]; return missingTemplates; } diff --git a/packages/edit-site/src/components/add-new-template/utils.js b/packages/edit-site/src/components/add-new-template/utils.js index 3a3998ed53abd8..7a61fcbfc0da68 100644 --- a/packages/edit-site/src/components/add-new-template/utils.js +++ b/packages/edit-site/src/components/add-new-template/utils.js @@ -59,9 +59,9 @@ export const useDefaultTemplateTypes = () => { [] ); }; -export const useExtraTemplateSlugs = () => { +export const useExtraTemplateTypes = () => { return useSelect( ( select ) => { - return select( editorStore ).__experimentalGetExtraTemplateSlugs(); + return select( editorStore ).__experimentalGetExtraTemplateTypes(); }, [] ); }; diff --git a/packages/edit-site/src/index.js b/packages/edit-site/src/index.js index aa632360aa48cb..79f25c2054876f 100644 --- a/packages/edit-site/src/index.js +++ b/packages/edit-site/src/index.js @@ -84,7 +84,7 @@ export function reinitializeEditor( target, settings ) { dispatch( editorStore ).updateEditorSettings( { defaultTemplateTypes: settings.defaultTemplateTypes, defaultTemplatePartAreas: settings.defaultTemplatePartAreas, - extraTemplateSlugs: settings.extraTemplateSlugs, + extraTemplateTypes: settings.extraTemplateTypes, } ); } diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index ddde1dfcf9a893..3ff3cc2a892ca6 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1556,8 +1556,8 @@ export function __experimentalGetDefaultTemplateTypes( state ) { * * @return {Array} The template slugs. */ -export function __experimentalGetExtraTemplateSlugs( state ) { - return getEditorSettings( state )?.extraTemplateSlugs; +export function __experimentalGetExtraTemplateTypes( state ) { + return getEditorSettings( state )?.extraTemplateTypes; } /** From 08588bed106c599cfd2c6d8972b6e3db64204ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Fri, 9 Dec 2022 10:52:39 +0100 Subject: [PATCH 3/8] Add compat 6.2 file --- .../wordpress-6.2/template-parts-screen.php | 44 +++++++++++++++++++ lib/load.php | 1 + 2 files changed, 45 insertions(+) create mode 100644 lib/compat/wordpress-6.2/template-parts-screen.php diff --git a/lib/compat/wordpress-6.2/template-parts-screen.php b/lib/compat/wordpress-6.2/template-parts-screen.php new file mode 100644 index 00000000000000..a6a206a9e9ff5b --- /dev/null +++ b/lib/compat/wordpress-6.2/template-parts-screen.php @@ -0,0 +1,44 @@ + $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(), + 'extraTemplateTypes' => $extra_template_types, + 'defaultTemplateTypes' => $indexed_template_types, + 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), + 'supportsLayout' => wp_theme_has_theme_json(), + 'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), + ); + + $editor_settings = get_block_editor_settings( $custom_settings, $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 ) + ) + ); +} +add_action( 'admin_enqueue_scripts', 'gutenberg_add_custom_settings' ); diff --git a/lib/load.php b/lib/load.php index 11830fb9a0c4d3..4ad5a550c49b50 100644 --- a/lib/load.php +++ b/lib/load.php @@ -108,6 +108,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.2/class-wp-theme-json-6-2.php'; require __DIR__ . '/compat/wordpress-6.2/edit-form-blocks.php'; require __DIR__ . '/compat/wordpress-6.2/site-editor.php'; +require __DIR__ . '/compat/wordpress-6.2/template-parts-screen.php'; // Experimental features. remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WP 6.0's stopgap handler for Webfonts API. From 881b591e828d3b9069b7cda56e610d1b16ff39ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Fri, 9 Dec 2022 13:39:28 +0100 Subject: [PATCH 4/8] Remove param --- lib/compat/wordpress-6.2/template-parts-screen.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/compat/wordpress-6.2/template-parts-screen.php b/lib/compat/wordpress-6.2/template-parts-screen.php index a6a206a9e9ff5b..748434ccf1f134 100644 --- a/lib/compat/wordpress-6.2/template-parts-screen.php +++ b/lib/compat/wordpress-6.2/template-parts-screen.php @@ -5,7 +5,6 @@ * * Note: Parts that need to be ported back should have inline comments. * - * @param string $hook Current page hook. * @return void */ function gutenberg_add_custom_settings() { From 4f10b7fcc4972eaf876d890f73713b46b00c3259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Fri, 9 Dec 2022 15:31:12 +0100 Subject: [PATCH 5/8] Remove `/lib` changes and add the new setting under 6.2 `site-editor.php` --- .../wordpress-6.1/template-parts-screen.php | 3 -- lib/compat/wordpress-6.2/site-editor.php | 17 ++++++-- .../wordpress-6.2/template-parts-screen.php | 43 ------------------- lib/load.php | 1 - 4 files changed, 14 insertions(+), 50 deletions(-) delete mode 100644 lib/compat/wordpress-6.2/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 index a4c6e0a3d49e40..1555b6ab1e250b 100644 --- a/lib/compat/wordpress-6.1/template-parts-screen.php +++ b/lib/compat/wordpress-6.1/template-parts-screen.php @@ -103,8 +103,6 @@ static function( $classes ) { } ); - $extra_template_types = apply_filters( 'extra_template_types', array() ); - $indexed_template_types = array(); foreach ( get_default_block_template_types() as $slug => $template_type ) { $template_type['slug'] = (string) $slug; @@ -116,7 +114,6 @@ static function( $classes ) { 'siteUrl' => site_url(), 'postsPerPage' => get_option( 'posts_per_page' ), 'styles' => get_block_editor_theme_styles(), - 'extraTemplateTypes' => $extra_template_types, 'defaultTemplateTypes' => $indexed_template_types, 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 'supportsLayout' => wp_theme_has_theme_json(), diff --git a/lib/compat/wordpress-6.2/site-editor.php b/lib/compat/wordpress-6.2/site-editor.php index b6246e49c6d113..de81680313727d 100644 --- a/lib/compat/wordpress-6.2/site-editor.php +++ b/lib/compat/wordpress-6.2/site-editor.php @@ -6,19 +6,30 @@ */ /** - * Remove home template setting for WP 6.2. + * Remove home template setting and add filtered extraTemplatesTypes setting for WP 6.2. * * @param array $settings Existing block editor settings. * @param WP_Block_Editor_Context $context The current block editor context. * @return array */ -function gutenberg_site_editor_unset_homepage_setting( $settings, $context ) { +function gutenberg_site_editor_update_settings( $settings, $context ) { if ( isset( $context->post ) ) { return $settings; } unset( $settings['__unstableHomeTemplate'] ); + /** + * Filters the list of extra templates. + * + * Template types added in this filter will show up under the `Add new` menu in the Site Editor. + * + * @since 6.2.0 + * + * @param array $extra_template_types An array of template types, formatted as [ slug, title, description ] ]. + */ + $settings['extraTemplateTypes'] = apply_filters( 'extra_template_types', array() ); + return $settings; } -add_filter( 'block_editor_settings_all', 'gutenberg_site_editor_unset_homepage_setting', 10, 2 ); +add_filter( 'block_editor_settings_all', 'gutenberg_site_editor_update_settings', 10, 2 ); diff --git a/lib/compat/wordpress-6.2/template-parts-screen.php b/lib/compat/wordpress-6.2/template-parts-screen.php deleted file mode 100644 index 748434ccf1f134..00000000000000 --- a/lib/compat/wordpress-6.2/template-parts-screen.php +++ /dev/null @@ -1,43 +0,0 @@ - $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(), - 'extraTemplateTypes' => $extra_template_types, - 'defaultTemplateTypes' => $indexed_template_types, - 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), - 'supportsLayout' => wp_theme_has_theme_json(), - 'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), - ); - - $editor_settings = get_block_editor_settings( $custom_settings, $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 ) - ) - ); -} -add_action( 'admin_enqueue_scripts', 'gutenberg_add_custom_settings' ); diff --git a/lib/load.php b/lib/load.php index 4ad5a550c49b50..11830fb9a0c4d3 100644 --- a/lib/load.php +++ b/lib/load.php @@ -108,7 +108,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.2/class-wp-theme-json-6-2.php'; require __DIR__ . '/compat/wordpress-6.2/edit-form-blocks.php'; require __DIR__ . '/compat/wordpress-6.2/site-editor.php'; -require __DIR__ . '/compat/wordpress-6.2/template-parts-screen.php'; // Experimental features. remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WP 6.0's stopgap handler for Webfonts API. From b656f947f11f4e54fab8983a6016a7c5a9e20cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Fri, 9 Dec 2022 15:32:25 +0100 Subject: [PATCH 6/8] Revert to original array --- .../edit-site/src/components/add-new-template/new-template.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/add-new-template/new-template.js b/packages/edit-site/src/components/add-new-template/new-template.js index 8c422d73c45557..b5fae29705cbb6 100644 --- a/packages/edit-site/src/components/add-new-template/new-template.js +++ b/packages/edit-site/src/components/add-new-template/new-template.js @@ -276,7 +276,7 @@ function useMissingTemplates( ); const missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter( ( template ) => - [ ...DEFAULT_TEMPLATE_SLUGS ].includes( template.slug ) && + DEFAULT_TEMPLATE_SLUGS.includes( template.slug ) && ! existingTemplateSlugs.includes( template.slug ) ); const onClickMenuItem = ( _entityForSuggestions ) => { From d340f383f35f2a908b5eed99c700469095d3c2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Mon, 2 Jan 2023 12:59:53 +0100 Subject: [PATCH 7/8] Avoid overriding any templates with the extra templates --- .../src/components/add-new-template/new-template.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/add-new-template/new-template.js b/packages/edit-site/src/components/add-new-template/new-template.js index b5fae29705cbb6..88324e222261dc 100644 --- a/packages/edit-site/src/components/add-new-template/new-template.js +++ b/packages/edit-site/src/components/add-new-template/new-template.js @@ -270,7 +270,6 @@ function useMissingTemplates( ) { const existingTemplates = useExistingTemplates(); const defaultTemplateTypes = useDefaultTemplateTypes(); - const extraTemplateTypes = useExtraTemplateTypes(); const existingTemplateSlugs = ( existingTemplates || [] ).map( ( { slug } ) => slug ); @@ -279,6 +278,7 @@ function useMissingTemplates( DEFAULT_TEMPLATE_SLUGS.includes( template.slug ) && ! existingTemplateSlugs.includes( template.slug ) ); + const extraTemplateTypes = useExtraTemplateTypes(); const onClickMenuItem = ( _entityForSuggestions ) => { setShowCustomTemplateModal( true ); setEntityForSuggestions( _entityForSuggestions ); @@ -328,7 +328,14 @@ function useMissingTemplates( ...usePostTypeArchiveMenuItems(), ...postTypesMenuItems, ...taxonomiesMenuItems, - ...extraTemplateTypes, ]; - return missingTemplates; + + const missingTemplateSlugs = ( missingTemplates || [] ).map( + ( { slug } ) => slug + ); + const missingExtraTemplateTypes = ( extraTemplateTypes || [] ).filter( + ( template ) => ! missingTemplateSlugs.includes( template.slug ) + ); + + return [ ...missingTemplates, ...missingExtraTemplateTypes ]; } From af0b75ba03ecfea7cb007550370610f853f7129f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 10 Jan 2023 13:10:24 +0100 Subject: [PATCH 8/8] Add onclick = createTemplate(template, false) for extra templates and extra check --- .../add-new-template/new-template.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/add-new-template/new-template.js b/packages/edit-site/src/components/add-new-template/new-template.js index 679117e46b87fb..a48422943bd04e 100644 --- a/packages/edit-site/src/components/add-new-template/new-template.js +++ b/packages/edit-site/src/components/add-new-template/new-template.js @@ -205,6 +205,7 @@ export default function NewTemplate( { slug, onClick, icon, + isWPSuggestion = false, } = template; return ( onClick ? onClick( template ) - : createTemplate( template ) + : createTemplate( + template, + isWPSuggestion + ) } > { title } @@ -281,7 +285,13 @@ function useMissingTemplates( DEFAULT_TEMPLATE_SLUGS.includes( template.slug ) && ! existingTemplateSlugs.includes( template.slug ) ); - const extraTemplateTypes = useExtraTemplateTypes(); + const extraTemplateTypes = ( useExtraTemplateTypes() || [] ).map( + ( template ) => { + template.isWPSuggestion = false; + return template; + } + ); + const onClickMenuItem = ( _entityForSuggestions ) => { setShowCustomTemplateModal( true ); setEntityForSuggestions( _entityForSuggestions ); @@ -337,7 +347,9 @@ function useMissingTemplates( ( { slug } ) => slug ); const missingExtraTemplateTypes = ( extraTemplateTypes || [] ).filter( - ( template ) => ! missingTemplateSlugs.includes( template.slug ) + ( template ) => + ! missingTemplateSlugs.includes( template.slug ) && + ! existingTemplateSlugs.includes( template.slug ) ); return [ ...missingTemplates, ...missingExtraTemplateTypes ];