WP_REST_Server::add_image_to_index
Exposes an image through the WordPress REST API. This is used for fetching this information when user has no rights to update settings.
Метод класса: WP_REST_Server{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->add_image_to_index( $response, $image_id, $type );
- $response(WP_REST_Response) (обязательный)
- REST API response.
- $image_id(int) (обязательный)
- Image attachment ID.
- $type(строка) (обязательный)
- Type of Image.
Список изменений
| С версии 5.9.0 | Введена. |
Код WP_REST_Server::add_image_to_index() WP REST Server::add image to index WP 7.0
protected function add_image_to_index( WP_REST_Response $response, $image_id, $type ) {
$response->data[ $type ] = (int) $image_id;
if ( $image_id ) {
$response->add_link(
'https://api.w.org/featuredmedia',
rest_url( rest_get_route_for_post( $image_id ) ),
array(
'embeddable' => true,
'type' => $type,
)
);
}
}