Add inline uploader to plugin option page

Okay, here is what I came up with: It’s all about using the plupload library that comes shipped with WP. 1. Add a <div> to your plugin’s option page that later becomes the drag’n’drop area <div class=”your-plugin-uploader multiple”> <input id=”your-plugin-uploader-button” type=”button” value=”<?php esc_attr_e( ‘Select Files’ ); ?>” class=”your-plugin-uploader-button button”> <span class=”ajaxnonce” id=”<?php echo wp_create_nonce( __FILE__ … Read more

Filter for changing MediaElement.js Settings

Copy wp-includes/js/mediaelement/wp-mediaelement.js into your theme or plugin and make your modifications there. For example, I added some settings to force the use of native video controls on iOS & Android devices, like so: (function ($) { // add mime-type aliases to MediaElement plugin support mejs.plugins.silverlight[0].types.push(‘video/x-ms-wmv’); mejs.plugins.silverlight[0].types.push(‘audio/x-ms-wma’); $(function () { var settings = { // Put … Read more

Image upload callback in new 3.5 media

There is a FileUploaded event being fired in wp-includes/js/plupload/wp-plupload.js. Alternatively (and propably the better way) you may want extend wp.Uploader with your own success callback . (function($){ $.extend( wp.Uploader.prototype, { success : function( file_attachment ){ console.log( file_attachment ); } }); })(jQuery);

Stop WordPress from reserving slugs for media items?

Thank you for the response everyone. I played around with macemmek’s solution and I think it led me to an even better solution: add_filter( ‘wp_unique_post_slug_is_bad_attachment_slug’, ‘__return_true’ ); That is all that is needed. This will automatically ‘skip’ the default assigned slug on any attachment. So an attachment that might normally get the slug “services” will … Read more

Proper way to add a button to the top menu of the media library?

So, this is the only way I’ve found so far and it’s ugly, however WordPress offers no means of modifying this through filters that I can find in core. I present, the hacky “do-it-through-Javascript” method: add_action( ‘load-upload.php’, function(){ $js = <<<JAVASCRIPT jQuery(document).ready(function($){ setTimeout(function() { $(‘.wp-filter .button:last’ ).after($(‘<button class=”button”>Hi</button>’)); }, 1000); }); JAVASCRIPT; add_filter( ‘admin_footer’, function() … Read more

Display attachments by ID in a wp.media frame

You can always filter on the client side: var query = wp.media.query(); query.filterWithIds = function(ids) { return _(this.models.filter(function(c) { return _.contains(ids, c.id); })); }; var res = query.filterWithIds([6,87]); // change these to your IDs res.each(function(v){ console.log( v.toJSON() ); }); Disclaimer: found the beautiful filterWithIds function in this SO question.