WP_REST_Widgets_Controller::prepare_links()protectedWP 5.8.0

Prepares links for the widget.

Method of the class: WP_REST_Widgets_Controller{}

No Hooks.

Return

Array. Links for the given widget.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_links( $prepared );
$prepared(array) (required)
Widget.

Changelog

Since 5.8.0 Introduced.

WP_REST_Widgets_Controller::prepare_links() code WP 6.5.2

protected function prepare_links( $prepared ) {
	$id_base = ! empty( $prepared['id_base'] ) ? $prepared['id_base'] : $prepared['id'];

	return array(
		'self'                      => array(
			'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $prepared['id'] ) ),
		),
		'collection'                => array(
			'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
		),
		'about'                     => array(
			'href'       => rest_url( sprintf( 'wp/v2/widget-types/%s', $id_base ) ),
			'embeddable' => true,
		),
		'https://api.w.org/sidebar' => array(
			'href' => rest_url( sprintf( 'wp/v2/sidebars/%s/', $prepared['sidebar'] ) ),
		),
	);
}