From 8c19f67e3aea232ebfc0e5d22b834404f8591c25 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 6 Apr 2022 21:23:57 +0400 Subject: [PATCH] Template Parts: Limit slug to Latin chars --- .../block-library/src/template-part/edit/utils/hooks.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/template-part/edit/utils/hooks.js b/packages/block-library/src/template-part/edit/utils/hooks.js index 010e7f87eb80be..dab55db6fc19ae 100644 --- a/packages/block-library/src/template-part/edit/utils/hooks.js +++ b/packages/block-library/src/template-part/edit/utils/hooks.js @@ -102,13 +102,18 @@ export function useCreateTemplatePartFromBlocks( area, setAttributes ) { const { saveEntityRecord } = useDispatch( coreStore ); return async ( blocks = [], title = __( 'Untitled Template Part' ) ) => { + // Currently template parts only allow latin chars. + // Fallback slug will receive suffix by default. + const cleanSlug = + kebabCase( title ).replace( /[^\w-]+/g, '' ) || 'wp-custom-part'; + // If we have `area` set from block attributes, means an exposed // block variation was inserted. So add this prop to the template // part entity on creation. Afterwards remove `area` value from // block attributes. const record = { title, - slug: kebabCase( title ), + slug: cleanSlug, content: serialize( blocks ), // `area` is filterable on the server and defaults to `UNCATEGORIZED` // if provided value is not allowed.