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

When removing core pattern, allow theme.json pattern slugs to be listed in inserter #41282

Closed
bph opened this issue May 24, 2022 · 8 comments · Fixed by #43634
Closed

When removing core pattern, allow theme.json pattern slugs to be listed in inserter #41282

bph opened this issue May 24, 2022 · 8 comments · Fixed by #43634
Assignees
Labels
[Feature] Pattern Directory The Pattern Directory, a place to find patterns [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Focus] Blocks Adoption For issues that directly impact the ability to adopt features of Gutenberg. [Type] Enhancement A suggestion for improvement.

Comments

@bph
Copy link
Contributor

bph commented May 24, 2022

What problem does this address?

At the moment, `remove_theme_support( 'core-block-patterns' ); is an all or nothing with allowing pattern directory patterns to be viewed in the inserter.
Being able to still use the theme.json registration of pattern via slugs from the pattern directory, allows a curated list of patterns and more granular control.

What is your proposed solution?

The theme developer would set in functions.php remove_theme_support( 'core-block-patterns' );
and set in theme.json the list of pattern allowed: "patterns": [ "short-text-surrounded-by-round-images", "partner-logos" ]

There could be a check that if there is a theme.json pattern setting, it would allow them to be visible in the Inserter.
Instead an "Disallow all" it should be an explicit allow.

With the growing number of pattern in the directory, a curation would help with the exposure of patterns in the editor. The more patterns there are the more theme developer would want to restrict the visiblity. This feature would give them the means instead of just blocking all patterns from the directory, select the few that should work well.

@ndiego ndiego added [Type] Enhancement A suggestion for improvement. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Pattern Directory The Pattern Directory, a place to find patterns labels May 24, 2022
@ndiego
Copy link
Member

ndiego commented May 24, 2022

Yes, I have confirmed the current functionality, and agree with this proposal.

While I still think many themes will register their own patterns and use remove_theme_support( 'core-block-patterns' );, they may also was to pull a few curated patterns into the theme from the Pattern Directory. Alternatively, the theme author might want to submit all their theme patterns to the Directory, and then only pull their own patterns into the theme. The existing setup does not seem to support these use-cases.

@bph bph changed the title When removing core pattern, allow theme.json pattern slugs to be views. When removing core pattern, allow theme.json pattern slugs to be listed in inserter May 24, 2022
@bph bph added the Needs Dev Ready for, and needs developer efforts label May 24, 2022
@carolinan
Copy link
Contributor

I agree, I think it would make it easier for theme authors to select exactly which patterns they want to feature from the directory.
And loading "your" patterns from the directory would reduce the amount of repetition and number of files in the theme. Especially if you have a set of themes all using the same patterns.

@bph bph added the [Focus] Blocks Adoption For issues that directly impact the ability to adopt features of Gutenberg. label Jun 2, 2022
@ndiego
Copy link
Member

ndiego commented Jun 2, 2022

@bph and @carolinan are you testing with Gutenberg active? I have been trying to diagnose this today and think I found a solution, but it depends on #40824 being resolved. There were changes made in core that have not yet been backported to Gutenberg.

I will write up a PR, but if you have a chance to test, can you try the following?

  1. Setup a local site with 6.0 and Twenty Twenty Two installed (do not activate Gutenberg)
  2. Add remove_theme_support( 'core-block-patterns' ); on line 30 of the functions.php file
  3. Confirm that the core patterns do not display in the inserter, only the theme patterns
  4. Add "patterns": [ "short-text-surrounded-by-round-images", "partner-logos" ] to the theme.json file
  5. Confirm that the patterns do not show in the inserter
  6. Open the wp-includes/block-patterns.php file in your local install
  7. Comment out lines 136-143
  8. Confirm that the patterns added via theme.json now display in the inserter

Let me know if you run into any issues. Thanks! 🙏

@bph
Copy link
Contributor Author

bph commented Jun 7, 2022

@ndiego I just followed your instructions and the patterns from the directory showed up nicely.

@richtabor
Copy link
Member

Alternatively, the theme author might want to submit all their theme patterns to the Directory, and then only pull their own patterns into the theme.

I'm thinking this may be the norm one day. Instead of including them in a single theme, having the patterns available within the theme — but also for everyone else.

@ndiego
Copy link
Member

ndiego commented Jun 30, 2022

This was closed incorrectly, reopening.

@ndiego ndiego reopened this Jun 30, 2022
@fklein-lu
Copy link
Contributor

Tried the PR, and looks good. 👍

@ndiego ndiego added [Status] In Progress Tracking issues with work in progress and removed Needs Dev Ready for, and needs developer efforts labels Jul 15, 2022
@ndiego
Copy link
Member

ndiego commented Aug 26, 2022

This fix will be included in WordPress 6.0.2, and I just added #43634 to fix the 6.0 compat file in Gutenberg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Pattern Directory The Pattern Directory, a place to find patterns [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Focus] Blocks Adoption For issues that directly impact the ability to adopt features of Gutenberg. [Type] Enhancement A suggestion for improvement.
Projects
None yet
6 participants