Skip to main content
improved solution
Source Link
z1ad
  • 46
  • 3

Im also having this issue and Ive been searching for a solution for the last few days but I couldnt find one.

Basically once you set ignore:(+ new Date()), the uploader uploads to the old non-ignore collection. You can verify this by manually setting ignoreedit:null ok after an upload and seeing that the upload appears again. The downside toworking on this is that it loads an old cached collection so you losefor the refresh functionality.

I did manage to figure outlast hour ive finally found a workaround using collection.reset() but its not perfect as it clears the gallery during upload. But once the upload completes everything renders correctly again.solution that works without affecting uploading and without messing with ignore or reset

// this runs once upload starts
wp.media.frame.on('library:selection:add''open', function() {
    if (wp.media.frame.content.get() !== null) {          
         wp.media.frame.content.get().collection.props.set({ignore: null});
        wp.media.frame.content.get().collection.reset(); // this is the missing link
 forces a refresh }of elsethe {content
        wp.media.frame.library.propscontent.setget({ignore: null});
    }
}, this);

wp.media.framecollection.on('open', function_requery(true) {;
    if (wp.media.frame.content.get() !== null) {          
        wp.media.frame.content.get().collection.props.set({ignore:// (+optional: newreset Date())});selection
        wp.media.frame.content.get().options.selection.reset();
    } else {
        wp.media.frame.library.props.set({ignore: (+ new Date())});
    }
}, this);

Im also having this issue and Ive been searching for a solution for the last few days but I couldnt find one.

Basically once you set ignore:(+ new Date()), the uploader uploads to the old non-ignore collection. You can verify this by manually setting ignore:null after an upload and seeing that the upload appears again. The downside to this is that it loads an old cached collection so you lose the refresh functionality.

I did manage to figure out a workaround using collection.reset() but its not perfect as it clears the gallery during upload. But once the upload completes everything renders correctly again.

// this runs once upload starts
wp.media.frame.on('library:selection:add', function() {
    if (wp.media.frame.content.get() !== null) {          
         wp.media.frame.content.get().collection.props.set({ignore: null});
        wp.media.frame.content.get().collection.reset(); // this is the missing link
    } else {
        wp.media.frame.library.props.set({ignore: null});
    }
}, this);

wp.media.frame.on('open', function() {
    if (wp.media.frame.content.get() !== null) {          
        wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())});
        wp.media.frame.content.get().options.selection.reset();
    } else {
        wp.media.frame.library.props.set({ignore: (+ new Date())});
    }
}, this);

edit: ok after working on this for the last hour ive finally found a solution that works without affecting uploading and without messing with ignore or reset

wp.media.frame.on('open', function() {
    if (wp.media.frame.content.get() !== null) {          
        // this forces a refresh of the content
        wp.media.frame.content.get().collection._requery(true);

        // optional: reset selection
        wp.media.frame.content.get().options.selection.reset();
    }
}, this);
Source Link
z1ad
  • 46
  • 3

Im also having this issue and Ive been searching for a solution for the last few days but I couldnt find one.

Basically once you set ignore:(+ new Date()), the uploader uploads to the old non-ignore collection. You can verify this by manually setting ignore:null after an upload and seeing that the upload appears again. The downside to this is that it loads an old cached collection so you lose the refresh functionality.

I did manage to figure out a workaround using collection.reset() but its not perfect as it clears the gallery during upload. But once the upload completes everything renders correctly again.

// this runs once upload starts
wp.media.frame.on('library:selection:add', function() {
    if (wp.media.frame.content.get() !== null) {          
        wp.media.frame.content.get().collection.props.set({ignore: null});
        wp.media.frame.content.get().collection.reset(); // this is the missing link
    } else {
        wp.media.frame.library.props.set({ignore: null});
    }
}, this);

wp.media.frame.on('open', function() {
    if (wp.media.frame.content.get() !== null) {          
        wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())});
        wp.media.frame.content.get().options.selection.reset();
    } else {
        wp.media.frame.library.props.set({ignore: (+ new Date())});
    }
}, this);