Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#16249 closed defect (bug) (worksforme)

Control of admin bar hiding/display

Reported by: johnhennmacc's profile johnhennmacc Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Administration Keywords: needs-patch
Focuses: Cc:

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 12 years ago.
Admin bar space
16249.diff (1012 bytes) - added by jtsternberg 12 years ago.
checks for $show_admin_bar global

Download all attachments as: .zip

Change History (14)

#1 @nacin
13 years ago

  • 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.

#2 @jtsternberg
12 years ago

  • 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>

#3 @jtsternberg
12 years ago

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');

#4 @ocean90
12 years ago

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

It works for me.

#5 @ocean90
12 years ago

  • 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' ) );

#6 @jtsternberg
12 years ago

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?

#7 @jtsternberg
12 years ago

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);
    }
}

#8 @ocean90
12 years ago

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

#9 @jtsternberg
12 years ago

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

@jtsternberg
12 years ago

checks for $show_admin_bar global

#10 @jtsternberg
12 years ago

  • 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 12 years ago by jtsternberg (previous) (diff)

#11 @jtsternberg
12 years ago

  • 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.

#12 @DrewAPicture
12 years ago

  • Cc xoodrew@… added

Removed comment: It was a theme-induced issue.

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