public function get_item($request)
{
$id = (int) $request['id'];
$post = get_post($id);
if (empty($id) || empty($post->ID) || $this->post_type !== $post->post_type) {
return new WP_Error('rest_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
}
$data = $this->prepare_item_for_response($post, $request);
$response = rest_ensure_response($data);
if (is_post_type_viewable(get_post_type_object($post->post_type))) {
$response->link_header('alternate', get_permalink($id), array('type' => 'text/html'));
}
return $response;
}