WP_REST_Block_Types_Controller::prepare_links()protectedWP 5.5.0

Prepares links for the request.

Method of the class: WP_REST_Block_Types_Controller{}

No Hooks.

Return

Array. Links for the given block type.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_links( $block_type );
$block_type(WP_Block_Type) (required)
Block type data.

Changelog

Since 5.5.0 Introduced.

WP_REST_Block_Types_Controller::prepare_links() code WP 6.6.1

protected function prepare_links( $block_type ) {
	list( $namespace ) = explode( '/', $block_type->name );

	$links = array(
		'collection' => array(
			'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
		),
		'self'       => array(
			'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $block_type->name ) ),
		),
		'up'         => array(
			'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $namespace ) ),
		),
	);

	if ( $block_type->is_dynamic() ) {
		$links['https://api.w.org/render-block'] = array(
			'href' => add_query_arg(
				'context',
				'edit',
				rest_url( sprintf( '%s/%s/%s', 'wp/v2', 'block-renderer', $block_type->name ) )
			),
		);
	}

	return $links;
}