Opened 2 years ago

Closed 17 months ago

Last modified 17 months ago

#16249 closed defect (bug) (worksforme)

Control of admin bar hiding/display

Reported by: johnhennmacc Owned by:
Priority: normal Milestone:
Component: Administration Version: 3.1
Severity: normal Keywords: needs-patch
Cc: justin@…, xoodrew@…

Description

Can the assignment of space for an admin bar be controlled by the same switch that turns it on and off? At the moment, you can make the bar not appear but space still is set aside for it after ticket #16222. You need to remove the space as well as hiding the bar.

Attachments (2)

Screen shot 2011-12-20 at 10.00.46 AM.JPG (72.8 KB) - added by jtsternberg 17 months ago.
Admin bar space
16249.diff (1012 bytes) - added by jtsternberg 17 months ago.
checks for $show_admin_bar global

Download all attachments as: .zip

Change History (14)

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

You're not disabling it properly. Use the following function or hook:

show_admin_bar( false );

Or:

add_filter( 'show_admin_bar', '__return_false' );

Additionally, you can change the callback that spits out the CSS, thus allowing you to adjust it for your theme if for some reason it isn't compatible.

Admin bar space

  • Cc justin@… added
  • Keywords needs-patch added
  • Resolution worksforme deleted
  • Status changed from closed to reopened

The screenshot displays this error still happening, using both filter's Nacin put above. The code in the head is not being removed:

<style type="text/css" media="screen">
	html { margin-top: 28px !important; }
	* html body { margin-top: 28px !important; }
</style>

adding this snippet will take care of it, but not sure that should be necessary.

        show_admin_bar(false);
        remove_action('wp_head', '_admin_bar_bump_cb');

Seems like it's too late when you call add_filter( 'show_admin_bar', '__return_false' );.

It works for me.

  • Resolution set to worksforme
  • Status changed from reopened to closed
function ds_hide_toolbar() {
	add_filter( 'show_admin_bar', '__return_false' );
}

add_action( 'init', 'ds_hide_toolbar', 1 );

or

add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );

Thank you for your response.. The only thing missing in my code was the "1" at the end of the add_action. With the diff that I just added, that "1" doesn't seem to be needed. Please take a look and consider it?

And to be as clear as possible, this was my code that was not properly removing the space at the top of the page for the admin bar:

// Hide dashboard, admin bar, etc from subscribers
add_action( 'init', 'aec_hide_admin_stuff' );
function aec_hide_admin_stuff(  ) {
    if ( !current_user_can('edit_posts') ) {
        show_admin_bar(false);
    }
}

Btw: If the CSS is printed the JS files will be enqueued too, so your patch doesn't help.

Good point. I'll see if I can upload a more thorough patch. Thank you.

checks for $show_admin_bar global

  • Keywords has-patch added

Ok, I scoured the source code of my page after applying this patch to be sure it was removing everything that

function ds_hide_toolbar() {
	add_filter( 'show_admin_bar', '__return_false' );
}

add_action( 'init', 'ds_hide_toolbar', 1 );

was removing, so hopefully this patch is considered for addition?

Last edited 17 months ago by jtsternberg (previous) (diff)
  • Keywords has-patch removed

Bah, sorry, that diff works too well... the $show_admin_bar global is not set yet, so it removes it from the front-end permanently whether you specify that option or not. I'll have to give it some thought, or just drop it.

  • Cc xoodrew@… added

Removed comment: It was a theme-induced issue.

Last edited 17 months ago by DrewAPicture (previous) (diff)
Note: See TracTickets for help on using tickets.