-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add custom category support #5
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
Conversation
parthnvaswani
commented
Aug 4, 2025
- Add support to show and sync custom pattern categories
- Fix category tab QA issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for custom pattern categories by enabling the system to retrieve user-created categories from the WordPress taxonomy system and include them in category listings alongside the default registered categories.
- Integrate custom categories from
wp_pattern_categorytaxonomy into pattern category retrieval - Fix quote consistency in JavaScript files by converting from double quotes to single quotes
- Update category handling to avoid duplicates and ensure proper error messaging
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| inc/classes/class-rest.php | Adds custom category retrieval and duplicate checking for pattern categories |
| inc/classes/class-hooks.php | Registers pattern categories as taxonomy terms when patterns are registered |
| assets/src/plugins/consumer-site.js | Converts string literals from double quotes to single quotes |
| assets/src/patterns-popover/components/MemoizedPatternPreview.js | Quote style consistency fixes |
| assets/src/patterns-popover/components/LibraryModal.js | Quote style consistency fixes |
| assets/src/patterns-popover/components/Category.js | Improves error handling and display logic for categories |
| assets/src/patterns-popover/components/BasePatternsTab.js | Quote style consistency fixes |
| assets/src/patterns-popover/components/AppliedPatternsTab.js | Quote style consistency fixes |
| assets/src/css/admin.scss | Minor CSS formatting improvements |
| README.md | Updates GitHub repository URL |
| $pattern['category_labels'] = array(); | ||
| if ( ! empty( $pattern['categories'] ) && is_array( $pattern['categories'] ) ) { | ||
| foreach ( $pattern['categories'] as $category_name ) { | ||
| if ( ! empty( $categories ) && is_array( $categories ) ) { |
Copilot
AI
Aug 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name '$categories' is incorrect here. Based on the context, this should be '$pattern['categories']' to match the original logic that was checking the pattern's categories array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a false positive. $categories is the right variable used over here.
| $pattern_categories = \WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(); | ||
|
|
||
| $user_created_categories = get_terms( | ||
| array( | ||
| 'taxonomy' => 'wp_pattern_category', | ||
| 'hide_empty' => false, | ||
| ) | ||
| ); | ||
|
|
||
| if ( ! is_wp_error( $user_created_categories ) && ! empty( $user_created_categories ) && is_array( $user_created_categories ) ) { | ||
| foreach ( $user_created_categories as $category ) { | ||
| // Ensure the category has a name and label. | ||
| if ( ! empty( $category->name ) && ! empty( $category->slug ) ) { | ||
| $pattern_categories[] = array( | ||
| 'name' => $category->slug, | ||
| 'label' => $category->name, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
Copilot
AI
Aug 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code duplicates the logic found in the get_pattern_categories method (lines 560-589). Consider extracting this into a private method to avoid code duplication.
| $pattern_categories = \WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(); | |
| $user_created_categories = get_terms( | |
| array( | |
| 'taxonomy' => 'wp_pattern_category', | |
| 'hide_empty' => false, | |
| ) | |
| ); | |
| if ( ! is_wp_error( $user_created_categories ) && ! empty( $user_created_categories ) && is_array( $user_created_categories ) ) { | |
| foreach ( $user_created_categories as $category ) { | |
| // Ensure the category has a name and label. | |
| if ( ! empty( $category->name ) && ! empty( $category->slug ) ) { | |
| $pattern_categories[] = array( | |
| 'name' => $category->slug, | |
| 'label' => $category->name, | |
| ); | |
| } | |
| } | |
| } | |
| $pattern_categories = $this->get_merged_pattern_categories(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is enough difference in the for loop logic that it shouldn't be extracted in a different function.
rtBot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code analysis identified issues
action-phpcs-code-review has identified potential problems in this pull request during automated scanning. We recommend reviewing the issues noted and that they are resolved.
phpcs scanning turned up:
Powered by rtCamp's GitHub Actions Library