Skip to content

Commit

Permalink
Template Parts: Limit slug to Latin chars (#38861)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Apr 7, 2022
1 parent d980893 commit 0e5b82b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/block-library/src/template-part/edit/utils/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0e5b82b

Please sign in to comment.