WP_REST_Block_Pattern_Categories_Controller::get_items() WordPress Method

The WP_REST_Block_Pattern_Categories_Controller::get_items() method is used to get a list of block pattern categories. This is useful for displaying a list of categories in a UI.

WP_REST_Block_Pattern_Categories_Controller::get_items( WP_REST_Request $request ) #

Retrieves all block pattern categories.


Parameters

$request

(WP_REST_Request)(Required)Full details about the request.


Top ↑

Return

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


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php

	public function get_items( $request ) {
		$response   = array();
		$categories = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
		foreach ( $categories as $category ) {
			$prepared_category = $this->prepare_item_for_response( $category, $request );
			$response[]        = $this->prepare_response_for_collection( $prepared_category );
		}

		return rest_ensure_response( $response );
	}


Top ↑

Changelog

Changelog
VersionDescription
6.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.