Skip to content

Conversation

@parthnvaswani
Copy link
Collaborator

  • Add support to show and sync custom pattern categories
  • Fix category tab QA issues

@parthnvaswani parthnvaswani requested a review from danish17 August 4, 2025 08:08
@danish17 danish17 requested a review from Copilot August 4, 2025 08:19
Copy link
Contributor

Copilot AI left a 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_category taxonomy 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 ) ) {
Copy link

Copilot AI Aug 4, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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.

Comment on lines 757 to 777
$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,
);
}
}
}

Copy link

Copilot AI Aug 4, 2025

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.

Suggested change
$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();

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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.

Copy link

@rtBot rtBot left a 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:

⚠️ 1 warning


Powered by rtCamp's GitHub Actions Library

@parthnvaswani parthnvaswani merged commit 4c41ae9 into main Aug 4, 2025
5 checks passed
@up1512001 up1512001 deleted the feature/custom-categories-support branch October 13, 2025 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants