WP_REST_Server::add_image_to_index() WordPress Method
The WP_REST_Server::add_image_to_index() method allows you to add an image to the WordPress REST API index. This method accepts two arguments: the image ID and the image URL. The image ID is the number that is assigned to the image when it is uploaded to the WordPress media library. The image URL is the URL of the image file. This method can be used to add an image to the WordPress REST API index when the image is uploaded to the WordPress media library.
WP_REST_Server::add_image_to_index( WP_REST_Response $response, int $image_id, string $type ) #
Exposes an image through the WordPress REST API.
Description
This is used for fetching this information when user has no rights to update settings.
Parameters
- $response
(WP_REST_Response)(Required)REST API response.
- $image_id
(int)(Required)Image attachment ID.
- $type
(string)(Required)Type of Image.
Source
File: wp-includes/rest-api/class-wp-rest-server.php
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, ) ); } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |