0

I have written a plugin that uses the new media manager UI to insert images into a custom gallery custom post type. Everything works 100% but on a specific user's site something strange is happending that I cannot reproduce locally. Here is the code:

    var attachments = FOOGALLERY.media_uploader.state().get('selection').toJSON();

    $.each(attachments, function(i, item) {
      if (item && item.id && item.sizes && item.sizes.thumbnail) {
        var attachment = {
            id: item.id,
            src: item.sizes.thumbnail.url
        };

        FOOGALLERY.addAttachmentToGalleryList(attachment);
    } else {
        //there was a problem adding the item! Move on to the next
    }

As you can see on line 3, it does a check if the item is valid before it adds the thumb to the gallery.

item.sizes has data, but it only contains full but I rely on it having thumbnail to insert the thumb. Basically, item.sizes.thumbnail is return false so it never adds the image to the gallery.

So my question is "Why no thumbnail, dude?"

I checked his media settings and he does have thumbnails set at 200x200. The media library itself is showing his thumbnail images in the modal too.

As I said, I cannot reproduce this locally no matter what I try, and my items.sizes always contains thumbnail

0

It seems that if the default images sizes have been changed, then there will be an instance when the item.sizes.thumbnail will be underfined.

I ended up building in a check for this and if thumbnail was not defined, then I use the original image instead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.