[wp-hackers] Wordpress Media Uploader Use in a Plugin

BenderisGreat greglancaster71 at gmail.com
Mon Jul 7 21:18:27 UTC 2014


I am having some trouble using the Media Library in a plugin.  I have a meta
box in the new post area, and it allows for selection of a picture. The
issue is I dont see how to allow selection of more than one image, but more
importantly the image is returned at full size.  The attachment var returns
only the full size.  I am using this jQuery :

jQuery(document).ready(function($){
      var custom_uploader;
    $('#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({
              title: 'Choose Image',
              button: {
                  text: 'Choose Image',
              },
              multiple: false,
             // If you pretent a function only for images you can limit the
media elements only to images
             library : { type : 'image' }
         });

         //When close, grab the url of the image where needed
        custom_uploader.on('close', function() {
            attachment =
custom_uploader.state().get('selection').first().toJSON();
            console.log(attachment); ## This only returns the full size url,
no thumbnails.
            $('#upload_image').val(attachment.url);
            $('.custom_preview_image').attr("src", attachment.url);
        });

       //Open the uploader dialog
       custom_uploader.open();
   });

    $('#clear_images').click(function() {  
        var defaultImage =
jQuery(this).parent().siblings('.custom_default_image').text();  
		$('#upload_image').val('');
        $('img.custom_preview_image').attr('src', '');
        return false;  
    });  
});

Is there something I am doing wrong?  Or is returning the full size media
file the only available option?  (I followed most of this tutorial to get
where I am guys --
http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/
)



--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/Wordpress-Media-Uploader-Use-in-a-Plugin-tp44096.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.


More information about the wp-hackers mailing list