WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16249 closed defect (bug) (worksforme)

Control of admin bar hiding/display

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

Download all attachments as: .zip

Change History (14)

comment:1 nacin3 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.

jtsternberg3 years ago

Admin bar space

comment:2 jtsternberg3 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>

comment:3 jtsternberg3 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');

comment:4 ocean903 years ago

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

It works for me.

comment:5 ocean903 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' ) );

comment:6 jtsternberg3 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?

comment:7 jtsternberg3 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);
    }
}

comment:8 ocean903 years ago

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

comment:9 jtsternberg3 years ago

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

jtsternberg3 years ago

checks for $show_admin_bar global

comment:10 jtsternberg3 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 3 years ago by jtsternberg (previous) (diff)

comment:11 jtsternberg3 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.

comment:12 DrewAPicture3 years ago

  • Cc xoodrew@… added

Removed comment: It was a theme-induced issue.

Version 1, edited 3 years ago by DrewAPicture (previous) (next) (diff)
Note: See TracTickets for help on using tickets.