WP_REST_Plugins_Controller::prepare_item_for_response( mixed $item, WP_REST_Request $request ): WP_REST_Response|WP_Error

Prepares the plugin for the REST response.


Parameters

$item mixed Required
Unmarked up and untranslated plugin data from get_plugin_data() .
$request WP_REST_Request Required
Request object.

Top ↑

Return

WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php. View all references

public function prepare_item_for_response( $item, $request ) {
	$item   = _get_plugin_data_markup_translate( $item['_file'], $item, false );
	$marked = _get_plugin_data_markup_translate( $item['_file'], $item, true );

	$data = array(
		'plugin'       => substr( $item['_file'], 0, - 4 ),
		'status'       => $this->get_plugin_status( $item['_file'] ),
		'name'         => $item['Name'],
		'plugin_uri'   => $item['PluginURI'],
		'author'       => $item['Author'],
		'author_uri'   => $item['AuthorURI'],
		'description'  => array(
			'raw'      => $item['Description'],
			'rendered' => $marked['Description'],
		),
		'version'      => $item['Version'],
		'network_only' => $item['Network'],
		'requires_wp'  => $item['RequiresWP'],
		'requires_php' => $item['RequiresPHP'],
		'textdomain'   => $item['TextDomain'],
	);

	$data = $this->add_additional_fields_to_object( $data, $request );

	$response = new WP_REST_Response( $data );
	$response->add_links( $this->prepare_links( $item ) );

	/**
	 * Filters plugin data for a REST API response.
	 *
	 * @since 5.5.0
	 *
	 * @param WP_REST_Response $response The response object.
	 * @param array            $item     The plugin item from {@see get_plugin_data()}.
	 * @param WP_REST_Request  $request  The request object.
	 */
	return apply_filters( 'rest_prepare_plugin', $response, $item, $request );
}

Top ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
5.5.0 Introduced.

Top ↑

User Contributed Notes

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