WP_REST_Block_Renderer_Controller::get_item

Advertisement

Summery Summery

Returns block output from block’s registered render_callback.

Syntax Syntax

WP_REST_Block_Renderer_Controller::get_item( WP_REST_Request $request )

Parameters Parameters

$request

(Required) Full details about the request.

Return Return

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

Source Source

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

				return new WP_Error(
					'block_cannot_read',
					__( 'Sorry, you are not allowed to read blocks as this user.' ),
					array(
						'status' => rest_authorization_required_code(),
					)
				);
			}
		}

		return true;
	}

	/**
	 * Returns block output from block's registered render_callback.
	 *
	 * @since 5.0.0
	 *
	 * @param WP_REST_Request $request Full details about the request.
	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
	 */
	public function get_item( $request ) {
		global $post;

		$post_id = isset( $request['post_id'] ) ? intval( $request['post_id'] ) : 0;

		if ( 0 < $post_id ) {
			$post = get_post( $post_id );

			// Set up postdata since this will be needed if post_id was set.
			setup_postdata( $post );
		}

		$registry   = WP_Block_Type_Registry::get_instance();
		$registered = $registry->get_registered( $request['name'] );

		if ( null === $registered || ! $registered->is_dynamic() ) {
			return new WP_Error(
				'block_invalid',
				__( 'Invalid block.' ),

Advertisement

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Advertisement

Leave a Reply