From cfdd6c3ecd8ba12e9995048187d3ef6a653c37df Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Thu, 12 Mar 2026 15:22:00 +0900 Subject: [PATCH] Icons: Add label search support to WP_Icons_Registry --- src/wp-includes/class-wp-icons-registry.php | 5 ++++- .../tests/icons/wpRestIconsController.php | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-icons-registry.php b/src/wp-includes/class-wp-icons-registry.php index 2e306bec77e53..5b1d3ebdabd27 100644 --- a/src/wp-includes/class-wp-icons-registry.php +++ b/src/wp-includes/class-wp-icons-registry.php @@ -271,7 +271,10 @@ public function get_registered_icons( $search = '' ) { $icons = array(); foreach ( $this->registered_icons as $icon ) { - if ( ! empty( $search ) && false === stripos( $icon['name'], $search ) ) { + if ( ! empty( $search ) + && false === stripos( $icon['name'], $search ) + && false === stripos( $icon['label'] ?? '', $search ) + ) { continue; } diff --git a/tests/phpunit/tests/icons/wpRestIconsController.php b/tests/phpunit/tests/icons/wpRestIconsController.php index f6fd935061f0e..a3e0c1d96a063 100644 --- a/tests/phpunit/tests/icons/wpRestIconsController.php +++ b/tests/phpunit/tests/icons/wpRestIconsController.php @@ -296,6 +296,27 @@ public function test_get_items_search_filters_results() { $this->assertContains( 'core/arrow-left', $icon_names, 'Search results should include core/arrow-left icon' ); } + /** + * Test that GET /wp/v2/icons/?search= searches icon labels too. + * + * @ticket 64847 + * + * @covers ::get_items + */ + public function test_get_items_search_includes_label() { + wp_set_current_user( self::$editor_id ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/icons' ); + + // The '@' character is only found in the *label* for core/at-symbol + $request->set_param( 'search', '@' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + + $this->assertSame( 200, $response->get_status() ); + $this->assertEquals( array( 'core/at-symbol' ), array_column( $data, 'name' ) ); + } + /** * Test that search is case-insensitive. *