WP_REST_Block_Directory_Controller::prepare_links() WordPress Method

The WP_REST_Block_Directory_Controller::prepare_links() function is used to prepare links for the WordPress REST API. This function is used to add links to the top-level REST API endpoints for blocks.

WP_REST_Block_Directory_Controller::prepare_links( array $plugin ) #

Generates a list of links to include in the response for the plugin.


Parameters

$plugin

(array)(Required)The plugin data from WordPress.org.


Top ↑

Return

(array)


Top ↑

Source

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

	protected function prepare_links( $plugin ) {
		$links = array(
			'https://api.w.org/install-plugin' => array(
				'href' => add_query_arg( 'slug', urlencode( $plugin['slug'] ), rest_url( 'wp/v2/plugins' ) ),
			),
		);

		$plugin_file = $this->find_plugin_for_slug( $plugin['slug'] );

		if ( $plugin_file ) {
			$links['https://api.w.org/plugin'] = array(
				'href'       => rest_url( 'wp/v2/plugins/' . substr( $plugin_file, 0, - 4 ) ),
				'embeddable' => true,
			);
		}

		return $links;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.