New to WP development here so please bear with me if I’m missing something simple…
I am writing a plugin for the Media upload library which needs to get the selected media items in Grid View (for drag & drop). I know that the items in the media grid are dynamically generated, so I’m trying to extend the AttachmentsBrowser, and get those elements there during initialize(). However, initialize() is never called.
!function(e) {
var i = {
init: function() {
console.log("This is called");
wp.media.view.AttachmentsBrowser = wp.media.view.AttachmentsBrowser.extend({
initialize: function () {
console.log("This is NOT called.");
},
});
}
}
e(document).ready(function() {
i.init()
})
}(jQuery);
I’ve checked that wp.media.view.AttachmentsBrowser exists. But somehow initialize() doesn’t appear to get called. Is there something else that I need to add?
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
Turns out the reason this happened is because when I registered/enqueued the script, I had in_footer = true. Setting this to the default of false solved the problem.
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