In my plugin, I would like to add two buttons to Media Manager (to the left of “Insert Into Post” in “media-toolbar-primary” section), and connect a jQuery action to it.
- First one – The “Select All” button shoud allow to select all availabe images (only images), depending on option value selected (eg. All Media Items, Uploaded to This post etc). So if “All Media Items” is selected – all images available will be selected, if “Uploaded to This post” is selected – only images attached to current post will be selected.
- Second one – “Custom Insert Into Post” – will get images data for all selected images (full size image source, alt text, size etc that are available) and while allowing to wrap them in aditional html code – return code to tinymce editor.
Returned code for second button could look this way:
<ul>
<li><img src="full/path/to/001.jpg" alt="alt text 1" /></li>
<li><img src="full/path/to/002.jpg" alt="alt text 2" /></li>
<li><img src="full/path/to/003.jpg" alt="alt text 3" /></li>
<li><img src="full/path/to/004.jpg" alt="alt text 4" /></li>
<li><img src="full/path/to/005.jpg" alt="alt text 5" /></li>
</ul>
As far as I understand, the only way is to use override appropriate Backbone view, but beside that, thats all I know for now.
Thanks for help.
This block of code will add a button right next to the “Insert into post” one. When clicked, it will send selected images to WP editor, each wrapped inside your template HTML:
Adding a custom button is not a problem. But selecting “all images” could be a bit tricky because WP 3.5 media browser loads attachments bit by bit. I’ll look into it, but I recommend selecting attachments manually.
Write a small plugin, use the follow example source to add a item in the list of the left sidebar in the media manager inside the overlay popup.
Result of the source below:
Init solution form this WPSE Answer.
Link to draft plugin example to add a javascript menu into the WP3.5 Media Library popup
I do not have a full answer to your question, but here is a good start.
To customize the new Media Manager, you should study the javascript Backbone code in
wp-includes/js/media-views.js
.For exemple, here is a small plugin that adds a “Select All” button to the “Insert from URL” Toolbar :
custom.php
:custom.js
:For the “Custom insert into post” button, I suggest to use the gallery shortcode instead. The UI already exist to select the desired images and insert the shortcode at the right place in tinymce. All you have to do is to write your own gallery shortcode format.
Take a look at
gallery_shortcode
function inwp-includes/media.php
and use thepost_gallery
filter.Thomas Griffin created a plugin example, New Media Image Uploader, on how to work with the new media manager.
I’ve just encountered a case in WP 3.6 where aesqe’s (very useful) answer results in images being inserted twice due to backbone’s
state.get("selection")._byId
including bothid
andcid
for each image selected.Changing
state.get("selection")._byId
tostate.get("selection").models
fixed this for me while preserving each object’s attributes.Hopefully this will save someone some frustration. I would have posted this as a comment instead of an answer but, alas, I have no reputation.