wppaste
WordPress

WP_REST_Block_Renderer_Controller

Since
5.0.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php:17
Controller which provides REST endpoint for rendering a block.

Compatibility

WordPress
since 5.0.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Methods · 5

Source code

class WP_REST_Block_Renderer_Controller extends WP_REST_Controller { 	/**	 * Constructs the controller.	 *	 * @since 5.0.0	 */	public function __construct() {		$this->namespace = 'wp/v2';		$this->rest_base = 'block-renderer';	} 	/**	 * Registers the necessary REST API routes, one for each dynamic block.	 *	 * @since 5.0.0	 *	 * @see register_rest_route()	 */	public function register_routes() {		register_rest_route(			$this->namespace,			'/' . $this->rest_base . '/(?P<name>[a-z0-9-]+/[a-z0-9-]+)',			array(				'args'   => array(					'name' => array(						'description' => __( 'Unique registered name for the block.' ),						'type'        => 'string',					),				),				array(					'methods'             => array( WP_REST_Server::READABLE, WP_REST_Server::CREATABLE ),					'callback'            => array( $this, 'get_item' ),					'permission_callback' => array( $this, 'get_item_permissions_check' ),					'args'                => array(						'context'    => $this->get_context_param( array( 'default' => 'view' ) ),						'attributes' => array(							'description'       => __( 'Attributes for the block.' ),							'type'              => 'object',							'default'           => array(),							'validate_callback' => static function ( $value, $request ) {								$block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] ); 								if ( ! $block ) {									// This will get rejected in ::get_item().									return true;								} 								$schema = array(									'type'                 => 'object',									'properties'           => $block->get_attributes(),									'additionalProperties' => false,								); 								return rest_validate_value_from_schema( $value, $schema );							},							'sanitize_callback' => static function ( $value, $request ) {								$block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] ); 								if ( ! $block ) {									// This will get rejected in ::get_item().									return true;								} 								$schema = array(									'type'                 => 'object',									'properties'           => $block->get_attributes(),									'additionalProperties' => false,								); 								return rest_sanitize_value_from_schema( $value, $schema );							},						),						'post_id'    => array(							'description' => __( 'ID of the post context.' ),							'type'        => 'integer',						),					),				),				'schema' => array( $this, 'get_public_item_schema' ),

Changelog

Introduced in 5.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.