From 95d94ea2ecf6744af4015c4631e9004a152bff7e Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 16 Feb 2022 21:01:29 +0400 Subject: [PATCH] Template Parts: Limit slug to Latin chars --- .../src/template-part/edit/placeholder/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/template-part/edit/placeholder/index.js b/packages/block-library/src/template-part/edit/placeholder/index.js index 64a730535c0f5b..0c3cb541d6f5a8 100644 --- a/packages/block-library/src/template-part/edit/placeholder/index.js +++ b/packages/block-library/src/template-part/edit/placeholder/index.js @@ -59,13 +59,19 @@ export default function TemplatePartPlaceholder( { startingBlocks = [], 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( startingBlocks ), // `area` is filterable on the server and defaults to `UNCATEGORIZED` // if provided value is not allowed.