« Back to blog

Defaulting the WordPress Media Uploader to the browser uploader in WP 3.3

Personally I love the new WP Media uploader, however it seems to have been creating trouble for a large number of our contributors. While there are no shortage of sites providing a simple code snippet to disable the old Flash based uploader in versions of WordPress prior to the 3.3 overhaul, we were unable to find any existing solutions to apply a similar tweak to the new media uploader released with WP Sonny.

To resolve this, we added the below code snippet to our custom functions file, which forces the media uploader to default to the browser uploader in 3.3, while still allowing access to the new uploader on demand:

add_action('pre-html-upload-ui', 'sw_switch_to_browser_uploader');

function sw_switch_to_browser_uploader()
{
?>
 <script type="text/javascript">
 (function($, exports) {
 $('document').ready(function() {
 var divs = $('#plupload-upload-ui, #html-upload-ui');
 var links = $('a').filter(function() { return $(this).text() == 'Switch to the new uploader' || $(this).text() == 'browser uploader'});
 links.click(function() {
 divs.each(function() {
 if ($(this).css('display') == 'none') $(this).show();
 else $(this).hide();
 });
 });
 $('#plupload-upload-ui').hide();
 $('#html-upload-ui').show();
 });
 })(jQuery, window);
 </script>
<?php
}

Seeing as how this was a fairly popular topic pre-3.3, we’ve bundled this as a plugin for easy implementation and made it available here.

If you’ve come up with your own interesting tweaks to the new media uploader in WP Sonny, we’d love to hear about it in the comments.

from BostInno http://bostinno.com/all-series/defaulting-the-wordpress-media-uploader-to-the...