最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Not able to extend wp.media.view.AttachmentsBrowser

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Jan 30, 2021 at 16:10 zzazzles asked Jan 30, 2021 at 16:03 zzazzleszzazzles 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

发布评论

评论列表(0)

  1. 暂无评论