From ddf804233c490ba8b4c485c65f3290bfd0f89b70 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Tue, 22 Sep 2026 13:43:12 -0500 Subject: [PATCH 1/8] backport php files --- src/wp-includes/class-wp-icons-registry.php | 80 +++++++++++++++---- src/wp-includes/icons.php | 26 +++--- .../class-wp-rest-icons-controller.php | 13 +++ 3 files changed, 95 insertions(+), 24 deletions(-) diff --git a/src/wp-includes/class-wp-icons-registry.php b/src/wp-includes/class-wp-icons-registry.php index 5a0296a9209cd..efa01118d3cac 100644 --- a/src/wp-includes/class-wp-icons-registry.php +++ b/src/wp-includes/class-wp-icons-registry.php @@ -53,15 +53,17 @@ protected function __construct() {} * @param array $icon_properties { * List of properties for the icon. * - * @type string $label Required. A human-readable label for the icon. - * @type string $content Optional. SVG markup for the icon. - * If not provided, the content will be retrieved from the `file_path` if set. - * If both `content` and `file_path` are not set, the icon will not be registered. - * @type string $file_path Optional. The full path to the file containing the icon content. - * @type bool $public Optional. Whether the icon is exposed through the REST API, and - * therefore selectable in the editor's icon picker. Non-public icons - * stay available to server-side code via {@see wp_get_icon()}. - * Default true. + * @type string $label Required. A human-readable label for the icon. + * @type string $content Optional. SVG markup for the icon. + * If not provided, the content will be retrieved from the `file_path` if set. + * If both `content` and `file_path` are not set, the icon will not be registered. + * @type string $file_path Optional. The full path to the file containing the icon content. + * @type bool $public Optional. Whether the icon is exposed through the REST API, and + * therefore selectable in the editor's icon picker. Non-public icons + * stay available to server-side code via {@see wp_get_icon()}. + * Default true. + * @type string[] $keywords Optional. Additional search terms for the icon, matched by + * `get_registered_icons()` alongside the name and label. * } * @return bool True if the icon was registered with success and false otherwise. */ @@ -106,7 +108,7 @@ public function register( $icon_name, $icon_properties ) { return false; } - $allowed_keys = array_fill_keys( array( 'label', 'content', 'file_path', 'public' ), 1 ); + $allowed_keys = array_fill_keys( array( 'label', 'content', 'file_path', 'public', 'keywords' ), 1 ); foreach ( array_keys( $icon_properties ) as $key ) { if ( ! array_key_exists( $key, $allowed_keys ) ) { _doing_it_wrong( @@ -153,6 +155,30 @@ public function register( $icon_name, $icon_properties ) { return false; } + if ( array_key_exists( 'keywords', $icon_properties ) ) { + if ( ! is_array( $icon_properties['keywords'] ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon keywords must be an array of strings.', 'gutenberg' ), + '7.2.0' + ); + return false; + } + + foreach ( $icon_properties['keywords'] as $keyword ) { + if ( ! is_string( $keyword ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon keywords must be an array of strings.', 'gutenberg' ), + '7.2.0' + ); + return false; + } + } + + $icon_properties['keywords'] = array_map( 'sanitize_text_field', $icon_properties['keywords'] ); + } + if ( ( ! isset( $icon_properties['content'] ) && ! isset( $icon_properties['file_path'] ) ) || ( isset( $icon_properties['content'] ) && isset( $icon_properties['file_path'] ) ) @@ -401,6 +427,35 @@ public function get_registered_icon( $icon_name ) { return $icon; } + + /** + * Determines whether an icon matches a search term. + * + * The term is matched case-insensitively against the icon's name, its label, + * and any of its keywords. + * + * @param array $icon Registered icon properties. + * @param string $search Search term. + * @return bool True if the icon matches the search term, false otherwise. + */ + protected function icon_matches_search( $icon, $search ) { + if ( false !== stripos( $icon['name'], $search ) ) { + return true; + } + + if ( false !== stripos( $icon['label'], $search ) ) { + return true; + } + + foreach ( $icon['keywords'] ?? array() as $keyword ) { + if ( false !== stripos( $keyword, $search ) ) { + return true; + } + } + + return false; + } + /** * Retrieves all registered icons. * @@ -414,10 +469,7 @@ public function get_registered_icons( $search = '' ) { $icons = array(); foreach ( $this->registered_icons as $icon ) { - if ( ! empty( $search ) - && false === stripos( $icon['name'], $search ) - && false === stripos( $icon['label'] ?? '', $search ) - ) { + if ( ! empty( $search ) && ! $this->icon_matches_search( $icon, $search ) ) { continue; } diff --git a/src/wp-includes/icons.php b/src/wp-includes/icons.php index 4c906ad939bc7..4f8db3a1140db 100644 --- a/src/wp-includes/icons.php +++ b/src/wp-includes/icons.php @@ -41,7 +41,7 @@ function wp_unregister_icon_collection( $slug ) { * Registers a new icon. * * @since 7.1.0 - * @since 7.2.0 Added the `public` property. + * @since 7.2.0 Added the `public` and `keywords` properties. * * @param string $icon_name Namespaced icon name in the form "collection/icon-name" * (e.g. "my-plugin/arrow-left"). The "core" collection is @@ -51,15 +51,17 @@ function wp_unregister_icon_collection( $slug ) { * @param array $args { * List of properties for the icon. * - * @type string $label Required. A human-readable label for the icon. - * @type string $content Optional. SVG markup for the icon. - * If not provided, the content will be retrieved from the `file_path` if set. - * If both `content` and `file_path` are not set, the icon will not be registered. - * @type string $file_path Optional. The full path to the file containing the icon content. - * @type bool $public Optional. Whether the icon is exposed through the REST API, and - * therefore selectable in the editor's icon picker. Non-public icons - * stay available to server-side code via {@see wp_get_icon()}. - * Default true. + * @type string $label Required. A human-readable label for the icon. + * @type string $content Optional. SVG markup for the icon. + * If not provided, the content will be retrieved from the `file_path` if set. + * If both `content` and `file_path` are not set, the icon will not be registered. + * @type string $file_path Optional. The full path to the file containing the icon content. + * @type bool $public Optional. Whether the icon is exposed through the REST API, and + * therefore selectable in the editor's icon picker. Non-public icons + * stay available to server-side code via {@see wp_get_icon()}. + * Default true. + * @type string[] $keywords Optional. Additional search terms for the icon, matched by + * `get_registered_icons()` alongside the name and label. * } * @return bool True if the icon was registered successfully, else false. */ @@ -146,6 +148,10 @@ function _wp_register_default_icons() { $icon_args['public'] = $icon_data['public']; } + if ( isset( $icon_data['keywords'] ) ) { + $icon_args['keywords'] = $icon_data['keywords']; + } + wp_register_icon( 'core/' . $icon_name, $icon_args ); } } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php index 4578df9d28c1e..92036665e2815 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php @@ -229,6 +229,9 @@ public function get_icon( $name ) { /** * Prepare a raw icon before it gets output in a REST API response. * + * Adds `collection` and `keywords` fields to the base response while keeping + * the namespaced icon name (e.g. `core/arrow-left`) as the `name` field. + * * @since 7.0.0 * @since 7.1.0 Added the `collection` field. * @@ -243,6 +246,7 @@ public function prepare_item_for_response( $item, $request ) { 'label' => 'label', 'content' => 'content', 'collection' => 'collection', + 'keywords' => 'keywords', ); $data = array(); foreach ( $keys as $item_key => $rest_key ) { @@ -299,6 +303,15 @@ public function get_item_schema() { 'readonly' => true, 'context' => array( 'view', 'edit', 'embed' ), ), + 'keywords' => array( + 'description' => __( 'Additional search terms for the icon.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', + ), + 'readonly' => true, + 'context' => array( 'view', 'edit', 'embed' ), + ), ), ); From 04af1d3acf27e55b6134ac4aa944f448ae18510a Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Tue, 22 Sep 2026 13:49:06 -0500 Subject: [PATCH 2/8] backport phpunit tests --- tests/phpunit/tests/icons/wpIconsRegistry.php | 185 ++++++++++++++++++ .../tests/icons/wpRestIconsController.php | 64 ++++++ 2 files changed, 249 insertions(+) diff --git a/tests/phpunit/tests/icons/wpIconsRegistry.php b/tests/phpunit/tests/icons/wpIconsRegistry.php index 34ba5330b6ab1..bebfdba042f51 100644 --- a/tests/phpunit/tests/icons/wpIconsRegistry.php +++ b/tests/phpunit/tests/icons/wpIconsRegistry.php @@ -542,4 +542,189 @@ public function test_register_rejects_non_boolean_public_property() { $this->assertFalse( $result ); $this->assertFalse( $this->registry->is_registered( 'test-collection/invalid-visibility' ) ); } + + /** + * Should register an icon that provides a valid `keywords` array. + */ + public function test_register_icon_with_keywords() { + $name = 'test-collection/with-keywords'; + + $result = $this->register( + $name, + array( + 'label' => 'Icon', + 'content' => '', + 'keywords' => array( 'alpha', 'beta' ), + ) + ); + + $this->assertTrue( $result ); + + $icon = $this->registry->get_registered_icon( $name ); + $this->assertSame( array( 'alpha', 'beta' ), $icon['keywords'] ); + } + + /** + * Should register an icon that omits `keywords`, since the property is optional. + */ + public function test_register_icon_without_keywords() { + $name = 'test-collection/without-keywords'; + + $result = $this->register( + $name, + array( + 'label' => 'Icon', + 'content' => '', + ) + ); + + $this->assertTrue( $result ); + + $icon = $this->registry->get_registered_icon( $name ); + $this->assertArrayNotHasKey( 'keywords', $icon ); + } + + /** + * Provides values that are not an array of strings. + * + * @return array + */ + public function data_invalid_keywords() { + return array( + 'null' => array( null ), + 'a string' => array( 'alpha' ), + 'an integer' => array( 5 ), + 'an array of integers' => array( array( 1, 2 ) ), + 'a mixed array' => array( array( 'alpha', 5 ) ), + 'a nested array' => array( array( array( 'alpha' ) ) ), + 'an array of null' => array( array( null ) ), + ); + } + + /** + * Should fail to register an icon whose `keywords` is not an array of strings. + * + * @dataProvider data_invalid_keywords + * @expectedIncorrectUsage WP_Icons_Registry_Gutenberg::register + * + * @param mixed $keywords Invalid keywords candidate. + */ + public function test_register_icon_with_invalid_keywords( $keywords ) { + $name = 'test-collection/invalid-keywords'; + + $result = $this->register( + $name, + array( + 'label' => 'Icon', + 'content' => '', + 'keywords' => $keywords, + ) + ); + + $this->assertFalse( $result ); + $this->assertFalse( $this->registry->is_registered( $name ) ); + } + + /** + * Should match an icon by keyword when neither its name nor its label match. + */ + public function test_get_registered_icons_matches_keywords() { + $this->register( + 'test-collection/dove', + array( + 'label' => 'Dove', + 'content' => '', + 'keywords' => array( 'peace' ), + ) + ); + $this->register( + 'test-collection/anvil', + array( + 'label' => 'Anvil', + 'content' => '', + ) + ); + + /** + * The search term is deliberately absent from both the name and the label, + * so a match can only come from the keywords. + */ + $icon = $this->registry->get_registered_icon( 'test-collection/dove' ); + $this->assertStringNotContainsStringIgnoringCase( 'peace', $icon['name'] ); + $this->assertStringNotContainsStringIgnoringCase( 'peace', $icon['label'] ); + + $names = array_column( $this->registry->get_registered_icons( 'peace' ), 'name' ); + + $this->assertContains( + 'test-collection/dove', + $names, + 'Search results should include an icon matched only by its keyword' + ); + $this->assertNotContains( + 'test-collection/anvil', + $names, + 'Search results should exclude an icon that matches on no property' + ); + } + + /** + * Should match keywords case-insensitively, as names and labels are. + */ + public function test_get_registered_icons_matches_keywords_case_insensitively() { + $this->register( + 'test-collection/dove', + array( + 'label' => 'Dove', + 'content' => '', + 'keywords' => array( 'peace' ), + ) + ); + + $names = array_column( $this->registry->get_registered_icons( 'PEACE' ), 'name' ); + + $this->assertContains( 'test-collection/dove', $names ); + } + + /** + * Should not drop a third-party icon's keywords when an existing base registry + * is upgraded to the Gutenberg registry. + */ + public function test_get_instance_preserves_keywords_when_upgrading_base_registry() { + // Build a base registry without invoking the constructor, which would + // register the core icons from the core manifest. + $base = ( new ReflectionClass( WP_Icons_Registry::class ) )->newInstanceWithoutConstructor(); + + $icons_property = new ReflectionProperty( WP_Icons_Registry::class, 'registered_icons' ); + if ( PHP_VERSION_ID < 80100 ) { + $icons_property->setAccessible( true ); + } + $icons_property->setValue( + $base, + array( + 'test-collection/dove' => array( + 'name' => 'test-collection/dove', + 'collection' => 'test-collection', + 'label' => 'Dove', + 'content' => '', + 'keywords' => array( 'peace' ), + ), + ) + ); + + $instance_property = new ReflectionProperty( WP_Icons_Registry_Gutenberg::class, 'instance' ); + if ( PHP_VERSION_ID < 80100 ) { + $instance_property->setAccessible( true ); + } + $instance_property->setValue( null, $base ); + + $upgraded = WP_Icons_Registry_Gutenberg::get_instance(); + + $this->assertInstanceOf( WP_Icons_Registry_Gutenberg::class, $upgraded ); + + $icon = $upgraded->get_registered_icon( 'test-collection/dove' ); + $this->assertSame( array( 'peace' ), $icon['keywords'] ); + + $names = array_column( $upgraded->get_registered_icons( 'peace' ), 'name' ); + $this->assertContains( 'test-collection/dove', $names ); + } } diff --git a/tests/phpunit/tests/icons/wpRestIconsController.php b/tests/phpunit/tests/icons/wpRestIconsController.php index 41b4c578f0b6b..fc8c9d7642d9e 100644 --- a/tests/phpunit/tests/icons/wpRestIconsController.php +++ b/tests/phpunit/tests/icons/wpRestIconsController.php @@ -405,6 +405,70 @@ public function test_get_items_search_includes_label() { $this->assertEquals( array( 'core/at-symbol' ), array_column( $data, 'name' ) ); } + /** + * Test that GET /wp/v2/icons/?search=%s searches icon keywords too. + */ + public function test_get_items_search_includes_keywords() { + wp_set_current_user( self::$editor_id ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); + + // 'hamburger' is only found in the *keywords* for core/menu. + $request->set_param( 'search', 'hamburger' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + + $this->assertSame( 200, $response->get_status() ); + $this->assertEquals( array( 'core/menu' ), array_column( $data, 'name' ) ); + } + + /** + * Test that the response exposes an icon's keywords, so that clients which + * filter icons locally can match against them. + */ + public function test_get_items_response_includes_keywords() { + wp_set_current_user( self::$editor_id ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); + $request->set_param( 'search', 'core/menu' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + + $this->assertSame( 200, $response->get_status() ); + $this->assertCount( 1, $data ); + $this->assertArrayHasKey( 'keywords', $data[0] ); + $this->assertContains( 'hamburger', $data[0]['keywords'] ); + } + + /** + * Test that icons registered without keywords still expose an empty array, + * so consumers do not have to handle a missing field. + */ + public function test_get_items_response_keywords_defaults_to_empty_array() { + wp_set_current_user( self::$editor_id ); + + wp_register_icon( + 'core/no-keywords', + array( + 'label' => 'No Keywords', + 'content' => '', + ) + ); + + try { + $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); + $request->set_param( 'search', 'core/no-keywords' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + + $this->assertSame( 200, $response->get_status() ); + $this->assertCount( 1, $data ); + $this->assertSame( array(), $data[0]['keywords'] ); + } finally { + wp_unregister_icon( 'core/no-keywords' ); + } + } + /** * Test that search is case-insensitive. * From 7cc5c7ad478730479495d2810ec9390b56343124 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Tue, 22 Sep 2026 16:42:19 -0500 Subject: [PATCH 3/8] backport updates --- .../assets/icon-library-manifest.php | 88 +++++++++++++++++++ src/wp-includes/class-wp-icons-registry.php | 34 +++---- src/wp-includes/icons.php | 22 ++--- .../class-wp-rest-icons-controller.php | 11 ++- tests/phpunit/tests/icons/wpIconsRegistry.php | 57 ++---------- .../tests/icons/wpRestIconsController.php | 2 +- 6 files changed, 136 insertions(+), 78 deletions(-) diff --git a/src/wp-includes/assets/icon-library-manifest.php b/src/wp-includes/assets/icon-library-manifest.php index af72a1c00499c..3a47601705a36 100644 --- a/src/wp-includes/assets/icon-library-manifest.php +++ b/src/wp-includes/assets/icon-library-manifest.php @@ -8,353 +8,441 @@ 'arrow-down-left' => array( 'label' => _x( 'Arrow Down Left', 'icon label' ), 'filePath' => 'arrow-down-left.svg', + 'keywords' => array( _x( 'southwest', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-down-right' => array( 'label' => _x( 'Arrow Down Right', 'icon label' ), 'filePath' => 'arrow-down-right.svg', + 'keywords' => array( _x( 'southeast', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-down' => array( 'label' => _x( 'Arrow Down', 'icon label' ), 'filePath' => 'arrow-down.svg', + 'keywords' => array( _x( 'south', 'icon keyword' ), _x( 'descend', 'icon keyword' ) ), ), 'arrow-left' => array( 'label' => _x( 'Arrow Left', 'icon label' ), 'filePath' => 'arrow-left.svg', + 'keywords' => array( _x( 'west', 'icon keyword' ), _x( 'back', 'icon keyword' ) ), ), 'arrow-right' => array( 'label' => _x( 'Arrow Right', 'icon label' ), 'filePath' => 'arrow-right.svg', + 'keywords' => array( _x( 'east', 'icon keyword' ), _x( 'forward', 'icon keyword' ) ), ), 'arrow-up-left' => array( 'label' => _x( 'Arrow Up Left', 'icon label' ), 'filePath' => 'arrow-up-left.svg', + 'keywords' => array( _x( 'northwest', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-up-right' => array( 'label' => _x( 'Arrow Up Right', 'icon label' ), 'filePath' => 'arrow-up-right.svg', + 'keywords' => array( _x( 'northeast', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-up' => array( 'label' => _x( 'Arrow Up', 'icon label' ), 'filePath' => 'arrow-up.svg', + 'keywords' => array( _x( 'north', 'icon keyword' ), _x( 'ascend', 'icon keyword' ) ), ), 'at-symbol' => array( 'label' => _x( 'At Symbol (@)', 'icon label' ), 'filePath' => 'at-symbol.svg', + 'keywords' => array( _x( 'email', 'icon keyword' ), _x( 'mention', 'icon keyword' ), _x( 'username', 'icon keyword' ) ), ), 'audio' => array( 'label' => _x( 'Audio', 'icon label' ), 'filePath' => 'audio.svg', + 'keywords' => array( _x( 'sound', 'icon keyword' ), _x( 'music', 'icon keyword' ), _x( 'speaker', 'icon keyword' ) ), ), 'bell' => array( 'label' => _x( 'Bell', 'icon label' ), 'filePath' => 'bell.svg', + 'keywords' => array( _x( 'notification', 'icon keyword' ), _x( 'alert', 'icon keyword' ), _x( 'reminder', 'icon keyword' ) ), ), 'block-default' => array( 'label' => _x( 'Block Default', 'icon label' ), 'filePath' => 'block-default.svg', + 'keywords' => array( _x( 'placeholder', 'icon keyword' ), _x( 'generic', 'icon keyword' ) ), ), 'block-meta' => array( 'label' => _x( 'Block Meta', 'icon label' ), 'filePath' => 'block-meta.svg', + 'keywords' => array( _x( 'metadata', 'icon keyword' ), _x( 'custom field', 'icon keyword' ) ), ), 'block-table' => array( 'label' => _x( 'Block Table', 'icon label' ), 'filePath' => 'block-table.svg', + 'keywords' => array( _x( 'grid', 'icon keyword' ), _x( 'spreadsheet', 'icon keyword' ) ), ), 'calendar' => array( 'label' => _x( 'Calendar', 'icon label' ), 'filePath' => 'calendar.svg', + 'keywords' => array( _x( 'date', 'icon keyword' ), _x( 'schedule', 'icon keyword' ), _x( 'event', 'icon keyword' ) ), ), 'capture-photo' => array( 'label' => _x( 'Capture Photo', 'icon label' ), 'filePath' => 'capture-photo.svg', + 'keywords' => array( _x( 'camera', 'icon keyword' ), _x( 'snapshot', 'icon keyword' ) ), ), 'capture-video' => array( 'label' => _x( 'Capture Video', 'icon label' ), 'filePath' => 'capture-video.svg', + 'keywords' => array( _x( 'camcorder', 'icon keyword' ), _x( 'record', 'icon keyword' ) ), ), 'cart' => array( 'label' => _x( 'Cart', 'icon label' ), 'filePath' => 'cart.svg', + 'keywords' => array( _x( 'shopping', 'icon keyword' ), _x( 'basket', 'icon keyword' ), _x( 'checkout', 'icon keyword' ), _x( 'ecommerce', 'icon keyword' ) ), ), 'category' => array( 'label' => _x( 'Category', 'icon label' ), 'filePath' => 'category.svg', + 'keywords' => array( _x( 'taxonomy', 'icon keyword' ), _x( 'archive', 'icon keyword' ) ), ), 'caution' => array( 'label' => _x( 'Caution', 'icon label' ), 'filePath' => 'caution.svg', + 'keywords' => array( _x( 'warning', 'icon keyword' ), _x( 'alert', 'icon keyword' ), _x( 'danger', 'icon keyword' ) ), ), 'chart-bar' => array( 'label' => _x( 'Chart Bar', 'icon label' ), 'filePath' => 'chart-bar.svg', + 'keywords' => array( _x( 'graph', 'icon keyword' ), _x( 'statistics', 'icon keyword' ), _x( 'analytics', 'icon keyword' ) ), ), 'check' => array( 'label' => _x( 'Check', 'icon label' ), 'filePath' => 'check.svg', + 'keywords' => array( _x( 'tick', 'icon keyword' ), _x( 'done', 'icon keyword' ), _x( 'confirm', 'icon keyword' ), _x( 'success', 'icon keyword' ) ), ), 'chevron-down' => array( 'label' => _x( 'Chevron Down', 'icon label' ), 'filePath' => 'chevron-down.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'expand', 'icon keyword' ) ), ), 'chevron-down-small' => array( 'label' => _x( 'Chevron Down Small', 'icon label' ), 'filePath' => 'chevron-down-small.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'expand', 'icon keyword' ) ), ), 'chevron-left' => array( 'label' => _x( 'Chevron Left', 'icon label' ), 'filePath' => 'chevron-left.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'back', 'icon keyword' ) ), ), 'chevron-left-small' => array( 'label' => _x( 'Chevron Left Small', 'icon label' ), 'filePath' => 'chevron-left-small.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'back', 'icon keyword' ) ), ), 'chevron-right' => array( 'label' => _x( 'Chevron Right', 'icon label' ), 'filePath' => 'chevron-right.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'forward', 'icon keyword' ) ), ), 'chevron-right-small' => array( 'label' => _x( 'Chevron Right Small', 'icon label' ), 'filePath' => 'chevron-right-small.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'forward', 'icon keyword' ) ), ), 'chevron-up' => array( 'label' => _x( 'Chevron Up', 'icon label' ), 'filePath' => 'chevron-up.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'collapse', 'icon keyword' ) ), ), 'chevron-up-down' => array( 'label' => _x( 'Chevron Up Down', 'icon label' ), 'filePath' => 'chevron-up-down.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'sort', 'icon keyword' ), _x( 'reorder', 'icon keyword' ) ), ), 'chevron-up-small' => array( 'label' => _x( 'Chevron Up Small', 'icon label' ), 'filePath' => 'chevron-up-small.svg', + 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'collapse', 'icon keyword' ) ), ), 'comment' => array( 'label' => _x( 'Comment', 'icon label' ), 'filePath' => 'comment.svg', + 'keywords' => array( _x( 'reply', 'icon keyword' ), _x( 'discussion', 'icon keyword' ), _x( 'feedback', 'icon keyword' ) ), ), 'cover' => array( 'label' => _x( 'Cover', 'icon label' ), 'filePath' => 'cover.svg', + 'keywords' => array( _x( 'banner', 'icon keyword' ), _x( 'hero', 'icon keyword' ), _x( 'background', 'icon keyword' ) ), ), 'create' => array( 'label' => _x( 'Create', 'icon label' ), 'filePath' => 'create.svg', + 'keywords' => array( _x( 'new', 'icon keyword' ), _x( 'add', 'icon keyword' ), _x( 'compose', 'icon keyword' ), _x( 'plus', 'icon keyword' ) ), ), 'desktop' => array( 'label' => _x( 'Desktop', 'icon label' ), 'filePath' => 'desktop.svg', + 'keywords' => array( _x( 'computer', 'icon keyword' ), _x( 'monitor', 'icon keyword' ), _x( 'screen', 'icon keyword' ) ), ), 'download' => array( 'label' => _x( 'Download', 'icon label' ), 'filePath' => 'download.svg', + 'keywords' => array( _x( 'save', 'icon keyword' ), _x( 'export', 'icon keyword' ) ), ), 'drawer-left' => array( 'label' => _x( 'Drawer Left', 'icon label' ), 'filePath' => 'drawer-left.svg', + 'keywords' => array( _x( 'sidebar', 'icon keyword' ), _x( 'panel', 'icon keyword' ) ), ), 'drawer-right' => array( 'label' => _x( 'Drawer Right', 'icon label' ), 'filePath' => 'drawer-right.svg', + 'keywords' => array( _x( 'sidebar', 'icon keyword' ), _x( 'panel', 'icon keyword' ) ), ), 'envelope' => array( 'label' => _x( 'Envelope', 'icon label' ), 'filePath' => 'envelope.svg', + 'keywords' => array( _x( 'email', 'icon keyword' ), _x( 'mail', 'icon keyword' ), _x( 'message', 'icon keyword' ) ), ), 'error' => array( 'label' => _x( 'Error', 'icon label' ), 'filePath' => 'error.svg', + 'keywords' => array( _x( 'failure', 'icon keyword' ), _x( 'problem', 'icon keyword' ), _x( 'alert', 'icon keyword' ), _x( 'caution', 'icon keyword' ), _x( 'warning', 'icon keyword' ) ), ), 'external' => array( 'label' => _x( 'External', 'icon label' ), 'filePath' => 'external.svg', + 'keywords' => array( _x( 'outbound', 'icon keyword' ), _x( 'new window', 'icon keyword' ) ), ), 'file' => array( 'label' => _x( 'File', 'icon label' ), 'filePath' => 'file.svg', + 'keywords' => array( _x( 'attachment', 'icon keyword' ), _x( 'document', 'icon keyword' ), _x( 'folder', 'icon keyword' ) ), ), 'gallery' => array( 'label' => _x( 'Gallery', 'icon label' ), 'filePath' => 'gallery.svg', + 'keywords' => array( _x( 'photos', 'icon keyword' ), _x( 'album', 'icon keyword' ), _x( 'images', 'icon keyword' ) ), ), 'group' => array( 'label' => _x( 'Group', 'icon label' ), 'filePath' => 'group.svg', + 'keywords' => array( _x( 'container', 'icon keyword' ), _x( 'wrapper', 'icon keyword' ), _x( 'stack', 'icon keyword' ) ), ), 'heading' => array( 'label' => _x( 'Heading', 'icon label' ), 'filePath' => 'heading.svg', + 'keywords' => array( _x( 'title', 'icon keyword' ), _x( 'headline', 'icon keyword' ) ), ), 'help' => array( 'label' => _x( 'Help', 'icon label' ), 'filePath' => 'help.svg', + 'keywords' => array( _x( 'question', 'icon keyword' ), _x( 'support', 'icon keyword' ), _x( 'faq', 'icon keyword' ) ), ), 'home' => array( 'label' => _x( 'Home', 'icon label' ), 'filePath' => 'home.svg', + 'keywords' => array( _x( 'house', 'icon keyword' ), _x( 'front page', 'icon keyword' ), _x( 'dashboard', 'icon keyword' ) ), ), 'image' => array( 'label' => _x( 'Image', 'icon label' ), 'filePath' => 'image.svg', + 'keywords' => array( _x( 'photo', 'icon keyword' ), _x( 'picture', 'icon keyword' ), _x( 'media', 'icon keyword' ) ), ), 'info' => array( 'label' => _x( 'Info', 'icon label' ), 'filePath' => 'info.svg', + 'keywords' => array( _x( 'information', 'icon keyword' ), _x( 'about', 'icon keyword' ), _x( 'details', 'icon keyword' ) ), ), 'key' => array( 'label' => _x( 'Key', 'icon label' ), 'filePath' => 'key.svg', + 'keywords' => array( _x( 'password', 'icon keyword' ), _x( 'license', 'icon keyword' ), _x( 'credential', 'icon keyword' ) ), ), 'language' => array( 'label' => _x( 'Language', 'icon label' ), 'filePath' => 'language.svg', + 'keywords' => array( _x( 'translate', 'icon keyword' ), _x( 'locale', 'icon keyword' ), _x( 'globe', 'icon keyword' ) ), ), 'map-marker' => array( 'label' => _x( 'Map Marker', 'icon label' ), 'filePath' => 'map-marker.svg', + 'keywords' => array( _x( 'location', 'icon keyword' ), _x( 'pin', 'icon keyword' ), _x( 'address', 'icon keyword' ) ), ), 'menu' => array( 'label' => _x( 'Menu', 'icon label' ), 'filePath' => 'menu.svg', + 'keywords' => array( _x( 'hamburger', 'icon keyword' ), _x( 'navigation', 'icon keyword' ), _x( 'list', 'icon keyword' ) ), ), 'mobile' => array( 'label' => _x( 'Mobile', 'icon label' ), 'filePath' => 'mobile.svg', + 'keywords' => array( _x( 'phone', 'icon keyword' ), _x( 'smartphone', 'icon keyword' ), _x( 'handset', 'icon keyword' ) ), ), 'more-horizontal' => array( 'label' => _x( 'More Horizontal', 'icon label' ), 'filePath' => 'more-horizontal.svg', + 'keywords' => array( _x( 'ellipsis', 'icon keyword' ), _x( 'options', 'icon keyword' ), _x( 'overflow', 'icon keyword' ) ), ), 'more-vertical' => array( 'label' => _x( 'More Vertical', 'icon label' ), 'filePath' => 'more-vertical.svg', + 'keywords' => array( _x( 'ellipsis', 'icon keyword' ), _x( 'options', 'icon keyword' ), _x( 'overflow', 'icon keyword' ) ), ), 'next' => array( 'label' => _x( 'Next', 'icon label' ), 'filePath' => 'next.svg', + 'keywords' => array( _x( 'forward', 'icon keyword' ), _x( 'advance', 'icon keyword' ) ), ), 'paragraph' => array( 'label' => _x( 'Paragraph', 'icon label' ), 'filePath' => 'paragraph.svg', + 'keywords' => array( _x( 'text', 'icon keyword' ), _x( 'body copy', 'icon keyword' ) ), ), 'payment' => array( 'label' => _x( 'Payment', 'icon label' ), 'filePath' => 'payment.svg', + 'keywords' => array( _x( 'credit card', 'icon keyword' ), _x( 'billing', 'icon keyword' ), _x( 'checkout', 'icon keyword' ) ), ), 'pencil' => array( 'label' => _x( 'Pencil', 'icon label' ), 'filePath' => 'pencil.svg', + 'keywords' => array( _x( 'edit', 'icon keyword' ), _x( 'write', 'icon keyword' ), _x( 'modify', 'icon keyword' ) ), ), 'people' => array( 'label' => _x( 'People', 'icon label' ), 'filePath' => 'people.svg', + 'keywords' => array( _x( 'users', 'icon keyword' ), _x( 'team', 'icon keyword' ), _x( 'members', 'icon keyword' ) ), ), 'plus' => array( 'label' => _x( 'Plus', 'icon label' ), 'filePath' => 'plus.svg', + 'keywords' => array( _x( 'add', 'icon keyword' ), _x( 'new', 'icon keyword' ), _x( 'create', 'icon keyword' ) ), ), 'plus-circle' => array( 'label' => _x( 'Plus Circle', 'icon label' ), 'filePath' => 'plus-circle.svg', + 'keywords' => array( _x( 'add', 'icon keyword' ), _x( 'new', 'icon keyword' ), _x( 'create', 'icon keyword' ) ), ), 'previous' => array( 'label' => _x( 'Previous', 'icon label' ), 'filePath' => 'previous.svg', + 'keywords' => array( _x( 'back', 'icon keyword' ), _x( 'prior', 'icon keyword' ) ), ), 'published' => array( 'label' => _x( 'Published', 'icon label' ), 'filePath' => 'published.svg', + 'keywords' => array( _x( 'live', 'icon keyword' ), _x( 'visible', 'icon keyword' ), _x( 'public', 'icon keyword' ) ), ), 'quote' => array( 'label' => _x( 'Quote', 'icon label' ), 'filePath' => 'quote.svg', + 'keywords' => array( _x( 'blockquote', 'icon keyword' ), _x( 'citation', 'icon keyword' ), _x( 'testimonial', 'icon keyword' ) ), ), 'receipt' => array( 'label' => _x( 'Receipt', 'icon label' ), 'filePath' => 'receipt.svg', + 'keywords' => array( _x( 'invoice', 'icon keyword' ), _x( 'order', 'icon keyword' ), _x( 'bill', 'icon keyword' ) ), ), 'rss' => array( 'label' => _x( 'RSS', 'icon label' ), 'filePath' => 'rss.svg', + 'keywords' => array( _x( 'feed', 'icon keyword' ), _x( 'syndication', 'icon keyword' ), _x( 'subscribe', 'icon keyword' ) ), ), 'scheduled' => array( 'label' => _x( 'Scheduled', 'icon label' ), 'filePath' => 'scheduled.svg', + 'keywords' => array( _x( 'pending', 'icon keyword' ), _x( 'upcoming', 'icon keyword' ), _x( 'clock', 'icon keyword' ) ), ), 'search' => array( 'label' => _x( 'Search', 'icon label' ), 'filePath' => 'search.svg', + 'keywords' => array( _x( 'find', 'icon keyword' ), _x( 'magnifier', 'icon keyword' ), _x( 'lookup', 'icon keyword' ), _x( 'query', 'icon keyword' ) ), ), 'settings' => array( 'label' => _x( 'Settings', 'icon label' ), 'filePath' => 'settings.svg', + 'keywords' => array( _x( 'preferences', 'icon keyword' ), _x( 'options', 'icon keyword' ), _x( 'configuration', 'icon keyword' ), _x( 'gear', 'icon keyword' ) ), ), 'shadow' => array( 'label' => _x( 'Shadow', 'icon label' ), 'filePath' => 'shadow.svg', + 'keywords' => array( _x( 'depth', 'icon keyword' ), _x( 'elevation', 'icon keyword' ) ), ), 'share' => array( 'label' => _x( 'Share', 'icon label' ), 'filePath' => 'share.svg', + 'keywords' => array( _x( 'social', 'icon keyword' ), _x( 'distribute', 'icon keyword' ), _x( 'send', 'icon keyword' ) ), ), 'shield' => array( 'label' => _x( 'Shield', 'icon label' ), 'filePath' => 'shield.svg', + 'keywords' => array( _x( 'security', 'icon keyword' ), _x( 'protection', 'icon keyword' ), _x( 'privacy', 'icon keyword' ) ), ), 'shuffle' => array( 'label' => _x( 'Shuffle', 'icon label' ), 'filePath' => 'shuffle.svg', + 'keywords' => array( _x( 'random', 'icon keyword' ), _x( 'mix', 'icon keyword' ), _x( 'randomize', 'icon keyword' ) ), ), 'star-empty' => array( 'label' => _x( 'Star Empty', 'icon label' ), 'filePath' => 'star-empty.svg', + 'keywords' => array( _x( 'rating', 'icon keyword' ), _x( 'favorite', 'icon keyword' ), _x( 'bookmark', 'icon keyword' ) ), ), 'star-filled' => array( 'label' => _x( 'Star Filled', 'icon label' ), 'filePath' => 'star-filled.svg', + 'keywords' => array( _x( 'rating', 'icon keyword' ), _x( 'favorite', 'icon keyword' ), _x( 'bookmark', 'icon keyword' ) ), ), 'star-half' => array( 'label' => _x( 'Star Half', 'icon label' ), 'filePath' => 'star-half.svg', + 'keywords' => array( _x( 'rating', 'icon keyword' ), _x( 'partial', 'icon keyword' ) ), ), 'store' => array( 'label' => _x( 'Store', 'icon label' ), 'filePath' => 'store.svg', + 'keywords' => array( _x( 'shop', 'icon keyword' ), _x( 'merchant', 'icon keyword' ), _x( 'storefront', 'icon keyword' ) ), ), 'styles' => array( 'label' => _x( 'Styles', 'icon label' ), 'filePath' => 'styles.svg', + 'keywords' => array( _x( 'theme', 'icon keyword' ), _x( 'appearance', 'icon keyword' ), _x( 'design', 'icon keyword' ) ), ), 'symbol' => array( 'label' => _x( 'Symbol', 'icon label' ), 'filePath' => 'symbol.svg', + 'keywords' => array( _x( 'pattern', 'icon keyword' ), _x( 'reusable', 'icon keyword' ), _x( 'synced', 'icon keyword' ) ), ), 'symbol-filled' => array( 'label' => _x( 'Symbol Filled', 'icon label' ), 'filePath' => 'symbol-filled.svg', + 'keywords' => array( _x( 'pattern', 'icon keyword' ), _x( 'reusable', 'icon keyword' ), _x( 'synced', 'icon keyword' ) ), ), 'table' => array( 'label' => _x( 'Table', 'icon label' ), 'filePath' => 'table.svg', + 'keywords' => array( _x( 'grid', 'icon keyword' ), _x( 'spreadsheet', 'icon keyword' ), _x( 'rows', 'icon keyword' ) ), ), 'tablet' => array( 'label' => _x( 'Tablet', 'icon label' ), 'filePath' => 'tablet.svg', + 'keywords' => array( _x( 'device', 'icon keyword' ), _x( 'touchscreen', 'icon keyword' ) ), ), 'tag' => array( 'label' => _x( 'Tag', 'icon label' ), 'filePath' => 'tag.svg', + 'keywords' => array( _x( 'label', 'icon keyword' ), _x( 'keyword', 'icon keyword' ), _x( 'topic', 'icon keyword' ) ), ), 'tip' => array( 'label' => _x( 'Tip', 'icon label' ), 'filePath' => 'tip.svg', + 'keywords' => array( _x( 'hint', 'icon keyword' ), _x( 'lightbulb', 'icon keyword' ), _x( 'suggestion', 'icon keyword' ) ), ), 'upload' => array( 'label' => _x( 'Upload', 'icon label' ), 'filePath' => 'upload.svg', + 'keywords' => array( _x( 'import', 'icon keyword' ), _x( 'add file', 'icon keyword' ) ), ), 'verse' => array( 'label' => _x( 'Verse', 'icon label' ), 'filePath' => 'verse.svg', + 'keywords' => array( _x( 'poetry', 'icon keyword' ), _x( 'poem', 'icon keyword' ), _x( 'lyrics', 'icon keyword' ) ), ), ); diff --git a/src/wp-includes/class-wp-icons-registry.php b/src/wp-includes/class-wp-icons-registry.php index efa01118d3cac..00e3380d8fc85 100644 --- a/src/wp-includes/class-wp-icons-registry.php +++ b/src/wp-includes/class-wp-icons-registry.php @@ -46,23 +46,23 @@ protected function __construct() {} * * @since 7.0.0 * @since 7.1.0 The icon name must be namespaced in the form "collection/icon-name". - * @since 7.2.0 Added the `public` property. + * @since 7.2.0 Added the `public` and `keywords` properties. * * @param string $icon_name Namespaced icon name in the form "collection/icon-name" * (e.g. "core/arrow-left"). * @param array $icon_properties { * List of properties for the icon. * - * @type string $label Required. A human-readable label for the icon. - * @type string $content Optional. SVG markup for the icon. - * If not provided, the content will be retrieved from the `file_path` if set. - * If both `content` and `file_path` are not set, the icon will not be registered. - * @type string $file_path Optional. The full path to the file containing the icon content. - * @type bool $public Optional. Whether the icon is exposed through the REST API, and - * therefore selectable in the editor's icon picker. Non-public icons - * stay available to server-side code via {@see wp_get_icon()}. - * Default true. - * @type string[] $keywords Optional. Additional search terms for the icon, matched by + * @type string $label Required. A human-readable label for the icon. + * @type string $content Optional. SVG markup for the icon. + * If not provided, the content will be retrieved from the `file_path` if set. + * If both `content` and `file_path` are not set, the icon will not be registered. + * @type string $file_path Optional. The full path to the file containing the icon content. + * @type bool $public Optional. Whether the icon is exposed through the REST API, and + * therefore selectable in the editor's icon picker. Non-public icons + * stay available to server-side code via {@see wp_get_icon()}. + * Default true. + * @type string[] $keywords Optional. Additional search terms for the icon, matched by * `get_registered_icons()` alongside the name and label. * } * @return bool True if the icon was registered with success and false otherwise. @@ -159,7 +159,7 @@ public function register( $icon_name, $icon_properties ) { if ( ! is_array( $icon_properties['keywords'] ) ) { _doing_it_wrong( __METHOD__, - __( 'Icon keywords must be an array of strings.', 'gutenberg' ), + __( 'Icon keywords must be an array of strings.' ), '7.2.0' ); return false; @@ -169,7 +169,7 @@ public function register( $icon_name, $icon_properties ) { if ( ! is_string( $keyword ) ) { _doing_it_wrong( __METHOD__, - __( 'Icon keywords must be an array of strings.', 'gutenberg' ), + __( 'Icon keywords must be an array of strings.' ), '7.2.0' ); return false; @@ -427,13 +427,14 @@ public function get_registered_icon( $icon_name ) { return $icon; } - /** * Determines whether an icon matches a search term. * * The term is matched case-insensitively against the icon's name, its label, * and any of its keywords. * + * @since 7.2.0 + * * @param array $icon Registered icon properties. * @param string $search Search term. * @return bool True if the icon matches the search term, false otherwise. @@ -461,8 +462,11 @@ protected function icon_matches_search( $icon, $search ) { * * @since 7.0.0 * @since 7.1.0 Search also matches icon labels. + * @since 7.2.0 Search also matches icon keywords. * - * @param string $search Optional. Search term by which to filter the icons. + * @param string $search Optional. Search term matched against each icon's name, + * label, and keywords. Default empty string, which returns + * every registered icon. * @return array[] Array of arrays containing the registered icon properties. */ public function get_registered_icons( $search = '' ) { diff --git a/src/wp-includes/icons.php b/src/wp-includes/icons.php index 4f8db3a1140db..e6916aaed1ed0 100644 --- a/src/wp-includes/icons.php +++ b/src/wp-includes/icons.php @@ -51,17 +51,17 @@ function wp_unregister_icon_collection( $slug ) { * @param array $args { * List of properties for the icon. * - * @type string $label Required. A human-readable label for the icon. - * @type string $content Optional. SVG markup for the icon. - * If not provided, the content will be retrieved from the `file_path` if set. - * If both `content` and `file_path` are not set, the icon will not be registered. - * @type string $file_path Optional. The full path to the file containing the icon content. - * @type bool $public Optional. Whether the icon is exposed through the REST API, and - * therefore selectable in the editor's icon picker. Non-public icons - * stay available to server-side code via {@see wp_get_icon()}. - * Default true. - * @type string[] $keywords Optional. Additional search terms for the icon, matched by - * `get_registered_icons()` alongside the name and label. + * @type string $label Required. A human-readable label for the icon. + * @type string $content Optional. SVG markup for the icon. + * If not provided, the content will be retrieved from the `file_path` if set. + * If both `content` and `file_path` are not set, the icon will not be registered. + * @type string $file_path Optional. The full path to the file containing the icon content. + * @type bool $public Optional. Whether the icon is exposed through the REST API, and + * therefore selectable in the editor's icon picker. Non-public icons + * stay available to server-side code via {@see wp_get_icon()}. + * Default true. + * @type string[] $keywords Optional. Additional search terms for the icon, matched by + * `get_registered_icons()` alongside the name and label. * } * @return bool True if the icon was registered successfully, else false. */ diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php index 92036665e2815..610cc582304dd 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php @@ -234,6 +234,7 @@ public function get_icon( $name ) { * * @since 7.0.0 * @since 7.1.0 Added the `collection` field. + * @since 7.2.0 Added the `keywords` field. * * @param array $item Raw icon as registered, before any changes. * @param WP_REST_Request $request Request object. @@ -246,7 +247,6 @@ public function prepare_item_for_response( $item, $request ) { 'label' => 'label', 'content' => 'content', 'collection' => 'collection', - 'keywords' => 'keywords', ); $data = array(); foreach ( $keys as $item_key => $rest_key ) { @@ -255,6 +255,14 @@ public function prepare_item_for_response( $item, $request ) { } } + /* + * Keywords are optional at registration time, but the field is always + * present in the response so consumers do not have to handle its absence. + */ + if ( rest_is_field_included( 'keywords', $fields ) ) { + $data['keywords'] = isset( $item['keywords'] ) ? array_values( $item['keywords'] ) : array(); + } + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); @@ -266,6 +274,7 @@ public function prepare_item_for_response( $item, $request ) { * * @since 7.0.0 * @since 7.1.0 Added the `collection` property. + * @since 7.2.0 Added the `keywords` property. * * @return array Item schema data. */ diff --git a/tests/phpunit/tests/icons/wpIconsRegistry.php b/tests/phpunit/tests/icons/wpIconsRegistry.php index bebfdba042f51..b49f72b6af110 100644 --- a/tests/phpunit/tests/icons/wpIconsRegistry.php +++ b/tests/phpunit/tests/icons/wpIconsRegistry.php @@ -549,7 +549,7 @@ public function test_register_rejects_non_boolean_public_property() { public function test_register_icon_with_keywords() { $name = 'test-collection/with-keywords'; - $result = $this->register( + $result = $this->registry->register( $name, array( 'label' => 'Icon', @@ -570,7 +570,7 @@ public function test_register_icon_with_keywords() { public function test_register_icon_without_keywords() { $name = 'test-collection/without-keywords'; - $result = $this->register( + $result = $this->registry->register( $name, array( 'label' => 'Icon', @@ -605,14 +605,14 @@ public function data_invalid_keywords() { * Should fail to register an icon whose `keywords` is not an array of strings. * * @dataProvider data_invalid_keywords - * @expectedIncorrectUsage WP_Icons_Registry_Gutenberg::register + * @expectedIncorrectUsage WP_Icons_Registry::register * * @param mixed $keywords Invalid keywords candidate. */ public function test_register_icon_with_invalid_keywords( $keywords ) { $name = 'test-collection/invalid-keywords'; - $result = $this->register( + $result = $this->registry->register( $name, array( 'label' => 'Icon', @@ -629,7 +629,7 @@ public function test_register_icon_with_invalid_keywords( $keywords ) { * Should match an icon by keyword when neither its name nor its label match. */ public function test_get_registered_icons_matches_keywords() { - $this->register( + $this->registry->register( 'test-collection/dove', array( 'label' => 'Dove', @@ -637,7 +637,7 @@ public function test_get_registered_icons_matches_keywords() { 'keywords' => array( 'peace' ), ) ); - $this->register( + $this->registry->register( 'test-collection/anvil', array( 'label' => 'Anvil', @@ -671,7 +671,7 @@ public function test_get_registered_icons_matches_keywords() { * Should match keywords case-insensitively, as names and labels are. */ public function test_get_registered_icons_matches_keywords_case_insensitively() { - $this->register( + $this->registry->register( 'test-collection/dove', array( 'label' => 'Dove', @@ -684,47 +684,4 @@ public function test_get_registered_icons_matches_keywords_case_insensitively() $this->assertContains( 'test-collection/dove', $names ); } - - /** - * Should not drop a third-party icon's keywords when an existing base registry - * is upgraded to the Gutenberg registry. - */ - public function test_get_instance_preserves_keywords_when_upgrading_base_registry() { - // Build a base registry without invoking the constructor, which would - // register the core icons from the core manifest. - $base = ( new ReflectionClass( WP_Icons_Registry::class ) )->newInstanceWithoutConstructor(); - - $icons_property = new ReflectionProperty( WP_Icons_Registry::class, 'registered_icons' ); - if ( PHP_VERSION_ID < 80100 ) { - $icons_property->setAccessible( true ); - } - $icons_property->setValue( - $base, - array( - 'test-collection/dove' => array( - 'name' => 'test-collection/dove', - 'collection' => 'test-collection', - 'label' => 'Dove', - 'content' => '', - 'keywords' => array( 'peace' ), - ), - ) - ); - - $instance_property = new ReflectionProperty( WP_Icons_Registry_Gutenberg::class, 'instance' ); - if ( PHP_VERSION_ID < 80100 ) { - $instance_property->setAccessible( true ); - } - $instance_property->setValue( null, $base ); - - $upgraded = WP_Icons_Registry_Gutenberg::get_instance(); - - $this->assertInstanceOf( WP_Icons_Registry_Gutenberg::class, $upgraded ); - - $icon = $upgraded->get_registered_icon( 'test-collection/dove' ); - $this->assertSame( array( 'peace' ), $icon['keywords'] ); - - $names = array_column( $upgraded->get_registered_icons( 'peace' ), 'name' ); - $this->assertContains( 'test-collection/dove', $names ); - } } diff --git a/tests/phpunit/tests/icons/wpRestIconsController.php b/tests/phpunit/tests/icons/wpRestIconsController.php index fc8c9d7642d9e..92947c5a3a6f9 100644 --- a/tests/phpunit/tests/icons/wpRestIconsController.php +++ b/tests/phpunit/tests/icons/wpRestIconsController.php @@ -405,7 +405,7 @@ public function test_get_items_search_includes_label() { $this->assertEquals( array( 'core/at-symbol' ), array_column( $data, 'name' ) ); } - /** + /** * Test that GET /wp/v2/icons/?search=%s searches icon keywords too. */ public function test_get_items_search_includes_keywords() { From 80872366e23f06ac4c3a53fab0109f2eaf5e52ee Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Tue, 22 Sep 2026 20:09:47 -0500 Subject: [PATCH 4/8] update tests and manifest --- .../assets/icon-library-manifest.php | 88 ------------------- .../tests/icons/wpRestIconsController.php | 72 +++++++++++---- 2 files changed, 57 insertions(+), 103 deletions(-) diff --git a/src/wp-includes/assets/icon-library-manifest.php b/src/wp-includes/assets/icon-library-manifest.php index 3a47601705a36..af72a1c00499c 100644 --- a/src/wp-includes/assets/icon-library-manifest.php +++ b/src/wp-includes/assets/icon-library-manifest.php @@ -8,441 +8,353 @@ 'arrow-down-left' => array( 'label' => _x( 'Arrow Down Left', 'icon label' ), 'filePath' => 'arrow-down-left.svg', - 'keywords' => array( _x( 'southwest', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-down-right' => array( 'label' => _x( 'Arrow Down Right', 'icon label' ), 'filePath' => 'arrow-down-right.svg', - 'keywords' => array( _x( 'southeast', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-down' => array( 'label' => _x( 'Arrow Down', 'icon label' ), 'filePath' => 'arrow-down.svg', - 'keywords' => array( _x( 'south', 'icon keyword' ), _x( 'descend', 'icon keyword' ) ), ), 'arrow-left' => array( 'label' => _x( 'Arrow Left', 'icon label' ), 'filePath' => 'arrow-left.svg', - 'keywords' => array( _x( 'west', 'icon keyword' ), _x( 'back', 'icon keyword' ) ), ), 'arrow-right' => array( 'label' => _x( 'Arrow Right', 'icon label' ), 'filePath' => 'arrow-right.svg', - 'keywords' => array( _x( 'east', 'icon keyword' ), _x( 'forward', 'icon keyword' ) ), ), 'arrow-up-left' => array( 'label' => _x( 'Arrow Up Left', 'icon label' ), 'filePath' => 'arrow-up-left.svg', - 'keywords' => array( _x( 'northwest', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-up-right' => array( 'label' => _x( 'Arrow Up Right', 'icon label' ), 'filePath' => 'arrow-up-right.svg', - 'keywords' => array( _x( 'northeast', 'icon keyword' ), _x( 'diagonal', 'icon keyword' ) ), ), 'arrow-up' => array( 'label' => _x( 'Arrow Up', 'icon label' ), 'filePath' => 'arrow-up.svg', - 'keywords' => array( _x( 'north', 'icon keyword' ), _x( 'ascend', 'icon keyword' ) ), ), 'at-symbol' => array( 'label' => _x( 'At Symbol (@)', 'icon label' ), 'filePath' => 'at-symbol.svg', - 'keywords' => array( _x( 'email', 'icon keyword' ), _x( 'mention', 'icon keyword' ), _x( 'username', 'icon keyword' ) ), ), 'audio' => array( 'label' => _x( 'Audio', 'icon label' ), 'filePath' => 'audio.svg', - 'keywords' => array( _x( 'sound', 'icon keyword' ), _x( 'music', 'icon keyword' ), _x( 'speaker', 'icon keyword' ) ), ), 'bell' => array( 'label' => _x( 'Bell', 'icon label' ), 'filePath' => 'bell.svg', - 'keywords' => array( _x( 'notification', 'icon keyword' ), _x( 'alert', 'icon keyword' ), _x( 'reminder', 'icon keyword' ) ), ), 'block-default' => array( 'label' => _x( 'Block Default', 'icon label' ), 'filePath' => 'block-default.svg', - 'keywords' => array( _x( 'placeholder', 'icon keyword' ), _x( 'generic', 'icon keyword' ) ), ), 'block-meta' => array( 'label' => _x( 'Block Meta', 'icon label' ), 'filePath' => 'block-meta.svg', - 'keywords' => array( _x( 'metadata', 'icon keyword' ), _x( 'custom field', 'icon keyword' ) ), ), 'block-table' => array( 'label' => _x( 'Block Table', 'icon label' ), 'filePath' => 'block-table.svg', - 'keywords' => array( _x( 'grid', 'icon keyword' ), _x( 'spreadsheet', 'icon keyword' ) ), ), 'calendar' => array( 'label' => _x( 'Calendar', 'icon label' ), 'filePath' => 'calendar.svg', - 'keywords' => array( _x( 'date', 'icon keyword' ), _x( 'schedule', 'icon keyword' ), _x( 'event', 'icon keyword' ) ), ), 'capture-photo' => array( 'label' => _x( 'Capture Photo', 'icon label' ), 'filePath' => 'capture-photo.svg', - 'keywords' => array( _x( 'camera', 'icon keyword' ), _x( 'snapshot', 'icon keyword' ) ), ), 'capture-video' => array( 'label' => _x( 'Capture Video', 'icon label' ), 'filePath' => 'capture-video.svg', - 'keywords' => array( _x( 'camcorder', 'icon keyword' ), _x( 'record', 'icon keyword' ) ), ), 'cart' => array( 'label' => _x( 'Cart', 'icon label' ), 'filePath' => 'cart.svg', - 'keywords' => array( _x( 'shopping', 'icon keyword' ), _x( 'basket', 'icon keyword' ), _x( 'checkout', 'icon keyword' ), _x( 'ecommerce', 'icon keyword' ) ), ), 'category' => array( 'label' => _x( 'Category', 'icon label' ), 'filePath' => 'category.svg', - 'keywords' => array( _x( 'taxonomy', 'icon keyword' ), _x( 'archive', 'icon keyword' ) ), ), 'caution' => array( 'label' => _x( 'Caution', 'icon label' ), 'filePath' => 'caution.svg', - 'keywords' => array( _x( 'warning', 'icon keyword' ), _x( 'alert', 'icon keyword' ), _x( 'danger', 'icon keyword' ) ), ), 'chart-bar' => array( 'label' => _x( 'Chart Bar', 'icon label' ), 'filePath' => 'chart-bar.svg', - 'keywords' => array( _x( 'graph', 'icon keyword' ), _x( 'statistics', 'icon keyword' ), _x( 'analytics', 'icon keyword' ) ), ), 'check' => array( 'label' => _x( 'Check', 'icon label' ), 'filePath' => 'check.svg', - 'keywords' => array( _x( 'tick', 'icon keyword' ), _x( 'done', 'icon keyword' ), _x( 'confirm', 'icon keyword' ), _x( 'success', 'icon keyword' ) ), ), 'chevron-down' => array( 'label' => _x( 'Chevron Down', 'icon label' ), 'filePath' => 'chevron-down.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'expand', 'icon keyword' ) ), ), 'chevron-down-small' => array( 'label' => _x( 'Chevron Down Small', 'icon label' ), 'filePath' => 'chevron-down-small.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'expand', 'icon keyword' ) ), ), 'chevron-left' => array( 'label' => _x( 'Chevron Left', 'icon label' ), 'filePath' => 'chevron-left.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'back', 'icon keyword' ) ), ), 'chevron-left-small' => array( 'label' => _x( 'Chevron Left Small', 'icon label' ), 'filePath' => 'chevron-left-small.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'back', 'icon keyword' ) ), ), 'chevron-right' => array( 'label' => _x( 'Chevron Right', 'icon label' ), 'filePath' => 'chevron-right.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'forward', 'icon keyword' ) ), ), 'chevron-right-small' => array( 'label' => _x( 'Chevron Right Small', 'icon label' ), 'filePath' => 'chevron-right-small.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'forward', 'icon keyword' ) ), ), 'chevron-up' => array( 'label' => _x( 'Chevron Up', 'icon label' ), 'filePath' => 'chevron-up.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'collapse', 'icon keyword' ) ), ), 'chevron-up-down' => array( 'label' => _x( 'Chevron Up Down', 'icon label' ), 'filePath' => 'chevron-up-down.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'sort', 'icon keyword' ), _x( 'reorder', 'icon keyword' ) ), ), 'chevron-up-small' => array( 'label' => _x( 'Chevron Up Small', 'icon label' ), 'filePath' => 'chevron-up-small.svg', - 'keywords' => array( _x( 'caret', 'icon keyword' ), _x( 'collapse', 'icon keyword' ) ), ), 'comment' => array( 'label' => _x( 'Comment', 'icon label' ), 'filePath' => 'comment.svg', - 'keywords' => array( _x( 'reply', 'icon keyword' ), _x( 'discussion', 'icon keyword' ), _x( 'feedback', 'icon keyword' ) ), ), 'cover' => array( 'label' => _x( 'Cover', 'icon label' ), 'filePath' => 'cover.svg', - 'keywords' => array( _x( 'banner', 'icon keyword' ), _x( 'hero', 'icon keyword' ), _x( 'background', 'icon keyword' ) ), ), 'create' => array( 'label' => _x( 'Create', 'icon label' ), 'filePath' => 'create.svg', - 'keywords' => array( _x( 'new', 'icon keyword' ), _x( 'add', 'icon keyword' ), _x( 'compose', 'icon keyword' ), _x( 'plus', 'icon keyword' ) ), ), 'desktop' => array( 'label' => _x( 'Desktop', 'icon label' ), 'filePath' => 'desktop.svg', - 'keywords' => array( _x( 'computer', 'icon keyword' ), _x( 'monitor', 'icon keyword' ), _x( 'screen', 'icon keyword' ) ), ), 'download' => array( 'label' => _x( 'Download', 'icon label' ), 'filePath' => 'download.svg', - 'keywords' => array( _x( 'save', 'icon keyword' ), _x( 'export', 'icon keyword' ) ), ), 'drawer-left' => array( 'label' => _x( 'Drawer Left', 'icon label' ), 'filePath' => 'drawer-left.svg', - 'keywords' => array( _x( 'sidebar', 'icon keyword' ), _x( 'panel', 'icon keyword' ) ), ), 'drawer-right' => array( 'label' => _x( 'Drawer Right', 'icon label' ), 'filePath' => 'drawer-right.svg', - 'keywords' => array( _x( 'sidebar', 'icon keyword' ), _x( 'panel', 'icon keyword' ) ), ), 'envelope' => array( 'label' => _x( 'Envelope', 'icon label' ), 'filePath' => 'envelope.svg', - 'keywords' => array( _x( 'email', 'icon keyword' ), _x( 'mail', 'icon keyword' ), _x( 'message', 'icon keyword' ) ), ), 'error' => array( 'label' => _x( 'Error', 'icon label' ), 'filePath' => 'error.svg', - 'keywords' => array( _x( 'failure', 'icon keyword' ), _x( 'problem', 'icon keyword' ), _x( 'alert', 'icon keyword' ), _x( 'caution', 'icon keyword' ), _x( 'warning', 'icon keyword' ) ), ), 'external' => array( 'label' => _x( 'External', 'icon label' ), 'filePath' => 'external.svg', - 'keywords' => array( _x( 'outbound', 'icon keyword' ), _x( 'new window', 'icon keyword' ) ), ), 'file' => array( 'label' => _x( 'File', 'icon label' ), 'filePath' => 'file.svg', - 'keywords' => array( _x( 'attachment', 'icon keyword' ), _x( 'document', 'icon keyword' ), _x( 'folder', 'icon keyword' ) ), ), 'gallery' => array( 'label' => _x( 'Gallery', 'icon label' ), 'filePath' => 'gallery.svg', - 'keywords' => array( _x( 'photos', 'icon keyword' ), _x( 'album', 'icon keyword' ), _x( 'images', 'icon keyword' ) ), ), 'group' => array( 'label' => _x( 'Group', 'icon label' ), 'filePath' => 'group.svg', - 'keywords' => array( _x( 'container', 'icon keyword' ), _x( 'wrapper', 'icon keyword' ), _x( 'stack', 'icon keyword' ) ), ), 'heading' => array( 'label' => _x( 'Heading', 'icon label' ), 'filePath' => 'heading.svg', - 'keywords' => array( _x( 'title', 'icon keyword' ), _x( 'headline', 'icon keyword' ) ), ), 'help' => array( 'label' => _x( 'Help', 'icon label' ), 'filePath' => 'help.svg', - 'keywords' => array( _x( 'question', 'icon keyword' ), _x( 'support', 'icon keyword' ), _x( 'faq', 'icon keyword' ) ), ), 'home' => array( 'label' => _x( 'Home', 'icon label' ), 'filePath' => 'home.svg', - 'keywords' => array( _x( 'house', 'icon keyword' ), _x( 'front page', 'icon keyword' ), _x( 'dashboard', 'icon keyword' ) ), ), 'image' => array( 'label' => _x( 'Image', 'icon label' ), 'filePath' => 'image.svg', - 'keywords' => array( _x( 'photo', 'icon keyword' ), _x( 'picture', 'icon keyword' ), _x( 'media', 'icon keyword' ) ), ), 'info' => array( 'label' => _x( 'Info', 'icon label' ), 'filePath' => 'info.svg', - 'keywords' => array( _x( 'information', 'icon keyword' ), _x( 'about', 'icon keyword' ), _x( 'details', 'icon keyword' ) ), ), 'key' => array( 'label' => _x( 'Key', 'icon label' ), 'filePath' => 'key.svg', - 'keywords' => array( _x( 'password', 'icon keyword' ), _x( 'license', 'icon keyword' ), _x( 'credential', 'icon keyword' ) ), ), 'language' => array( 'label' => _x( 'Language', 'icon label' ), 'filePath' => 'language.svg', - 'keywords' => array( _x( 'translate', 'icon keyword' ), _x( 'locale', 'icon keyword' ), _x( 'globe', 'icon keyword' ) ), ), 'map-marker' => array( 'label' => _x( 'Map Marker', 'icon label' ), 'filePath' => 'map-marker.svg', - 'keywords' => array( _x( 'location', 'icon keyword' ), _x( 'pin', 'icon keyword' ), _x( 'address', 'icon keyword' ) ), ), 'menu' => array( 'label' => _x( 'Menu', 'icon label' ), 'filePath' => 'menu.svg', - 'keywords' => array( _x( 'hamburger', 'icon keyword' ), _x( 'navigation', 'icon keyword' ), _x( 'list', 'icon keyword' ) ), ), 'mobile' => array( 'label' => _x( 'Mobile', 'icon label' ), 'filePath' => 'mobile.svg', - 'keywords' => array( _x( 'phone', 'icon keyword' ), _x( 'smartphone', 'icon keyword' ), _x( 'handset', 'icon keyword' ) ), ), 'more-horizontal' => array( 'label' => _x( 'More Horizontal', 'icon label' ), 'filePath' => 'more-horizontal.svg', - 'keywords' => array( _x( 'ellipsis', 'icon keyword' ), _x( 'options', 'icon keyword' ), _x( 'overflow', 'icon keyword' ) ), ), 'more-vertical' => array( 'label' => _x( 'More Vertical', 'icon label' ), 'filePath' => 'more-vertical.svg', - 'keywords' => array( _x( 'ellipsis', 'icon keyword' ), _x( 'options', 'icon keyword' ), _x( 'overflow', 'icon keyword' ) ), ), 'next' => array( 'label' => _x( 'Next', 'icon label' ), 'filePath' => 'next.svg', - 'keywords' => array( _x( 'forward', 'icon keyword' ), _x( 'advance', 'icon keyword' ) ), ), 'paragraph' => array( 'label' => _x( 'Paragraph', 'icon label' ), 'filePath' => 'paragraph.svg', - 'keywords' => array( _x( 'text', 'icon keyword' ), _x( 'body copy', 'icon keyword' ) ), ), 'payment' => array( 'label' => _x( 'Payment', 'icon label' ), 'filePath' => 'payment.svg', - 'keywords' => array( _x( 'credit card', 'icon keyword' ), _x( 'billing', 'icon keyword' ), _x( 'checkout', 'icon keyword' ) ), ), 'pencil' => array( 'label' => _x( 'Pencil', 'icon label' ), 'filePath' => 'pencil.svg', - 'keywords' => array( _x( 'edit', 'icon keyword' ), _x( 'write', 'icon keyword' ), _x( 'modify', 'icon keyword' ) ), ), 'people' => array( 'label' => _x( 'People', 'icon label' ), 'filePath' => 'people.svg', - 'keywords' => array( _x( 'users', 'icon keyword' ), _x( 'team', 'icon keyword' ), _x( 'members', 'icon keyword' ) ), ), 'plus' => array( 'label' => _x( 'Plus', 'icon label' ), 'filePath' => 'plus.svg', - 'keywords' => array( _x( 'add', 'icon keyword' ), _x( 'new', 'icon keyword' ), _x( 'create', 'icon keyword' ) ), ), 'plus-circle' => array( 'label' => _x( 'Plus Circle', 'icon label' ), 'filePath' => 'plus-circle.svg', - 'keywords' => array( _x( 'add', 'icon keyword' ), _x( 'new', 'icon keyword' ), _x( 'create', 'icon keyword' ) ), ), 'previous' => array( 'label' => _x( 'Previous', 'icon label' ), 'filePath' => 'previous.svg', - 'keywords' => array( _x( 'back', 'icon keyword' ), _x( 'prior', 'icon keyword' ) ), ), 'published' => array( 'label' => _x( 'Published', 'icon label' ), 'filePath' => 'published.svg', - 'keywords' => array( _x( 'live', 'icon keyword' ), _x( 'visible', 'icon keyword' ), _x( 'public', 'icon keyword' ) ), ), 'quote' => array( 'label' => _x( 'Quote', 'icon label' ), 'filePath' => 'quote.svg', - 'keywords' => array( _x( 'blockquote', 'icon keyword' ), _x( 'citation', 'icon keyword' ), _x( 'testimonial', 'icon keyword' ) ), ), 'receipt' => array( 'label' => _x( 'Receipt', 'icon label' ), 'filePath' => 'receipt.svg', - 'keywords' => array( _x( 'invoice', 'icon keyword' ), _x( 'order', 'icon keyword' ), _x( 'bill', 'icon keyword' ) ), ), 'rss' => array( 'label' => _x( 'RSS', 'icon label' ), 'filePath' => 'rss.svg', - 'keywords' => array( _x( 'feed', 'icon keyword' ), _x( 'syndication', 'icon keyword' ), _x( 'subscribe', 'icon keyword' ) ), ), 'scheduled' => array( 'label' => _x( 'Scheduled', 'icon label' ), 'filePath' => 'scheduled.svg', - 'keywords' => array( _x( 'pending', 'icon keyword' ), _x( 'upcoming', 'icon keyword' ), _x( 'clock', 'icon keyword' ) ), ), 'search' => array( 'label' => _x( 'Search', 'icon label' ), 'filePath' => 'search.svg', - 'keywords' => array( _x( 'find', 'icon keyword' ), _x( 'magnifier', 'icon keyword' ), _x( 'lookup', 'icon keyword' ), _x( 'query', 'icon keyword' ) ), ), 'settings' => array( 'label' => _x( 'Settings', 'icon label' ), 'filePath' => 'settings.svg', - 'keywords' => array( _x( 'preferences', 'icon keyword' ), _x( 'options', 'icon keyword' ), _x( 'configuration', 'icon keyword' ), _x( 'gear', 'icon keyword' ) ), ), 'shadow' => array( 'label' => _x( 'Shadow', 'icon label' ), 'filePath' => 'shadow.svg', - 'keywords' => array( _x( 'depth', 'icon keyword' ), _x( 'elevation', 'icon keyword' ) ), ), 'share' => array( 'label' => _x( 'Share', 'icon label' ), 'filePath' => 'share.svg', - 'keywords' => array( _x( 'social', 'icon keyword' ), _x( 'distribute', 'icon keyword' ), _x( 'send', 'icon keyword' ) ), ), 'shield' => array( 'label' => _x( 'Shield', 'icon label' ), 'filePath' => 'shield.svg', - 'keywords' => array( _x( 'security', 'icon keyword' ), _x( 'protection', 'icon keyword' ), _x( 'privacy', 'icon keyword' ) ), ), 'shuffle' => array( 'label' => _x( 'Shuffle', 'icon label' ), 'filePath' => 'shuffle.svg', - 'keywords' => array( _x( 'random', 'icon keyword' ), _x( 'mix', 'icon keyword' ), _x( 'randomize', 'icon keyword' ) ), ), 'star-empty' => array( 'label' => _x( 'Star Empty', 'icon label' ), 'filePath' => 'star-empty.svg', - 'keywords' => array( _x( 'rating', 'icon keyword' ), _x( 'favorite', 'icon keyword' ), _x( 'bookmark', 'icon keyword' ) ), ), 'star-filled' => array( 'label' => _x( 'Star Filled', 'icon label' ), 'filePath' => 'star-filled.svg', - 'keywords' => array( _x( 'rating', 'icon keyword' ), _x( 'favorite', 'icon keyword' ), _x( 'bookmark', 'icon keyword' ) ), ), 'star-half' => array( 'label' => _x( 'Star Half', 'icon label' ), 'filePath' => 'star-half.svg', - 'keywords' => array( _x( 'rating', 'icon keyword' ), _x( 'partial', 'icon keyword' ) ), ), 'store' => array( 'label' => _x( 'Store', 'icon label' ), 'filePath' => 'store.svg', - 'keywords' => array( _x( 'shop', 'icon keyword' ), _x( 'merchant', 'icon keyword' ), _x( 'storefront', 'icon keyword' ) ), ), 'styles' => array( 'label' => _x( 'Styles', 'icon label' ), 'filePath' => 'styles.svg', - 'keywords' => array( _x( 'theme', 'icon keyword' ), _x( 'appearance', 'icon keyword' ), _x( 'design', 'icon keyword' ) ), ), 'symbol' => array( 'label' => _x( 'Symbol', 'icon label' ), 'filePath' => 'symbol.svg', - 'keywords' => array( _x( 'pattern', 'icon keyword' ), _x( 'reusable', 'icon keyword' ), _x( 'synced', 'icon keyword' ) ), ), 'symbol-filled' => array( 'label' => _x( 'Symbol Filled', 'icon label' ), 'filePath' => 'symbol-filled.svg', - 'keywords' => array( _x( 'pattern', 'icon keyword' ), _x( 'reusable', 'icon keyword' ), _x( 'synced', 'icon keyword' ) ), ), 'table' => array( 'label' => _x( 'Table', 'icon label' ), 'filePath' => 'table.svg', - 'keywords' => array( _x( 'grid', 'icon keyword' ), _x( 'spreadsheet', 'icon keyword' ), _x( 'rows', 'icon keyword' ) ), ), 'tablet' => array( 'label' => _x( 'Tablet', 'icon label' ), 'filePath' => 'tablet.svg', - 'keywords' => array( _x( 'device', 'icon keyword' ), _x( 'touchscreen', 'icon keyword' ) ), ), 'tag' => array( 'label' => _x( 'Tag', 'icon label' ), 'filePath' => 'tag.svg', - 'keywords' => array( _x( 'label', 'icon keyword' ), _x( 'keyword', 'icon keyword' ), _x( 'topic', 'icon keyword' ) ), ), 'tip' => array( 'label' => _x( 'Tip', 'icon label' ), 'filePath' => 'tip.svg', - 'keywords' => array( _x( 'hint', 'icon keyword' ), _x( 'lightbulb', 'icon keyword' ), _x( 'suggestion', 'icon keyword' ) ), ), 'upload' => array( 'label' => _x( 'Upload', 'icon label' ), 'filePath' => 'upload.svg', - 'keywords' => array( _x( 'import', 'icon keyword' ), _x( 'add file', 'icon keyword' ) ), ), 'verse' => array( 'label' => _x( 'Verse', 'icon label' ), 'filePath' => 'verse.svg', - 'keywords' => array( _x( 'poetry', 'icon keyword' ), _x( 'poem', 'icon keyword' ), _x( 'lyrics', 'icon keyword' ) ), ), ); diff --git a/tests/phpunit/tests/icons/wpRestIconsController.php b/tests/phpunit/tests/icons/wpRestIconsController.php index ad90651352651..95506e947469c 100644 --- a/tests/phpunit/tests/icons/wpRestIconsController.php +++ b/tests/phpunit/tests/icons/wpRestIconsController.php @@ -409,17 +409,45 @@ public function test_get_items_search_includes_label() { * Test that GET /wp/v2/icons/?search=%s searches icon keywords too. */ public function test_get_items_search_includes_keywords() { + wp_register_icon_collection( 'rest-test-collection', array( 'label' => 'REST Test' ) ); + wp_register_icon( + 'rest-test-collection/dove', + array( + 'label' => 'Dove', + 'content' => '', + 'keywords' => array( 'peace' ), + ) + ); + wp_register_icon( + 'rest-test-collection/anvil', + array( + 'label' => 'Anvil', + 'content' => '', + ) + ); + wp_set_current_user( self::$editor_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); + try { + $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); - // 'hamburger' is only found in the *keywords* for core/menu. - $request->set_param( 'search', 'hamburger' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); + /* + * The search term appears in no icon's name or label, so a match can + * only come from the keywords. + */ + $request->set_param( 'search', 'peace' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); - $this->assertSame( 200, $response->get_status() ); - $this->assertEquals( array( 'core/menu' ), array_column( $data, 'name' ) ); + $this->assertSame( 200, $response->get_status() ); + $this->assertSame( + array( 'rest-test-collection/dove' ), + array_column( $data, 'name' ), + 'Search results should contain only the icon matched by its keyword' + ); + } finally { + wp_unregister_icon_collection( 'rest-test-collection' ); + } } /** @@ -427,17 +455,31 @@ public function test_get_items_search_includes_keywords() { * filter icons locally can match against them. */ public function test_get_items_response_includes_keywords() { + wp_register_icon_collection( 'rest-test-collection', array( 'label' => 'REST Test' ) ); + wp_register_icon( + 'rest-test-collection/dove', + array( + 'label' => 'Dove', + 'content' => '', + 'keywords' => array( 'peace', 'bird' ), + ) + ); + wp_set_current_user( self::$editor_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); - $request->set_param( 'search', 'core/menu' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); + try { + $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); + $request->set_param( 'search', 'rest-test-collection/dove' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); - $this->assertSame( 200, $response->get_status() ); - $this->assertCount( 1, $data ); - $this->assertArrayHasKey( 'keywords', $data[0] ); - $this->assertContains( 'hamburger', $data[0]['keywords'] ); + $this->assertSame( 200, $response->get_status() ); + $this->assertCount( 1, $data ); + $this->assertArrayHasKey( 'keywords', $data[0] ); + $this->assertSame( array( 'peace', 'bird' ), $data[0]['keywords'] ); + } finally { + wp_unregister_icon_collection( 'rest-test-collection' ); + } } /** From 3596cc05c7d79be499fb61e54a6e3d5ddcc326a2 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Wed, 23 Sep 2026 18:45:45 +0900 Subject: [PATCH 5/8] Tests: Add ticket references to the icon keyword tests. Co-Authored-By: Claude --- tests/phpunit/tests/icons/wpIconsRegistry.php | 10 ++++++++++ tests/phpunit/tests/icons/wpRestIconsController.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/tests/phpunit/tests/icons/wpIconsRegistry.php b/tests/phpunit/tests/icons/wpIconsRegistry.php index b49f72b6af110..89a7d9e7fce61 100644 --- a/tests/phpunit/tests/icons/wpIconsRegistry.php +++ b/tests/phpunit/tests/icons/wpIconsRegistry.php @@ -545,6 +545,8 @@ public function test_register_rejects_non_boolean_public_property() { /** * Should register an icon that provides a valid `keywords` array. + * + * @ticket 66158 */ public function test_register_icon_with_keywords() { $name = 'test-collection/with-keywords'; @@ -566,6 +568,8 @@ public function test_register_icon_with_keywords() { /** * Should register an icon that omits `keywords`, since the property is optional. + * + * @ticket 66158 */ public function test_register_icon_without_keywords() { $name = 'test-collection/without-keywords'; @@ -604,6 +608,8 @@ public function data_invalid_keywords() { /** * Should fail to register an icon whose `keywords` is not an array of strings. * + * @ticket 66158 + * * @dataProvider data_invalid_keywords * @expectedIncorrectUsage WP_Icons_Registry::register * @@ -627,6 +633,8 @@ public function test_register_icon_with_invalid_keywords( $keywords ) { /** * Should match an icon by keyword when neither its name nor its label match. + * + * @ticket 66158 */ public function test_get_registered_icons_matches_keywords() { $this->registry->register( @@ -669,6 +677,8 @@ public function test_get_registered_icons_matches_keywords() { /** * Should match keywords case-insensitively, as names and labels are. + * + * @ticket 66158 */ public function test_get_registered_icons_matches_keywords_case_insensitively() { $this->registry->register( diff --git a/tests/phpunit/tests/icons/wpRestIconsController.php b/tests/phpunit/tests/icons/wpRestIconsController.php index 95506e947469c..dc76c3a414c3b 100644 --- a/tests/phpunit/tests/icons/wpRestIconsController.php +++ b/tests/phpunit/tests/icons/wpRestIconsController.php @@ -407,6 +407,8 @@ public function test_get_items_search_includes_label() { /** * Test that GET /wp/v2/icons/?search=%s searches icon keywords too. + * + * @ticket 66158 */ public function test_get_items_search_includes_keywords() { wp_register_icon_collection( 'rest-test-collection', array( 'label' => 'REST Test' ) ); @@ -453,6 +455,8 @@ public function test_get_items_search_includes_keywords() { /** * Test that the response exposes an icon's keywords, so that clients which * filter icons locally can match against them. + * + * @ticket 66158 */ public function test_get_items_response_includes_keywords() { wp_register_icon_collection( 'rest-test-collection', array( 'label' => 'REST Test' ) ); @@ -485,6 +489,8 @@ public function test_get_items_response_includes_keywords() { /** * Test that icons registered without keywords still expose an empty array, * so consumers do not have to handle a missing field. + * + * @ticket 66158 */ public function test_get_items_response_keywords_defaults_to_empty_array() { wp_set_current_user( self::$editor_id ); From 5d611d266eb42b16171257f0db29c266501b7bb1 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Wed, 23 Sep 2026 08:28:14 -0500 Subject: [PATCH 6/8] Update src/wp-includes/class-wp-icons-registry.php Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> --- src/wp-includes/class-wp-icons-registry.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wp-includes/class-wp-icons-registry.php b/src/wp-includes/class-wp-icons-registry.php index 00e3380d8fc85..745e369e7c872 100644 --- a/src/wp-includes/class-wp-icons-registry.php +++ b/src/wp-includes/class-wp-icons-registry.php @@ -175,8 +175,6 @@ public function register( $icon_name, $icon_properties ) { return false; } } - - $icon_properties['keywords'] = array_map( 'sanitize_text_field', $icon_properties['keywords'] ); } if ( From 150546b251fba3efdcc3cef7dc1702f9422acc6f Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Mon, 28 Sep 2026 14:01:04 -0500 Subject: [PATCH 7/8] update test --- tests/phpunit/tests/icons/wpRestIconsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/icons/wpRestIconsController.php b/tests/phpunit/tests/icons/wpRestIconsController.php index 86ebf84c0c672..cdc9793242461 100644 --- a/tests/phpunit/tests/icons/wpRestIconsController.php +++ b/tests/phpunit/tests/icons/wpRestIconsController.php @@ -249,6 +249,7 @@ public function test_prepare_item() { /** * @ticket 40538 * @ticket 64651 + * @ticket 66158 * * @covers ::get_item_schema */ @@ -258,11 +259,12 @@ public function test_get_item_schema() { $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 4, $properties ); + $this->assertCount( 5, $properties ); $this->assertArrayHasKey( 'name', $properties ); $this->assertArrayHasKey( 'label', $properties ); $this->assertArrayHasKey( 'content', $properties ); $this->assertArrayHasKey( 'collection', $properties ); + $this->assertArrayHasKey( 'keywords', $properties ); } /** From e470b18e6b69b43c0a3e12db5ffa840387c29cb6 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Tue, 29 Sep 2026 19:24:58 +0900 Subject: [PATCH 8/8] Tests: Use an inline comment instead of a DocBlock in the icon keyword search test. Co-Authored-By: Claude --- tests/phpunit/tests/icons/wpIconsRegistry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/icons/wpIconsRegistry.php b/tests/phpunit/tests/icons/wpIconsRegistry.php index b067b391951d2..621ff00b0df20 100644 --- a/tests/phpunit/tests/icons/wpIconsRegistry.php +++ b/tests/phpunit/tests/icons/wpIconsRegistry.php @@ -653,7 +653,7 @@ public function test_get_registered_icons_matches_keywords() { ) ); - /** + /* * The search term is deliberately absent from both the name and the label, * so a match can only come from the keywords. */