Skip to content

Instantly share code, notes, and snippets.

@CodeAngry
Last active December 22, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeAngry/6530089 to your computer and use it in GitHub Desktop.
Save CodeAngry/6530089 to your computer and use it in GitHub Desktop.
WordPress standalone plugin to make the admin menu wider.
<?php
/*
Plugin Name: Wider Admin Menu
Plugin URI: https://github.com/5ubliminal/WordPress-Wider-Admin-Menu
Description: Changes the WordPress admin menu width to <code>apply_filters('admin_menu_width', 200);</code>.
Version: 0.0.7
Author: Claude "CodeAngry" Adrian
Author URI: http://codeangry.com/
License: WTFPL
*/
// Check for direct access
if(!function_exists('add_action')):
header("{$_SERVER['SERVER_PROTOCOL']} 403 Forbidden");
header("Status: 403 Forbidden");
echo 'Why are you here? Be gone!';
die;
endif;
// Change this manually to avoid using plugins for making it wider.
!defined('WPMENU_WIDTH') and define('WPMENU_WIDTH', 200);
// Hook into admin_footer and CSS the width
add_action('admin_footer', function(){
if(empty($GLOBALS['wp_version'])) return; // WTF?!?!
// Get the default width and see if anyone altered it
$DefaultWidth = constant('WPMENU_WIDTH');
if(!is_integer($DefaultWidth) or !$DefaultWidth = intval($DefaultWidth)){
return;
}
// Let's hard limit this to a slightly larger value than the one of WordPress.
$MenuWidth = max(175, intval(apply_filters('admin_menu_width', $DefaultWidth)));
// And output the CSS that does the magic.
echo '<style type="text/css">', PHP_EOL;
// We use the Version with utmost specificity as UI can change and we will just add a new
// if else branch here to match the new design changes WordPress may undergo in time.
global $wp_version;
if(empty($wp_version)):
// Stupid condition so then I can just copy the next line and just paste it before the endif
// therefore maintaing the structural and syntactical similarity.
elseif(version_compare($wp_version, '3.2', '>=') and version_compare($wp_version, '3.3', '<')):
echo '#adminmenuback, #adminmenuwrap, #adminmenu { width: ', $MenuWidth, 'px; }', PHP_EOL;
echo '#wpcontent, #footer, #wpfooter { margin-left: ', $MenuWidth + 15, 'px; }', PHP_EOL;
elseif(version_compare($wp_version, '3.3', '>=') and version_compare($wp_version, '3.8', '<')):
echo '#adminmenuback, #adminmenuwrap, #adminmenu, ',
'#adminmenu .wp-submenu, #adminmenu .wp-submenu-wrap,
.folded #adminmenu .wp-has-current-submenu .wp-submenu ',
'{ ', 'width: ', $MenuWidth, 'px; ', '}', PHP_EOL;
echo '#adminmenu li .wp-submenu, .folded #adminmenu .wp-has-current-submenu .wp-submenu ',
'{ ', 'left: ', $MenuWidth + 1, 'px; ', '}', PHP_EOL;
echo '#adminmenu li.wp-not-current-submenu .wp-menu-arrow ',
'{ ',
'-o-transform: translate(', $MenuWidth, 'px); ',
'-ms-transform: translate(', $MenuWidth, 'px); ',
'-webkit-transform: translate(', $MenuWidth, 'px); ',
'-moz-transform: translate(', $MenuWidth, 'px); ',
'transform: translate(', $MenuWidth, 'px); ',
'}', PHP_EOL;
echo '#wpcontent, #footer, #wpfooter ',
'{ ', 'margin-left: ', $MenuWidth + 20, 'px; ',
'}', PHP_EOL;
elseif(version_compare($wp_version, '3.8', '>=') and version_compare($wp_version, '3.9', '<')):
echo '#adminmenuback, #adminmenuwrap, #adminmenu, ',
'#adminmenu .wp-submenu, #adminmenu .wp-submenu-wrap,
.folded #adminmenu .wp-has-current-submenu .wp-submenu ',
'{ ', 'width: ', $MenuWidth, 'px; ', '}', PHP_EOL;
echo '#adminmenu li .wp-submenu, .folded #adminmenu .wp-has-current-submenu .wp-submenu ',
'{ ', 'left: ', $MenuWidth, 'px; ', '}', PHP_EOL;
echo '#adminmenu li.wp-not-current-submenu .wp-menu-arrow ',
'{ ',
'-o-transform: translate(', $MenuWidth, 'px); ',
'-ms-transform: translate(', $MenuWidth, 'px); ',
'-webkit-transform: translate(', $MenuWidth, 'px); ',
'-moz-transform: translate(', $MenuWidth, 'px); ',
'transform: translate(', $MenuWidth, 'px); ',
'}', PHP_EOL;
echo '#wpcontent, #footer, #wpfooter ',
'{ ', 'margin-left: ', $MenuWidth + 20, 'px; ',
'}', PHP_EOL;
endif;
echo '</style>', PHP_EOL;
}, 11); // action:admin_footer
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment