WP_REST_Block_Renderer_Controller::register_routes()

Registers the necessary REST API routes, one for each dynamic block.


Description Description


Source Source

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

	public function register_routes() {
		$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();

		foreach ( $block_types as $block_type ) {
			if ( ! $block_type->is_dynamic() ) {
				continue;
			}

			register_rest_route(
				$this->namespace,
				'/' . $this->rest_base . '/(?P<name>' . $block_type->name . ')',
				array(
					'args'   => array(
						'name' => array(
							'description' => __( 'Unique registered name for the block.' ),
							'type'        => 'string',
						),
					),
					array(
						'methods'             => WP_REST_Server::READABLE,
						'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(
								/* translators: %s: The name of the block. */
								'description'          => sprintf( __( 'Attributes for %s block' ), $block_type->name ),
								'type'                 => 'object',
								'additionalProperties' => false,
								'properties'           => $block_type->get_attributes(),
								'default'              => array(),
							),
							'post_id'    => array(
								'description' => __( 'ID of the post context.' ),
								'type'        => 'integer',
							),
						),
					),
					'schema' => array( $this, 'get_public_item_schema' ),
				)
			);
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.