Skip to content

Commit cfdd6c3

Browse files
committed
Icons: Add label search support to WP_Icons_Registry
1 parent cc19ca7 commit cfdd6c3

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/wp-includes/class-wp-icons-registry.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ public function get_registered_icons( $search = '' ) {
271271
$icons = array();
272272

273273
foreach ( $this->registered_icons as $icon ) {
274-
if ( ! empty( $search ) && false === stripos( $icon['name'], $search ) ) {
274+
if ( ! empty( $search )
275+
&& false === stripos( $icon['name'], $search )
276+
&& false === stripos( $icon['label'] ?? '', $search )
277+
) {
275278
continue;
276279
}
277280

tests/phpunit/tests/icons/wpRestIconsController.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,27 @@ public function test_get_items_search_filters_results() {
296296
$this->assertContains( 'core/arrow-left', $icon_names, 'Search results should include core/arrow-left icon' );
297297
}
298298

299+
/**
300+
* Test that GET /wp/v2/icons/?search= searches icon labels too.
301+
*
302+
* @ticket 64847
303+
*
304+
* @covers ::get_items
305+
*/
306+
public function test_get_items_search_includes_label() {
307+
wp_set_current_user( self::$editor_id );
308+
309+
$request = new WP_REST_Request( 'GET', '/wp/v2/icons' );
310+
311+
// The '@' character is only found in the *label* for core/at-symbol
312+
$request->set_param( 'search', '@' );
313+
$response = rest_get_server()->dispatch( $request );
314+
$data = $response->get_data();
315+
316+
$this->assertSame( 200, $response->get_status() );
317+
$this->assertEquals( array( 'core/at-symbol' ), array_column( $data, 'name' ) );
318+
}
319+
299320
/**
300321
* Test that search is case-insensitive.
301322
*

0 commit comments

Comments
 (0)