I have little problem with Media Uploader in new WordPress 3.5. I created own plugin which is upload the picture. I’m using this code JS:
<script type="text/javascript">
var file_frame;
jQuery('.button-secondary').live('click', function( event ){
event.preventDefault();
if ( file_frame ) {
file_frame.open();
return;
}
file_frame = wp.media.frames.file_frame = wp.media(
{
title: 'Select File',
button: {
text: jQuery( this ).data( 'uploader_button_text' )
},
multiple: false
}
);
file_frame.on('select', function() {
attachment = file_frame.state().get('selection').first().toJSON();
jQuery('#IMGsrc').val(attachment.url);
});
file_frame.open();
});
</script>
The code works fine, but unfortunately forms appears incomplete. When I select any picture doesn’t show me ‘Attachment Display Settings’ on right side. I don’t know why. I try add options to media:
displaySettings: true,
displayUserSettings: true
But it also doesn’t work.
Only Uploader
below a example code, works only on post edit page. If you will use also on other page, then include the function
wp_enqueue_media()
, see the next headline.Short explanation of Media Manager
At first include the relevant scripts, use the core function:
wp_enqueue_media();
The function set up all the relevant settings, localizes menu text, and loads in all the appropriate javascript files.
You can add custom script via
wp_enqueue_script()
.Add also a default script for custom header:
wp_enqueue_script( 'custom-header' );
This creates an image selection frame, and ties it to an interface element, for example a button or link. It then calls a url or our choice with the selected image id. This is the same script that is used when selecting theme custom header images.
Add the button to media manager:
Define Action Function
last, you need to add in some code for processing the image id that we will pass to the data-update-link url.
Sources and hints:
I have put a answer in the stackoverflow.com site as well and that would be help.
I’m using this method to use media uploader into my custom plugin.May be this would be help.
in the main theme file(index.php) add these.
In the admin_script.js file,
admin file(admin_settings.php),
More details in my blog
More info
http://webexplorar.com/how-to-use-media-uploader-in-wordpress-custom-plugin/
Just use this code for media uploader .
you got link in jquery response.