I did not have much chance to play with this, but for those who want to use the gallery element, this code should set you in your path.
This is just the starting point - it provides only a list of image identifiers, separated by commas, but this should be enough to start the work.
<input id="custom_media_id" type="text" name="attachment_id" value=""> <a href="#" class="button custom_media_upload" title="Add Media">Add Media</a> <script type="text/javascript"> jQuery('.custom_media_upload').click(function() { var clone = wp.media.gallery.shortcode; wp.media.gallery.shortcode = function(attachments) { images = attachments.pluck('id'); jQuery('#custom_media_id').val(images); wp.media.gallery.shortcode = clone; var shortcode= new Object(); shortcode.string = function() {return ''}; return shortcode; } jQuery(this).blur(); </script>
This will fill the input field with a comma-separated list of image identifiers in the order in which they were set in the editor (using the new drag and drop functions).
The function expects that a short code will be sent for placement in the main editor, but we do not want to do this, so we create a new object that returns an empty string for insertion.
Also note that this does not apply to inserting a single image, as described above - it simply fits into the message editor. Therefore, try to combine the two listeners or delete the corresponding tabs.
EDIT
After spending some time looking at the kernel, I think that the whole process can be simplified using the technique here , but as you read, I have not yet figured out how to pre-select images when re-opening the media manager.
Mark Dec 16 '12 at 12:29 2012-12-16 12:29
source share