Wordpress tinyMCE window 管理器上传按钮未将 url 添加到文本字段

Wordpress tinyMCE window manager upload button not adding url to text field

我在 WYSIWYG 中添加了一个按钮,它会打开一个弹出窗口,其中包含要填写的字段。对于这些字段,我试图添加另一个按钮,该按钮将从媒体库中选择一个文件并插入 link/url在文本字段中。我有按钮工作,它打开了媒体库,但是当我 select 一个文件时,文本字段中没有插入任何内容。

如果我在媒体 selection 之后添加 json.url 的警报,它将提醒我文件 link,所以我知道它正在获取 url 从文件中。但是,我无法将其输入文本字段。

这是我的 editor_plugin.js 文件中的一段代码:

{
    type: 'textbox',
    name: 'myfile',
    label: 'My File',
    id: 'my-file',
    value: ''
},{
    type: 'button',
    name: 'select-file',
    text: 'Upload File',
    onclick: function() {
        window.mb = window.mb || {};

        window.mb.frame = wp.media({
            frame: 'post',
            state: 'insert',
            library : {
                type : 'image'
            },
            multiple: false
        });

        window.mb.frame.on('select', function() {
            var json = window.mb.frame.state().get('selection').first().toJSON();
            alert(json.url);
            if (0 > $.trim(json.url.length)) {
                return;
            }

            $('#my-file').val(json.url);
        });

        window.mb.frame.open();
    }
}

解决了!!

我从 wp.media 中删除了 "frame" & "state" 并将“$”更改为 "jQuery"

window.mb.frame = wp.media({

            library : {
                type : 'image'
            },
            multiple: false
        });

        window.mb.frame.on('select', function() {
            var json = window.mb.frame.state().get('selection').first().toJSON();

            if (0 > $.trim(json.url.length)) {
                return;
            }

            jQuery('#my-file').val(json.url);
        });