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

$responseWP_REST_Responserequired
REST API response.
$image_idintrequired
Image attachment ID.
$typestringrequired
Type of Image.

Source

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,
			)
		);
	}
}

Changelog

VersionDescription
5.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.