WP_REST_Attachments_Controller::prepare_links( WP_Post $post ): array

In this article

Prepares attachment links for the request.

Parameters

$postWP_Postrequired
Post object.

Return

array Links for the given attachment.

Source

protected function prepare_links( $post ) {
	$links = parent::prepare_links( $post );

	if ( ! empty( $post->post_parent ) ) {
		$post = get_post( $post->post_parent );

		if ( ! empty( $post ) ) {
			$links['https://api.w.org/attached-to'] = array(
				'href'       => rest_url( rest_get_route_for_post( $post ) ),
				'embeddable' => true,
				'post_type'  => $post->post_type,
				'id'         => $post->ID,
			);
		}
	}

	return $links;
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

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