From c000b6825b138a2e3a403984371d9c851f8c2744 Mon Sep 17 00:00:00 2001 From: s43 Date: Mon, 26 Jan 2015 11:00:41 +0000 Subject: [PATCH] Adding the possibility to pick a specified size Basically the variable "attachment.url" gives in return the full size of the image, I've been through a case where I needed to pick a specific cropped size, otherwise the images shows up in a bad resolution on the front-end. The Wp media editor returns gives is to arguments, props has an object with the selected size it, and attachment has almost everything about the file, including the sizes with it urls. I fixed it for my self, and I wanted to share it with others, and hopefully it may be helpful :). Thanks for the good work guys, keep it up! --- public/js/shared.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/public/js/shared.js b/public/js/shared.js index 31d1a46..6feabc4 100644 --- a/public/js/shared.js +++ b/public/js/shared.js @@ -926,15 +926,18 @@ if ( vp_wp.use_new_media_upload ) // handler for attachment wp.media.editor.send.attachment = function(props, attachment) { - $input.val(attachment.url); + // Check for sizes + var $selectedSize = attachment.sizes[props.size]; + + $input.val($selectedSize.url); $input.trigger('change'); - if(attachment.type === 'image') - $preview.attr('src', attachment.url); + if($selectedSize.type === 'image') + $preview.attr('src', $selectedSize.url); else - $preview.attr('src', attachment.icon); + $preview.attr('src', $selectedSize.icon); - wp.media.editor.send.attachment = _orig_send_attachment; + wp.media.editor.send.$selectedSize = _orig_send_attachment; window.send_to_editor = _orig_send_to_editor; }; @@ -1203,4 +1206,4 @@ vp.tinyMCE_save = function() { tinyMCE.triggerSave(false, true); } -}; \ No newline at end of file +};