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.
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.
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/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.
Share Improve this question asked Jan 12, 2021 at 18:50 Jose AdrianJose Adrian 1114 bronze badges1 Answer
Reset to default 0Found 2 other questions similar (almost the same?) as mine:
- Trigger refresh for new media manager in 3.5
- Media Modal not updating with file upload
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.