/**
  * Get attachment-specific data
  *
  * @param array $post
  * @return array
  */
 protected function prepare_post($post, $context = 'single')
 {
     $data = parent::prepare_post($post, $context);
     if (is_wp_error($data) || $post['post_type'] !== 'attachment') {
         return $data;
     }
     // $thumbnail_size = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail';
     $data['source'] = wp_get_attachment_url($post['ID']);
     $data['is_image'] = wp_attachment_is_image($post['ID']);
     $data['attachment_meta'] = wp_get_attachment_metadata($post['ID']);
     // Ensure empty meta is an empty object
     if (empty($data['attachment_meta'])) {
         $data['attachment_meta'] = new stdClass();
     } elseif (!empty($data['attachment_meta']['sizes'])) {
         $img_url_basename = wp_basename($data['source']);
         foreach ($data['attachment_meta']['sizes'] as $size => &$size_data) {
             // Use the same method image_downsize() does
             $size_data['url'] = str_replace($img_url_basename, $size_data['file'], $data['source']);
         }
     } else {
         $data['attachment_meta']['sizes'] = new stdClass();
     }
     // Override entity meta keys with the correct links
     $data['meta'] = array('links' => array('self' => json_url('/media/' . $post['ID']), 'author' => json_url('/users/' . $post['post_author']), 'collection' => json_url('/media'), 'replies' => json_url('/media/' . $post['ID'] . '/comments'), 'version-history' => json_url('/media/' . $post['ID'] . '/revisions')));
     if (!empty($post['post_parent'])) {
         $data['meta']['links']['up'] = json_url('/media/' . (int) $post['post_parent']);
     }
     return apply_filters('json_prepare_attachment', $data, $post, $context);
 }
 /**
  * Prepare post data
  *
  * @param array $post The unprepared post data
  * @param string $context The context for the prepared post. (view|view-revision|edit|embed|single-parent)
  * @return array The prepared post data
  */
 protected function prepare_post($post, $context = 'view')
 {
     $_post = parent::prepare_post($post, $context);
     if (is_wp_error($_post)) {
         return $_post;
     }
     // Override entity meta keys with the correct links
     $_post['meta'] = array('links' => array('self' => json_url($this->base . '/' . $post['ID']), 'author' => json_url('/users/' . $post['post_author']), 'collection' => json_url($this->base), 'replies' => json_url($this->base . '/' . $post['ID'] . '/comments'), 'version-history' => json_url($this->base . '/' . $post['ID'] . '/revisions')));
     if (!empty($post['post_parent'])) {
         $_post['meta']['links']['up'] = json_url($this->base . '/' . $post['ID']);
     }
     return apply_filters("json_prepare_{$this->type}", $_post, $post, $context);
 }