Skip to content

Commit a2d90ce

Browse files
committed
Icons: Add label search support to WP_Icons_Registry.
When filtering registered icons by a search term, the registry now matches the term against each icon's `label` in addition to its `name`. Previously only the `name` was searched, so icons whose human-readable label differed from their name could not be found. Props mcsf, wildworks. See #64847. git-svn-id: https://develop.svn.wordpress.org/trunk@62551 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a1314bb commit a2d90ce

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
@@ -310,7 +310,10 @@ public function get_registered_icons( $search = '' ) {
310310
$icons = array();
311311

312312
foreach ( $this->registered_icons as $icon ) {
313-
if ( ! empty( $search ) && false === stripos( $icon['name'], $search ) ) {
313+
if ( ! empty( $search )
314+
&& false === stripos( $icon['name'], $search )
315+
&& false === stripos( $icon['label'] ?? '', $search )
316+
) {
314317
continue;
315318
}
316319

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)