WP_REST_Icons_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error

In this article

Retrieves all icons, optionally scoped to a collection.

Parameters

$requestWP_REST_Requestrequired
Full details about the request.

Return

WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.

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 );
}

Changelog

VersionDescription
7.1.0Supports filtering by collection.
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.