• Today, I finally updated the plugin from version 1.0.7 to 1.1.1. All works well, except the attachments of sub-blogs, all image variations are empty.
    The cause: the check if a file exists is done using ABSPATH, concatenated with a substring of the url. However, the subdir in which the blog resides is stripped off during this action.
    If the file exists check is necessary, one should use upload-path from the blogsettings, because this variable holds the correct path to the files from ABSPATH. No need to substring the url.
    instead of:

    <br />
    $filename = ABSPATH . substr($url, strlen($home) + 1);<br />

    better use:

    <br />
    $upload_dir = wp_upload_dir();<br />
    $filename = $upload_dir['path'] .'/'. basename(parse_url($url, PHP_URL_PATH));<br />

    [edit]
    I’m sorry, I was too hasty with my ‘patch’ because i forgot that $upload_dir[‘path’] returns the current folder if you use month-based subfolders, i’ll search for a better solution
    https://www.ads-software.com/plugins/json-api/

Viewing 1 replies (of 1 total)
  • Thread Starter xiffy

    (@xiffy)

    Okay, forgive my hastiness on the previous post. I played around with some multisite installs, and this is what i came up with for the JSON_API_Attachment::query_images method:

    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();
    $home = get_bloginfo('url');
    $upload_dir = wp_upload_dir();
    $basedir = $upload_dir['basedir'];
    $file = get_post_meta($this->id, '_wp_attached_file', true);

    foreach ($sizes as $size) {
    list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size);
    $filename = $basedir . '/' . str_replace(basename($file), basename(parse_url($url, PHP_URL_PATH)), $file);
    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
    );
    }
    }
    }
    }

    This does get the image src correctly for all types of install, it’s not as straightforward as I hoped it should be.

Viewing 1 replies (of 1 total)
  • The topic ‘models/attachment.php bug with getting attachments on folder-mulit-site installs’ is closed to new replies.