plugin development - Turn off Admin Bar (Toolbar) in backend - no easy way

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

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

Share Improve this question edited Jul 6, 2016 at 19:56 C C asked Jul 6, 2016 at 19:41 C CC C 1,95818 silver badges31 bronze badges 2
  • 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 Commented Jul 6, 2016 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 Commented Jul 6, 2016 at 23:54
Add a comment  | 

1 Answer 1

Reset to default 2

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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744899246a4599878.html

相关推荐

  • plugin development - Turn off Admin Bar (Toolbar) in backend - no easy way

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

    1天前
    90

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信