public
Last active

Replace the New WP 3.5 Uploader with the Old Thickbox

  • Download Gist
old-upload-method.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
<?php
 
/**
* Plugin Name: Old Upload Method
* Plugin URI: http://wordpress.org/support/topic/is-there-a-way-to-disable-the-new-media-manager
* Description: Replace the new media upload with the old thickbox
* Author: A.Morita, brasofilo
* Version: 1.2
* License: GPLv2 or later
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
if( function_exists( 'add_filter' ) )
add_action( 'plugins_loaded', array( 'I_Want_The_Old_Uploader', 'get_object' ) );
 
/**
* Add Tags and Categories taxonmies to Attachment with WP 3.5
*/
class I_Want_The_Old_Uploader
{
static private $classobj;
 
/**
* Constructor, init the functions inside WP
*
* @since 1.0.0
* @return void
*/
public function __construct()
{
// Run only in editing pages
global $pagenow;
if( !in_array( $pagenow, array('post.php','post-new.php') ) )
return;
// Old Upload buttons and thickbox
add_action( 'admin_head', array( $this, 'remove_media_buttons' ) );
 
// Featured Image
add_action( 'wp_default_scripts', array( $this, 'unset_media_views' ), 999, 1 );
add_action( 'admin_head', array( $this, 'remove_wp_print_media_templates' ) );
 
// Full screen behavior
add_action( 'after_wp_tiny_mce', array( $this, 'fullscreen_media_button' ) );
}
 
 
/**
* Handler for the action 'init'. Instantiates this class.
*
* @since 1.0.0
* @access public
* @return $classobj
*/
public function get_object()
{
if( NULL === self::$classobj )
self::$classobj = new self;
 
return self::$classobj;
}
 
 
/**
* Old Upload Buttons & Thickbox
*/
public function remove_media_buttons()
{
remove_action( 'media_buttons', 'media_buttons' );
add_action( 'media_buttons', array( $this, 'old_media_buttons' ) );
}
 
 
public function old_media_buttons( $editor_id = 'content' )
{
$context = apply_filters( 'media_buttons_context', __( 'Upload/Insert %s' ) );
 
$img = '<img src="'
. esc_url( admin_url( 'images/media-button.png?ver=20111005' ) )
. '" width="15" height="15" />';
 
echo '<a href="'
. esc_url( get_upload_iframe_src() )
. '" class="thickbox add_media" id="'
. esc_attr( $editor_id )
. '-add_media" title="'
. esc_attr__( 'Add Media' )
. '" onclick="return false;">'
. sprintf( $context, $img )
. '</a>';
}
 
 
/**
* Featured image
*/
public function unset_media_views( $scripts )
{
unset( $scripts->registered['media-views'] );
}
 
 
public function remove_wp_print_media_templates()
{
remove_action( 'admin_footer', 'wp_print_media_templates' );
remove_action( 'wp_footer', 'wp_print_media_templates' );
}
 
 
/**
* Adjust Full Screen behavior
* Check if fullscreen exists avoids errors in pages without Editor support
* ie: pages where the regular content textarea is not enabled
*/
public function fullscreen_media_button()
{
?>
<script type="text/javascript">
if( undefined != fullscreen )
{
fullscreen.medialib = function()
{
var href = jQuery('div#wp-content-media-buttons a.thickbox').attr('href') || '';
tb_show('', href);
}
}
</script>
<?php
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.