Retrieves all icons, optionally scoped to a collection.
Parameters
$requestWP_REST_Requestrequired- Full details about the request.
Source
public function get_items( $request ) {
$collection = $request->get_param( 'collection' );
if ( null !== $collection && ! WP_Icon_Collections_Registry::get_instance()->is_registered( $collection ) ) {
return new WP_Error(
'rest_icon_collection_not_found',
sprintf(
/* translators: %s: Icon collection slug. */
__( 'Icon collection not found: "%s".' ),
$collection
),
array( 'status' => 404 )
);
}
$response = array();
$search = $request->get_param( 'search' );
$icons = WP_Icons_Registry::get_instance()->get_registered_icons( $search );
foreach ( $icons as $icon ) {
if ( null !== $collection && ( ! isset( $icon['collection'] ) || $icon['collection'] !== $collection ) ) {
continue;
}
$prepared_icon = $this->prepare_item_for_response( $icon, $request );
$response[] = $this->prepare_response_for_collection( $prepared_icon );
}
return rest_ensure_response( $response );
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.