WP_REST_Attachments_Controller::prepare_links
Prepares attachment links for the request.
Method of the class: WP_REST_Attachments_Controller{}
No Hooks.
Returns
Array. Links for the given attachment.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_links( $post );
- $post(WP_Post) (required)
- Post object.
Changelog
| Since 6.9.0 | Introduced. |
WP_REST_Attachments_Controller::prepare_links() WP REST Attachments Controller::prepare links code WP 7.0
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;
}