Skip to content

Icons: Add category for icons #76519

Open
im3dabasia wants to merge 9 commits intoWordPress:trunkfrom
im3dabasia:feat/add-icon-category
Open

Icons: Add category for icons #76519
im3dabasia wants to merge 9 commits intoWordPress:trunkfrom
im3dabasia:feat/add-icon-category

Conversation

@im3dabasia
Copy link
Copy Markdown
Contributor

What?

Closes #75715 (Category Support)

Adds icon category support to the Icons API so consumers can group icons (including brand/group-based sets).

Why?

Icon consumers need a consistent way to group and discover icons by category, similar to block pattern categories.

How?

  • Added a dedicated icon categories registry (Gutenberg_Icon_Categories_Registry_7_1 similar to WP_Block_Pattern_Categories_Registry)

  • Added a REST controller for icon categories (Gutenberg_REST_Icons_Categories_Controller_7_1)

Endpoints

GET /wp-json/wp/v2/icons

  • Includes icon metadata (and category where available in the registry payload).

GET /wp-json/wp/v2/icons/categories

  • Returns registered icon categories from the icon category registry.

Notes / Current Scope

  • Category labels/slugs are initial choices for now and can be updated based on feedback.
  • Current model is single category per icon.
  • Multi-category support can be explored in a follow-up iteration/future PR if needed.

Testing Instructions

  1. Hit GET /wp-json/wp/v2/icons and verify icons are returned with category.
  2. Hit GET /wp-json/wp/v2/icons/categories and verify category objects are returned.

Screenshots or screencast

Screen.Recording.2026-03-16.at.10.40.34.AM.mov

@im3dabasia im3dabasia self-assigned this Mar 16, 2026
@im3dabasia im3dabasia added REST API Interaction Related to REST API [Package] Icons /packages/icons [Type] Enhancement A suggestion for improvement. labels Mar 16, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 16, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: hiroshisatoy <hiroshisato@git.wordpress.org>
Co-authored-by: alexandrebuffet <alexandrebuffet@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: mikemcalister <mmcalister@git.wordpress.org>
Co-authored-by: pbearne <pbearne@git.wordpress.org>
Co-authored-by: mrwweb <mrwweb@git.wordpress.org>
Co-authored-by: eric-michel <ytfeldrawkcab@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown
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 icon category support to the Icons API to enable grouping/discovery of icons by category, including exposing registered categories via a new REST endpoint.

Changes:

  • Added an icon categories registry and public wrapper functions for registering/unregistering categories.
  • Added a REST controller and route for /wp/v2/icons/categories, and extended the icons REST schema to expose an icon category.
  • Added category metadata across icon manifests and updated the PHP manifest generation script.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/icons/src/manifest.php Adds category metadata to the public icon manifest entries.
packages/icons/src/manifest.json Adds category metadata for all icons in the source manifest.
packages/icons/lib/generate-manifest-php.cjs Emits category into the generated PHP manifest.
lib/load.php Loads the new registry/controller and category APIs for the WP 7.1 compat layer.
lib/compat/wordpress-7.1/rest-api.php Registers the new icon categories REST routes alongside icons routes.
lib/compat/wordpress-7.1/icon-categories.php Adds register_icon_category()/unregister_icon_category() and registers core categories on init.
lib/compat/wordpress-7.1/class-gutenberg-rest-icons-controller-7-1.php Extends icons REST output/schema to include category.
lib/compat/wordpress-7.1/class-gutenberg-rest-icons-categories-controller-7-1.php New REST controller for listing registered icon categories.
lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php Adds category support when registering icons from the manifest.
lib/compat/wordpress-7.1/class-gutenberg-icon-categories-registry-7-1.php New singleton registry to manage icon categories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +90 to +107
public function prepare_item_for_response( $item, $request ) {
$keys = array(
'name' => 'name',
'label' => 'label',
'content' => 'content',
'category' => 'category',
);
$data = array();
foreach ( $keys as $item_key => $rest_key ) {
if ( isset( $item[ $item_key ] ) ) {
$data[ $rest_key ] = $item[ $item_key ];
}
}

$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
return rest_ensure_response( $data );
Comment on lines 46 to 51
'label' => $icon_data['label'],
'filePath' => $icons_directory . $icon_data['filePath'],
'category' => ! empty( $icon_data['category'] ) && is_string( $icon_data['category'] )
? $icon_data['category']
: null,
)
Comment on lines 12 to +17
function gutenberg_register_icons_controller_endpoints() {
$icons_controller = new Gutenberg_REST_Icons_Controller_7_1();
$icons_controller->register_routes();

$icon_categories_controller = new Gutenberg_REST_Icons_Categories_Controller_7_1();
$icon_categories_controller->register_routes();
im3dabasia and others added 3 commits March 16, 2026 13:55
@t-hamano t-hamano added [Feature] Icon Related to Icon registration API and Icon REST API and removed [Package] Icons /packages/icons labels Mar 16, 2026
@t-hamano
Copy link
Copy Markdown
Contributor

t-hamano commented Mar 16, 2026

Thanks for the PR!

In my opinion, many consumers will want to register multiple icons as their collections. That is, they should be structured like this:

Collections (e.g. Google Fonts, Font Awesome) > Categories (e.g. Allows, Social) > Icons

Therefore, I think we need an API for registering collections, rather than an API for registering categories. Please refer to this updated section.

@t-hamano t-hamano added [Status] Blocked Used to indicate that a current effort isn't able to move forward and removed REST API Interaction Related to REST API labels Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Icon Related to Icon registration API and Icon REST API [Status] Blocked Used to indicate that a current effort isn't able to move forward [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG Icon API: Iteration for WordPress 7.1

3 participants