Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/wp-includes/class-wp-icons-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/phpunit/tests/icons/wpRestIconsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading