Skip to content

Commit

Permalink
Template Parts: Limit slug to Latin chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 16, 2022
1 parent 1832b77 commit 95d94ea
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 95d94ea

Please sign in to comment.