WP_REST_Block_Patterns_Controller::get_items() WordPress Method

The get_items() method of the WP_REST_Block_Patterns_Controller class is responsible for fetching block patterns from the WordPress database and returning them as an array of objects. Each object represents a single block pattern and contains the pattern's id, title, description, and content. The get_items() method accepts two arguments: the first is the request object, which contains information about the request made to the WordPress API; the second is the response object, which contains information about the response that will be sent back to the client.

WP_REST_Block_Patterns_Controller::get_items( WP_REST_Request $request ) #

Retrieves all block patterns.


Parameters

$request

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


Top ↑

Return

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


Top ↑

Source

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

	public function get_items( $request ) {
		if ( ! $this->remote_patterns_loaded ) {
			// Load block patterns from w.org.
			_load_remote_block_patterns(); // Patterns with the `core` keyword.
			_load_remote_featured_patterns(); // Patterns in the `featured` category.
			_register_remote_theme_patterns(); // Patterns requested by current theme.

			$this->remote_patterns_loaded = true;
		}

		$response = array();
		$patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
		foreach ( $patterns as $pattern ) {
			$prepared_pattern = $this->prepare_item_for_response( $pattern, $request );
			$response[]       = $this->prepare_response_for_collection( $prepared_pattern );
		}
		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.