I am creating a wordpress plugin where I need to make able guests to upload images , my media uploader successfully opened but it shows error while uploading photo . My codes are below,
This is my php code
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');
}
and this is the jquery code
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();
});
});
Please tell me how can it possible to upload image using wordpress default media uploader .
Maybe not. WordPress does not support for guest to enable media uploader.