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

Add editSite.NewTemplate.defaultTemplateSlugs filter #46270

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 19 additions & 15 deletions packages/edit-site/src/components/add-new-template/new-template.js
Expand Up @@ -47,21 +47,7 @@ import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
import TemplateActionsLoadingScreen from './template-actions-loading-screen';
import { useHistory } from '../routes';
import { store as editSiteStore } from '../../store';

const DEFAULT_TEMPLATE_SLUGS = [
'front-page',
'single',
'page',
'index',
'archive',
'author',
'category',
'date',
'tag',
'taxonomy',
'search',
'404',
];
import { applyFilters } from '@wordpress/hooks';

const TEMPLATE_ICONS = {
'front-page': home,
Expand Down Expand Up @@ -263,6 +249,24 @@ function useMissingTemplates(
setEntityForSuggestions,
setShowCustomTemplateModal
) {
const DEFAULT_TEMPLATE_SLUGS = applyFilters(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm generally wary of implementing JS filters because of the potential performance hit, but I don't think this is a hot path so it should be okay.

A question for other reviewers is I'm wondering if it'd be better to get these slugs from the server and filter them server side?

'editSite.NewTemplate.defaultTemplateSlugs',
[
'front-page',
'single',
'page',
'index',
'archive',
'author',
'category',
'date',
'tag',
'taxonomy',
'search',
'404',
]
);

const existingTemplates = useExistingTemplates();
const defaultTemplateTypes = useDefaultTemplateTypes();
const existingTemplateSlugs = ( existingTemplates || [] ).map(
Expand Down