You are given the option to show/hide the admin bar when viewing the site, but there is no option to show/hide the admin bar when using the backend... So I created a plugin to provide that option on profile pages.
Why hide the admin bar in backend?
Normally I like the admin-bar and usually have it enabled, but it's nice to be able to switch it on/off from the "Edit Profile" page. The biggest reason for not loading/showing the admin_bar in the backend is SPEED. Here are 2 instances where I hide it-
· Sites with many authors/admins
· Moderating Comments on a Mobile Phone
I occasionally enjoy moderating blog comments using my Android mobile phone and a browser like Opera or Dolphin.... hiding the admin_bar improves Load Speed, Page Rendering Speed, and Scroll Speed. Basically everything.
The wp-admin-bar causes additional CSS, JavaScript, and HTML to be added to every page, increasing request size and time of every request! The jQuery used for the admin_bar keeps it floating at the top using javascript, meaning it gets executed on resize/scroll/load - MAJOR PAIN!
This plugin provides the option of hiding the admin bar when in_admin. It not only hides the admin_bar, it actually prevents the admin_bar class from even loading, at least in WP version 3.4-beta2-20509 thanks to the wp_admin_bar_class
filter.
Follow the Installation steps below and/or read on to see how it works.. it's an incredibly simple plugin and easy to extend for other purposes.
/wp-content/plugins/askapache-adminbar-prefs/askapache-adminbar-prefs.php
function askapache_adminbar_personal_options( $profileuser ) { global $wpdb, $wp_query; $show_admin_bar_backend=_get_admin_bar_pref( 'backend', $profileuser->ID ); ?>Toolbar2 Save preference when a profile updated
function askapache_adminbar_handle_post($useridtoedit) { global $wpdb, $wp_query, $current_user; $show_admin_bar_backend=_get_admin_bar_pref( 'backend', $useridtoedit ); $userID=(int)$useridtoedit; if ( !current_user_can('edit_user', $userID) ) wp_die(__('You do not have permission to edit this user.')); $show_admin_bar_backend=(isset( $_POST['admin_bar_backend'] ) ? 'true' : 'false'); update_user_option($userID, "show_admin_bar_backend", $show_admin_bar_backend); } add_action( 'personal_options_update', 'askapache_adminbar_handle_post', 10, 1); add_action( 'edit_user_profile_update', 'askapache_adminbar_handle_post', 10, 1);Remove admin_bar from backend
Now we need to hook into
init
to either show/hide the admin_bar while in the backend (in_admin()
) based on the users preference.
- Fetches the users preference for showing the admin_bar in the backend
- Removes the wp_admin_bar class from even loading (
wp_admin_bar_class
filter)- Returns false to the
show_admin_bar
filter- Overrules the
admin-bar
css applied to the bodyfunction askapache_adminbar_personal_options_init() { global $wpdb, $wp_query, $current_user; $show_admin_bar_backend=_get_admin_bar_pref( 'backend', $current_user->ID ); if(!$show_admin_bar_backend && is_admin()) { add_filter('wp_admin_bar_class', create_function('', 'return "none".rand(1000,666666);'), 9999999); add_filter('show_admin_bar', create_function('', 'return false;'), 999999); add_action('admin_head', create_function('', 'echo '';')); } } add_action( 'init', 'askapache_adminbar_personal_options_init',0);Add to Core WordPress
I'm sure this will be added to the dev version of WordPress by someone (volunteers?) and eventually integrated into stable. Note this was built and used on WordPress 3.4-beta2-20509.
Show or Hide WordPress Admin Bar Plugin - AskApache