WordPress at a glance
function is not described

WP_REST_Block_Directory_Controller::get_items() public WP 5.5.0

Search and retrieve blocks metadata

{} It's a method of the class: WP_REST_Block_Directory_Controller{}

No Hooks.

Return

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

Usage

$WP_REST_Block_Directory_Controller = new WP_REST_Block_Directory_Controller();
$WP_REST_Block_Directory_Controller->get_items( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 5.5.0 Introduced.

Code of WP_REST_Block_Directory_Controller::get_items() WP 5.5.2

<?php
public function get_items( $request ) {
	require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
	require_once ABSPATH . 'wp-admin/includes/plugin.php';

	$response = plugins_api(
		'query_plugins',
		array(
			'block'    => $request['term'],
			'per_page' => $request['per_page'],
			'page'     => $request['page'],
		)
	);

	if ( is_wp_error( $response ) ) {
		$response->add_data( array( 'status' => 500 ) );

		return $response;
	}

	$result = array();

	foreach ( $response->plugins as $plugin ) {
		// If the API returned a plugin with empty data for 'blocks', skip it.
		if ( empty( $plugin['blocks'] ) ) {
			continue;
		}

		$data     = $this->prepare_item_for_response( $plugin, $request );
		$result[] = $this->prepare_response_for_collection( $data );
	}

	return rest_ensure_response( $result );
}