1

I'm working on a theme for the back end Admin pages, this is for a custom web application built on WP.

After studying admin-bar.php and the function is_admin_bar_showing() for a few minutes I decided to do this:

function kill_admin_toolbar() {
    add_filter( 'xmlrpc_enabled', '__return_false' );
    define( 'XMLRPC_REQUEST', false );
}
add_action( 'admin_init', 'kill_admin_toolbar' );

I never plan on using XML-RPC with this application.

With this code there is no more 32px strip of immovable toolbar at the top of my admin screen.

I can't see any weird side effects so far; what do you guys think?

It's either this or I modify admin-bar.php and insert return false; right after the function definition for is_admin_bar_showing(). The idea of touching even one core file really bothers me, though.

Really maddening there is no hook early enough in that function to do this.

  • I haven't looked into this properly yet, but would CSS be suitable for you? It'll at least have no unknown side effects :) – Tim Malone Jul 6 '16 at 21:07
  • thanks...yeah I played around with css, looked at several examples of how other people were tackling this -- nothing was really great. I could also easily load some JS that removes the entire element from the DOM, but I really wanted to find something in PHP that worked. I kind of like my solution - if it doesn't cause any other problems ;-) – C C Jul 6 '16 at 23:54
1

While what you used appears to work for now, I couldn't guarantee it isn't going to cause other issues now or in the future because - as you already know - tricking is_admin_bar_showing() isn't what the check of the XMLRPC_REQUEST constant was designed for. Therefore even if it doesn't cause issues now I don't think it would future-proof to use it like this.

However, I continued your hunt and I think I've found the filter you need: wp_admin_bar_class.

Returning false to this filter - or returning any string that doesn't match the name of a defined class - will cause _wp_admin_bar_init() to short-circuit and thus never initialize the bar in the first place:

add_filter( 'wp_admin_bar_class', '__return_false' );

This works, but is unfortunately giving me a nice blank gap where the admin bar used to be, because of the wp-toolbar CSS class being present on the dashboard's <html> tag. This is added in wp-admin/includes/template.php and I can't immediately see a way to remove it in the PHP. So, you'd probably need to override this padding with custom CSS (sorry, maybe a PHP-only solution isn't possible after all!):

add_action( 'admin_head', function(){
  ?><style> html.wp-toolbar { padding-top: 0; } </style><?php
});

There may be other slight hiccups as a result of removing the admin bar like this, given that is_admin_bar_showing() still technically returns true, but I think they would be fairly minor, and if you find any, it probably wouldn't be too difficult to find a workaround.

To be sure (for now at least), you could hunt through the source for any usages of the function. As of 4.5.3, usage appears to be limited to four files: admin-header.php, template.php, admin-bar.php, and post-template.php, and from a cursory glance it appears you might want to filter admin_body_class to remove 'admin-bar' from there too, just in case (it's not making a visible difference for me though).

See also the 'no-customize-support' class - I don't think this will affect you, because it appears to be designed only for 'hide-if-no-customize' menu options in the toolbar... which of course you're not displaying anyway!

  • thanks Tim, I will try this out tonight. Pretty sure I did try inoculating wp_admin_bar_class -- but will look at it again. I'd love it if whoever actually gets to do dev on core would add a hook to is_admin_bar_showing(), earlier in the function. Seems like a zero-risk thing to do... – C C Jul 7 '16 at 12:35
  • @CC You can log a trac ticket for that if you like :) – Tim Malone Jul 7 '16 at 20:39
  • heh - ok thanks; I've never even looked into that before so might be an interesting learning experience! – C C Jul 7 '16 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.