Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update block-patterns.md #27655

Closed
wants to merge 1 commit into from

Conversation

emmahughescodes
Copy link

@emmahughescodes emmahughescodes commented Dec 10, 2020

In the new WordPress 5.6, it is required to have a 'categories' property in the register_block_pattern function.

Description

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

In the new WordPress 5.6, it is required to have a 'categories' property in the register_block_pattern function.
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 10, 2020
@gziolo gziolo added the [Type] Developer Documentation Documentation for developers label Dec 12, 2020
@gziolo
Copy link
Member

gziolo commented Dec 12, 2020

@youknowriad, can you review this changes proposed? I couldn't find the place in the code where categories for block patterns would be enforced.

@youknowriad
Copy link
Contributor

I think we should investigate where categories became required. If it wasn't the case in previous versions, this might be a bug we need to fix.

@@ -23,6 +23,7 @@ register_block_pattern(
'my-plugin/my-awesome-pattern',
array(
'title' => __( 'Two buttons', 'my-plugin' ),
'categories' => array( 'my-plugin' ),
Copy link
Member

@skorasaurus skorasaurus Dec 15, 2020

Choose a reason for hiding this comment

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

Thanks again for the Pull Request!

The value(s) inside the categories array needs to be an existing block pattern category.

Although 'my-plugin' could be its own block category, a custom block pattern needs to be registered first and for the sake of simplicity for this documentation; we should use one of the default categories, which would be buttons.

And then wrap it in a translation function, because buttons can mean some different context, so it would look like:

'categories' => array( _x( 'buttons', 'Block pattern category', 'my-plugin' )),

@skorasaurus
Copy link
Member

skorasaurus commented Dec 15, 2020

I think we should investigate where categories became required. If it wasn't the case in previous versions, this might be a bug we need to fix.

The block editor would crash if the categories was not included - #27249;

From testing, requiring the categories value was introduced sometime between 9.0.0 and 9.1.0 .

@skorasaurus
Copy link
Member

skorasaurus commented Jan 4, 2021

Hi @emmahughescodes

Thank you for reporting this! This was a bug in Gutenberg (categories are not required for a block pattern) and has been fixed in #27970 and will be added to WordPress 5.7 so the documentation does not need to be updated.

@skorasaurus skorasaurus closed this Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants