Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress自定义上载程序不显示附件设置_Wordpress_Wordpress Theming - Fatal编程技术网

Wordpress自定义上载程序不显示附件设置

Wordpress自定义上载程序不显示附件设置,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我一直在寻找这个,但没有发现任何与此相关的东西 我在插件中使用自定义上传程序插入图像 我使用的代码是 $('#upload_image_button').click(function(e) { e.preventDefault(); //If the uploader object has already been created, reopen the dialog if (custom_uploader) { custom_uploader.open(

我一直在寻找这个,但没有发现任何与此相关的东西

我在插件中使用自定义上传程序插入图像

我使用的代码是

$('#upload_image_button').click(function(e) {
    e.preventDefault();
    //If the uploader object has already been created, reopen the dialog
    if (custom_uploader) {
        custom_uploader.open();
        return;
    }
    //Extend the wp.media object
    custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Choose Image',
        button: {
            text: 'Choose Image'
        },
        multiple: false
    });
    //When a file is selected, grab the URL and set it as the text field's value
    custom_uploader.on('select', function() {
        attachment = custom_uploader.state().get('selection').first().toJSON();
        console.log(attachment);
        $('.ppwfg-images td').append( "<div id='image-placeholders' style='width:75px; height:75px; margin: 3px; float: left;'>" );
        $('#image-placeholders').append( "<input type='text' id='upload_image' name='ppwfg[]' class='' value=''  size='10' hidden />" );
        $('#image-placeholders').append( "<img src='' id='upload_image_holder' class='ppwfg_image' style='width:75px; height:75px; margin: 3px;'/>" );
        $('#image-placeholders').append( "<a class='close-overlay remove'>x</a>" );

        $('#image-placeholders').attr("id", attachment.id);

        $('#upload_image').attr("value", attachment.url);
        $('#upload_image').attr("class", attachment.id);
        $('#upload_image').attr("id", attachment.id);

        $('#upload_image_holder').attr("src", attachment.url);
        $('#upload_image_holder').attr("class", attachment.id);
        $('#upload_image_holder').attr("id", attachment.id);
    });
    //Open the uploader dialog
    custom_uploader.open();
});
$(“#上传图像按钮”)。单击(功能(e){
e、 预防默认值();
//如果已创建uploader对象,请重新打开该对话框
if(自定义上传器){
自定义上传程序.open();
返回;
}
//扩展wp.media对象
自定义上传程序=wp.media.frames.file\u frame=wp.media({
标题:“选择图像”,
按钮:{
文本:“选择图像”
},
多重:假
});
//选择文件后,抓取URL并将其设置为文本字段的值
自定义上传器.on('select',function(){
attachment=custom_uploader.state().get('selection').first().toJSON();
控制台日志(附件);
$('.ppwfg images td')。追加(“”);
$(“#图像占位符”)。追加(“”);
$(“#图像占位符”)。追加(“”);
$(“#图像占位符”)。附加(“x”);
$(“#图像占位符”).attr(“id”,附件.id);
$('#upload_image').attr(“value”,attachment.url);
$('#upload_image').attr(“class”,attachment.id);
$('#upload_image').attr(“id”,attachment.id);
$('upload_image_holder').attr(“src”,attachment.url);
$('upload_image_holder').attr(“class”,attachment.id);
$('upload_image_holder').attr(“id”,附件.id);
});
//打开uploader对话框
自定义上传程序.open();
});
上传程序打开,我可以选择一个图像并插入它,但问题是它总是使用主图像,并且不显示附件设置和下拉选择使用哪个图像。。。所以我留下了默认的图像,它最终会变大


如何在media.frame中显示附件设置?

太旧了,但我认为我应该为仍在查看的人提供答案

custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Choose Image',
        button: {
            text: 'Choose Image'
        },
        frame: 'post',
        state:    'insert',
        multiple: false
    });

    //When a file is selected, grab the URL and set it as the text field's value
    custom_uploader.on('insert', function() {
您可以选择frame:post,但必须选择state:insert并使用函数custom\u uploader.on('insert',function(){