Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

See if slashing new categories helps #200

Closed

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Jun 15, 2023

Summary of changes

Allows ' and non-word characters in a category title and slug.

A possible alternative to #198.

This works, but it's not better than 198.

How to test

  1. Create a new pattern
  2. Create a new category
  3. Include a ' in it
  4. Publish the pattern
  5. Reload the browser
  6. Expected: The category you created persists:
Screenshot 2023-06-15 at 6 28 31 PM

@kienstra
Copy link
Contributor Author

This isn't better than #198, so closing this.

@kienstra kienstra closed this Jun 16, 2023
@@ -1,7 +1,5 @@
/** Converts a string to a kebab-case. */
export default function toKebabCase( toConvert = '' ) {
return toConvert
.replace( /[_\W]+(?=\w+)/g, '-' )
Copy link
Contributor Author

@kienstra kienstra Jun 16, 2023

Choose a reason for hiding this comment

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

Because this stripped all non-word characters, it caused a category with an apostrophe to be saved without the apostrophe, and therefore never appear in the categories react-select.

This issue appeared because with the PHP edits below, categories can now have an apostrophe.

Copy link
Contributor Author

@kienstra kienstra Jun 16, 2023

Choose a reason for hiding this comment

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

Here's what it looked like without this fix in toKebabCase.ts:

<?php
/**
 * Title: My New Pattern 2
 * Slug: altitude-pro/my-new-pattern-2
 * Description: 
 * Categories: you-re-the-best   <-- Saved without the apostrophe, it was stripped in CategoriesPanel.ts#L62
 * Keywords: 
 * Viewport Width: 1280
 * Block Types: 
 * Post Types: 
 * Inserter: true
 * Custom Categories: You're The Best
 */
// Category name and label have the apostrophe
register_block_pattern_category( 'you\'re-the-best', [ 'label' => __( 'You\'re The Best', 'altitude-pro' ), 'pm_custom' => true ] ); 
?>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant