我正在创建一个wordpress插件,我需要让客人上传图片,我的媒体上传器已成功打开,但在上传照片时显示错误。我的代码在下面,
这是我的php代码
add_action('wp_enqueue_scripts', 'my_admin_scripts');
function my_admin_scripts()
{
wp_enqueue_media();
wp_register_script('my-admin-js', WP_PLUGIN_URL . '/foldername/js/call_media_uploader.js', array('jquery'));
wp_enqueue_script('my-admin-js');
}
这是jquery代码
jQuery(document).ready(function(jQuery){
var custom_uploader;
jQuery('#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();
jQuery('#upload_image').val(attachment.url);
});
//Open the uploader dialog
custom_uploader.open();
});
});
请告诉我如何使用wordpress默认媒体上传器上传图片。
答案 0 :(得分:0)
也许不是。 WordPress不支持来宾启用媒体上传器。