I am trying to add a unique custom tab to the Media Uploader using this code.
var customMedia = wp.media({
state: 'customState',
states: [
new wp.media.controller.Library({
id: 'customState',
title: 'Library',
library: wp.media.query({
type: 'image',
category: 'icon' // adding a filter to ajax_query_attachments_args
}),
multiple: false,
date: false,
})
]
});
So far it shows up the Media modal with the images in there as I expected. The issue is when I upload a file by drag and drop it won’t appear on the list of attachments view when the upload finishes, although it does upload the file. And it appears when the page is refreshed. https://share.getcloudapp.com/xQuY8gQW
I added one more state but without the ‘category’ in the query and when I do drag and drop, the image uploads as usual but it appears on the second tab.
Is there anything else I am missing? I tried reading the code for the options that the library receives and couldn’t figure it out.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Found 2 other questions similar (almost the same?) as mine:
And found the solution in one of the comments in the latter. It links to a ticket and the last post has the solution to it:
var customMedia = wp.media({
state: 'customState',
states: [
new wp.media.controller.Library({
id: 'customState',
title: 'Library',
library: wp.media.query({
type: 'image',
category: 'icon' // adding a filter to ajax_query_attachments_args
}),
multiple: false,
date: false,
})
]
});
// This will add the item uploaded to the list of attachments in the moodal
customMedia.states.get('library').get('library').observe( wp.Uploader.queue );
This won’t fix the issue when opening the modal again. It doesn’t show the images that were just added.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0