WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
thumbnails not included for attachment + fix (5 posts)

  1. Marco
    Member
    Posted 1 year ago #

    I noticed thumbnails had gone missing and found the problem:
    In models/attachment.php, line 44, change
    get_bloginfo('home') to site_url()

    I have an installation where the actual WP files are under the /wordpress directory and this change resolved the issue.

    http://wordpress.org/extend/plugins/json-api/

  2. weskoop
    Member
    Posted 1 year ago #

    Even safer is to use wp_upload_dir();

    function query_images() {
        $sizes = array('thumbnail', 'medium', 'large', 'full');
        if (function_exists('get_intermediate_image_sizes')) {
          $sizes = array_merge(array('full'), get_intermediate_image_sizes());
        }
        $this->images = array();
        $upload_dir = wp_upload_dir();
        foreach ($sizes as $size) {
          list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size);
          $filename = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $url);
          if (file_exists($filename)) {
            list($measured_width, $measured_height) = getimagesize($filename);
            if ($measured_width == $width &&
                $measured_height == $height) {
              $this->images[$size] = (object) array(
                'url' => $url,
                'width' => $width,
                'height' => $height
              );
            }
          }
        }
      }
  3. rfros
    Member
    Posted 10 months ago #

    using site_url() (not up_upload_dir(), unfortunately) worked for me -- thanks!

  4. Bob Gregor
    Member
    Posted 9 months ago #

    I had the same issue - and had to revert to older code that doesn't check file paths & image sizes - just builds a list of images base on WordPress's wp_get_attachment_image_src()

  5. jfreake
    Member
    Posted 4 months ago #

    Before making changes to the plugin code, check to see if you have jetpack>photon enabled. It rewrites the thumbnail urls to include the wp.com cdn in such a way that that makes the fileexists check fail.
    I disabled photon and the thumbnail urls reappeared in the JSON feed.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic