duanhan5388 2015-04-07 10:38
浏览 68

从新的WordPress Media Uploader获取JS回调

Is there a way to listen for an event when a user chooses an image from the WordPress Media Library/Uploader?

I'm developing an extension for a WordPress framework (Layers), which uses it's own controls for uploading images and I don't trigger the Uploader manually, which means I can't hook up to it's callback.

Is there a way to get the "global" media uploader, or the one that's currently open?

Something like:

wp.media().on('insert', function(url) {
    console.log('isnerted image: ' + url);
});

I could not find anything in the WordPress Codex besides this example: http://codex.wordpress.org/Javascript_Reference/wp.media Which assumes that I'm launching the editor myself.

  • 写回答

1条回答 默认 最新

  • dtpngq3378499 2016-09-14 19:16
    关注

    Too late for an assist? I've been looking at the same problem, thought I'd add a thought: The wp media-uploader js is here - https://github.com/WordPress/WordPress/blob/master/wp-includes/js/plupload/wp-plupload.js and looking at this problem https://wordpress.stackexchange.com/questions/92415/image-upload-callback-in-new-3-5-media I see there's a method to extend callbacks from it. After looking at the uploader js I see the following:

    init:     function() {},
    error:    function() {},
    success:  function() {},
    added:    function() {},
    progress: function() {},
    complete: function() {}
    

    which can all be extended using :

    $.extend( wp.Uploader.prototype, {
        success : function(){
            console.log( 'callback action replacing this line' );
        }
    });
    

    replacing success with one of the six options above (in your case I'm thinking 'insert' becomes either 'added', or 'complete') don't knw if that helps?

    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入