Prepares the plugin for the REST response.
Parameters
$item
arrayrequired- Unmarked up and untranslated plugin data from get_plugin_data().
$request
WP_REST_Requestrequired- Request object.
Source
public function prepare_item_for_response( $item, $request ) {
$fields = $this->get_fields_for_response( $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 );
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
$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 get_plugin_data().
* @param WP_REST_Request $request The request object.
*/
return apply_filters( 'rest_prepare_plugin', $response, $item, $request );
}
Hooks
- apply_filters( ‘rest_prepare_plugin’,
WP_REST_Response $response ,array $item ,WP_REST_Request $request ) Filters plugin data for a REST API response.
Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.