WP_REST_Block_Types_Controller::prepare_links( WP_Block_Type $block_type ): array

In this article

Prepares links for the request.

Parameters

$block_typeWP_Block_Typerequired
Block type data.

Return

array Links for the given block type.

Source

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;
}

Changelog

VersionDescription
5.5.0Introduced.

User Contributed Notes

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