Skip to content

Instantly share code, notes, and snippets.

@reinnovating
Forked from franz-josef-kaiser/hide_admin_bar.php
Created November 16, 2017 20:27
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 reinnovating/312e545548a39a32ce61123b8978ed3e to your computer and use it in GitHub Desktop.
Save reinnovating/312e545548a39a32ce61123b8978ed3e to your computer and use it in GitHub Desktop.
Hide the admin bar with the click of a button in the WP admin UI
<?php
/**
* Plugin Name: "Hide Admin Bar"-Button
* Plugin URI: http://unserkaiser.com
* Description: Easier debugging when the error message is hidden behind the admin bar.
* Version: 0.1
* Author: Franz Josef Kaiser
* Author URI: http://unserkaiser.com
*/
// Prevent loading this file directly - Busted!
! defined( 'ABSPATH' ) AND exit;
/**
* Adds a button to the admin bar to allow collapsing the admin bar
* Else some error messages that are output in the html <head> can not be read
*
* @version 0.3
*
* @return void
*/
function oxo_admin_bar_extd()
{
global $wp_admin_bar;
if ( ! is_admin_bar_showing() )
return;
// YOU HAVE TO ADJUST THIS TO FIT YOUR THEME
$title = '<div style="cursor: pointer; margin-bottom: 0;">&DoubleLeftArrow;<div></div></div>';
is_admin() AND $title = '<div id="collapse-button" class="ab-icon" style="cursor: pointer; margin-bottom: 0;"><div></div></div>';
$wp_admin_bar->add_node( array(
'id' => 'collapse'
,'title' => $title
,'parent' => false
,'meta' => array(
'title' => 'collapse'
)
) );
// Add the scripts
add_action( 'admin_footer', 'oxo_admin_bar_extd_cb', 9999 );
}
add_action( 'admin_bar_menu', 'oxo_admin_bar_extd' );
/**
* Callback that builds the needed script for the admin bar button
*
* @since 0.3
*
* @return void
*/
function oxo_admin_bar_extd_cb()
{
?>
<script type="text/javascript">
jQuery( document ).ready( function($)
{
clicked = 0;
$( '#wp-admin-bar-collapse div' ).click( function()
{
if ( 0 == clicked ) {
clicked = 1;
$( '#wpadminbar' ).animate( { width: 35 }, 0 );
$( '#wpadminbar' ).css( 'min-width', 35 );
$( '#wp-admin-bar-root-default' ).children().not( '#wp-admin-bar-collapse' ).hide();
$( '#wp-admin-bar-top-secondary' ).hide();
} else {
clicked = 0;
$( '#wpadminbar' ).animate( { width: '100%' }, 0 );
$( '#wpadminbar' ).css( 'min-width', 600 );
$( '#wp-admin-bar-root-default' ).children().not( '#wp-admin-bar-collapse' ).show();
$( '#wp-admin-bar-top-secondary' ).show();
}
} );
} );
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment