Tuesday, May 17, 2011

Removing the toolbar of WordPress 3.1


Last month, Automattic has released another update to WordPress, where a major news is a bar that awful administration is floating on top of the screen. The appeal was imported WodPress.com and now comes automatically enabled in version 3.1 of the CMS.


Such a bar can even be useful for administrators, but the space it occupies on the screen does not justify the resources it offers to ordinary users. Some readers liked the TB until the appeal, but we thought it best to please remove the majority. Even as the little bar is a feature of WordPress and would not appear in the TB forum.

Disable a user
If you do not like sticking his hand in code, you can disable the bar in the WordPress admin interface. The downside is that this only hides the bar to your user, requiring that all registered users on his blog making the same setup in their profile (assuming that your blog readers to accept registration.)

The option appears on the tab of the profile editing (there where you change your name and everything, you know?). Check the print:


Disable for all users at once
This option requires you to put your hands dirty. But it is quite simple (even). All you need to do is open the functions.php of your theme and paste the following line:

add_filter ('show_admin_bar', '__return_false');

Enable only for Admin
You can use the above function so that it applies only to specific users. To do this simply create a condition using the function get_current_user_id () of WordPress. See example:

if (get_current_user_id ()! = 1) {
add_filter ('show_admin_bar', '__return_false');
}

In the first line of code above checked the ID and user access. Each registered user has a blog-specific ID, and the user ID admin is always the number 1 (the first registered user on the blog).

Thus, the above code does is check whether the user is loading pages is the admin. If not, the script applies the filter to remove the bar.

Again, just copy and paste the above code in functions.php.

Enable for all editors
With this function you can activate the bar for all the blog authors. The logic is the same code above, but this time we use a function that checks the user's permissions - current_user_can (). See how the code is:

if (! current_user_can ('publish_posts')) {
add_filter ('show_admin_bar', '__return_false');
}

In the above we checked if the user has permissions to publish posts. If he does not possess, apply the filter to remove the bar.

Conclusion
You can play with these functions in different ways - you can do magic things with the functions.php file. Anyway, these three options should suffice for most users.