WP_REST_Abilities_V1_List_Controller::prepare_item_for_response
Prepares an ability for response.
Метод класса: WP_REST_Abilities_V1_List_Controller{}
Хуков нет.
Возвращает
WP_REST_Response. Response object.
Использование
$WP_REST_Abilities_V1_List_Controller = new WP_REST_Abilities_V1_List_Controller(); $WP_REST_Abilities_V1_List_Controller->prepare_item_for_response( $ability, $request );
- $ability(WP_Ability) (обязательный)
- The ability object.
- $request(WP_REST_Request) (обязательный)
- Request object.
Список изменений
| С версии 6.9.0 | Введена. |
Код WP_REST_Abilities_V1_List_Controller::prepare_item_for_response() WP REST Abilities V1 List Controller::prepare item for response WP 7.1.2
public function prepare_item_for_response( $ability, $request ) {
$data = array(
'name' => $ability->get_name(),
'label' => $ability->get_label(),
'description' => $ability->get_description(),
'category' => $ability->get_category(),
'input_schema' => wp_prepare_json_schema_for_client( $ability->get_input_schema() ),
'output_schema' => wp_prepare_json_schema_for_client( $ability->get_output_schema() ),
'meta' => $ability->get_meta(),
);
$context = $request['context'] ?? 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
$response = rest_ensure_response( $data );
$fields = $this->get_fields_for_response( $request );
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
$links = array(
'self' => array(
'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $ability->get_name() ) ),
),
'collection' => array(
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
),
);
$links['wp:action-run'] = array(
'href' => rest_url( sprintf( '%s/%s/%s/run', $this->namespace, $this->rest_base, $ability->get_name() ) ),
);
$response->add_links( $links );
}
return $response;
}