Make WordPress Core

Opened 8 years ago

Last modified 3 months ago

#28569 reviewing enhancement

Calling show_admin_bar( false ) should dehook toolbar entirely

Reported by: danielbachhuber Owned by: davidbaumwald
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Toolbar Keywords: has-patch needs-refresh needs-unit-tests
Focuses: Cc:

Description

Because I'm only hiding the toolbar in certain contexts, I'm calling show_admin_bar( false ) right before get_header(). #16249 was closed suggesting the function should only be called on init. #21746 suggests calling after plugins_loaded However, I think calling it after the query is set and the template is picked is a valid use case.

As such, I'd propose calling show_admin_bar( false ) should run remove_action('wp_head', '_admin_bar_bump_cb'); and similar setup callbacks.

Attachments (2)

28569.patch (428 bytes) - added by paulschreiber 7 years ago.
28569.1.diff (440 bytes) - added by audrasjb 4 months ago.
Toolbar: unhook the admin bar when a falsey value is used on show_admin_bar()

Download all attachments as: .zip

Change History (17)

#1 @paulschreiber
7 years ago

What other callbacks count as "and similar setup callbacks"?

@paulschreiber
7 years ago

#2 @helen
7 years ago

  • Keywords has-patch added; needs-patch removed

#3 @DrewAPicture
7 years ago

  • Owner set to paulschreiber
  • Status changed from new to assigned

#4 @chriscct7
6 years ago

  • Owner changed from paulschreiber to chriscct7
  • Status changed from assigned to reviewing

This ticket was mentioned in Slack in #core by sabernhardt. View the logs.


10 months ago

#6 @sabernhardt
10 months ago

  • Milestone set to 5.8
  • Owner changed from chriscct7 to davidbaumwald

The patch still applies, though it could use a Yoda condition on the check.

Also, it would help if someone with deeper knowledge of the admin bar (and/or themes) agrees this is the correct way to do this. I have used the show_admin_bar filter before, and returning false with that removes the style tag. But I have not used show_admin_bar( false ) to know how that works.

Last edited 10 months ago by sabernhardt (previous) (diff)

This ticket was mentioned in Slack in #core by sabernhardt. View the logs.


8 months ago

#8 @sabernhardt
8 months ago

  • Keywords needs-refresh added; good-first-bug removed
  • Milestone changed from 5.8 to Future Release

It's a bit late for 5.8. Moving to future release.

#9 @audrasjb
4 months ago

  • Keywords commit added; needs-refresh removed
  • Milestone changed from Future Release to 5.9

Patch refreshed against trunk.
I tested the patch and I can confirm it unhook entirely the admin bar and its assets.

Adding commit keyword and moving to milestone 5.9.

@audrasjb
4 months ago

Toolbar: unhook the admin bar when a falsey value is used on show_admin_bar()

#10 @peterwilsoncc
3 months ago

  • Keywords needs-refresh added; commit removed

Removing the commit keyword as it needs a little extra work:

  • admin-bar.css is still enqueued in the header
  • admin-bar.js is still enqueued in the footer
  • <style media="print">#wpadminbar { display:none; }</style> is still output in the header (harmless but not ideal)
  • it's possible for themes & plugins to set a custom callback add_theme_support( 'admin-bar', array( 'callback' => '28569_admin_bar_cb' ) );

Testing notes: added show_admin_bar( false ); to my theme's header.php prior to the wp_head() function call.

I'll reach out to a Jetpack team member to ensure they're aware of this change coming so they can check for compatibility with the WordPress.com bar. I'd rather not surprise them and break 5 million sites.

#11 @obenland
3 months ago

Let's also make sure that it works as expected when set to true again after.

<?php
show_admin_bar( false );
$this->assertFalse( has_action( 'wp_head', '_admin_bar_bump_cb' ) );

show_admin_bar( true );
$this->assertEquals( 10, has_action( 'wp_head', '_admin_bar_bump_cb' ) );

#12 @obenland
3 months ago

Looking at this a little bit more, the toolbar can also be toggled on/off through the show_admin_bar filter, which has no connection to the function.

This ticket was mentioned in Slack in #core by chaion07. View the logs.


3 months ago

#14 @chaion07
3 months ago

  • Keywords needs-unit-tests added

Hi @afercia! Thank you for reporting this. This ticket was discussed during a recent Bug-scrub session. Based on the feedback received we're updating the ticket. It would be great to have a patch too. Thanks!

Props to @audrasjb & @costdev

#15 @sabernhardt
3 months ago

  • Milestone changed from 5.9 to Future Release

Moving to Future Release until the patch is refreshed, with unit tests.

Note: See TracTickets for help on using tickets.