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

Patterns: add categories to user created patterns #53164

Closed
9 tasks done
glendaviesnz opened this issue Jul 31, 2023 · 8 comments
Closed
9 tasks done

Patterns: add categories to user created patterns #53164

glendaviesnz opened this issue Jul 31, 2023 · 8 comments
Assignees
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Enhancement A suggestion for improvement. [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.

Comments

@glendaviesnz
Copy link
Contributor

glendaviesnz commented Jul 31, 2023

Overview

Currently, there is no way for users to categorize/arrange their synced and unsynced patterns, they all appear under the 'My patterns' category.

Proposed solution?

Add a WP custom taxonomy called wp_pattern_category for the wp_block CPT.

The .org and theme patterns have a category registry, but these categories are generated on load based on the .org and theme patterns that are currently available to the site. There is no way for users to add/save their own categories, or to assign them to the wp_block CPT.

Options were explored of adding the existing pattern slugs to the wp_block CPT postmeta, but there would be performance issues with retrieving all patterns with a given category with this approach, and this also does not allow users to add their own categories.

WP taxonomies are a standard way to allow categorization of custom CPTs, and all the add/update/search functionality already exists, so this seems like the best way to add this functionality.

N.B. Tasks 2-5 below should all go into the same release, so ideally should be merged only when all 6 are ready to go
#53835 is the parent PR
#53837 & #53933 are branched off #53835
#54007 is branched off #53933

so merge order should be #54007, #53933, #53837, #53835

Tasks

@glendaviesnz glendaviesnz added [Type] Enhancement A suggestion for improvement. [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Jul 31, 2023
@glendaviesnz
Copy link
Contributor Author

glendaviesnz commented Jul 31, 2023

@aaronrobertshaw, @kevin940726, @youknowriad, @Mamaduka, @carolinan, @t-hamano let me know if you have any thoughts on whether a standard WP custom taxonomy is the best approach for this or not

@Mamaduka
Copy link
Member

Agreed, taxonomies are more suited for this and are more performant when querying the items vs. post meta.

P.S. We should probably drop the custom from the name - wp_pattern_category. The entities that ship with WordPress are native.

@t-hamano
Copy link
Contributor

I too think taxonomy is the way to go. The reason is that the template parts area is also registered as a taxonomy and I think the pattern should be able to have a similar design.

@glendaviesnz
Copy link
Contributor Author

We should probably drop the custom from the name - wp_pattern_category. The entities that ship with WordPress are native.

Have made that change on the PR. In my mind I was thinking of custom as being the user's custom patterns as opposed to the theme/.org patterns, but I can see how that wording would be confusing.

@aaronrobertshaw
Copy link
Contributor

+1 to pattern categories via a taxonomy.

The querying performance, consistency with template parts, and leveraging of existing features are all compelling reasons to me.

@mtias
Copy link
Member

mtias commented Aug 9, 2023

Taxonomy is correct — the thing I'm worried about is the overlap between semantic template parts and pattern categories, specially given they are separate objects (wp_template_part and wp_block). Which would render a term of "header" associated only with wp_block ambiguous. We might need to share the taxonomy.

@glendaviesnz
Copy link
Contributor Author

glendaviesnz commented Aug 10, 2023

Thanks for raising the concern about the crossover with template parts @mtias. This overlap was already an issue with the pattern categories that are assigned to .org/theme patterns. This is one of the main reasons the Template parts heading was put back in the Patterns section of the site editor as there were two entries of header and footer one for patterns and one for template parts, and no clear indication to users why they were duplicated.

Screenshot 2023-08-10 at 4 05 11 PM

In the short term giving users the ability to add their own patterns to a header or footer category won't add any additional ambiguity to what is already there (the user pattern categories will be merged with the .org/theme pattern categories).

I agree though that it would be good to have a shared taxonomy so users just see one Header or Footer category, which would then show them all the template parts & patterns related to headers and footers. Exactly how this might be achieved depends on how/when/if template parts might merge with patterns.

While we could reuse the existing wp_template_part_area taxonomy for patterns it is an odd fit name-wise, and I am not sure about the risks of a rename in terms of database migrations, backwards compat with plugins, etc.

It seems like the lower-risk option is to proceed with adding the wp_patterns_category. Then the first step of removing the ambiguity could be to merge the template and pattern category results in the patterns page. Once the future of template parts in relation to patterns is decided decisions could then be made on how taxonomies could be further merged, and based on recent changes it seems like this is more likely to be template parts merging to patterns rather than the other way around, so the wp_patterns_category is more likely to be the taxonomy that is still needed.

Let me know if you have any different views/thoughts on this.

@glendaviesnz
Copy link
Contributor Author

This work has been completed and is in GB 16.7 which will be used in the 6.4 beta release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Enhancement A suggestion for improvement. [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
No open projects
Status: Done
Status: Done
Development

No branches or pull requests

5 participants