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.
Method of the class: WP_REST_Server{}
No Hooks.
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->add_image_to_index( $response, $image_id, $type );
- $response(WP_REST_Response) (required)
- REST API response.
- $image_id(int) (required)
- Image attachment ID.
- $type(string) (required)
- Type of Image.
Changelog
Since 5.9.0 | Introduced. |
WP_REST_Server::add_image_to_index() WP REST Server::add image to index code WP 6.6.2
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, ) ); } }