I import image to wordpress via wp_insert_attachment
.
On frontend wordpress media library still don't know that image is imported. I need a way to update attachments in media library without refreshing page.
I found partial solution:
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);
Problem with this part of code is that now when I try to upload photo using Media Library uploader, image is uploaded correctly but it's not displayed.