How to disable admin bar in wordpress 3.9? - wordpress

I'm trying to disable admin bar for registered users, whiche are not administrators. I found many solutions like adding
if ( ! current_user_can( 'add_users' ) ) {
show_admin_bar( false ); }
to functions.php, but it totally doesn't work. As I understand it is problem of "the best" version 3.9. I also tried many plugins - there are no working ones... Does any solution exist today?

Have you tried using the filter? Add this to your functions.php replacing your existing code:
function wpse_hide_admin_bar() {
if ( current_user_can( 'manage_settings' ) ) {
return true; // Show for admins
} else {
return false; // Hide for other users
}
}
add_filter( 'show_admin_bar', 'wpse_hide_admin_bar' );

including this line of code in functions.php will disable it altogether,
add_filter( 'show_admin_bar', '__return_false');
Edit: The accepted answer is better than my answer, because that method doesn't disable the admin bar altogether, but it disables it based on the user permissions.

Go to Users > Admin Profile > Toolbar > Deselect "Show Toolbar when viewing site"

Related

Remove WordPress admin bar on a single page

Is there a way to remove the WordPress admin bar but just on a specific page?
I know that I can remove it or hide it completely by adding an action:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
I've done that but on my site I have one page that is displayed in an iframe (using colorbox) and I don't ever want the admin bar to show up in that iframe.
Is there a way to hide the admin bar but just for a specific page?
Thanks,
Ben
Your function is a bit complicated, there's a filter for that. Just check for the Page ID and filter it out using the show_admin_bar filter.
function riga_hide_admin_bar(){
if( $post->ID == YOUR_POST_ID ){
return false;
}
}
add_filter( 'show_admin_bar' , 'riga_hide_admin_bar' );
Remove WordPress admin bar on a single page
Yes, you can remove admin bar from a specific page as you wish.
Use add_filter( 'show_admin_bar', '__return_false' ); to hide admin bar from a specific page.
function my_function_admin_bar(){
return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
For more details please see below link:
https://codex.wordpress.org/Plugin_API/Filter_Reference/show_admin_bar
Get ID of specific page and add your filter in condition which meet the page ID
`If(get_the_ID()==#736637){
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
}`
For me the easiest way is to add the code in the template of the page I don't want to show. At the top of the template file I just add:
<?php
show_admin_bar(false);

Change menu if user is connected - WordPress

I'm working with WordPress.
I have two different menu.
If the user log in, the menu change.
So the first one is just for users that aren't connected.
Do you know a solution to do that ?
Have I to change some PHP files ?
EDIT
QUESTION
On my website I have a Back-Office. On the BO there is menu-2.
How could I put menu-2 only on the Back-Office ? And have the other menu (menu-1) on the original website ?
You need function is_user_logged_in() .
Shortest path to solve your problem is creating two different menus, one for logged in users and another for "guests".
Go to Appearance » Menus, create two menus logged-in and logged-out.
After creating the menus, add this code in your theme’s functions.php file or a site-specific plugin:
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged-in';
} else {
$args['menu'] = 'logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
Reference:
1.https://developer.wordpress.org/reference/functions/is_user_logged_in/

Wordpress 4.3 hide admin bar for non administrators

After updating to Wordpress 4.3 users can see the admin bar. I use this code to hide it normally, but this is not working anymore in 4.3.
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Any ideas?
The function current_user_can refers to capabilities or user role names. So try manage_options instead:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
// 'manage_options' is a capability assigned only to administrators
if (!current_user_can('manage_options') && !is_admin()) {
show_admin_bar(false);
}
}
Instead of using the after_setup_theme action you can also add a filter (prefered for newer WP versions):
add_filter( 'show_admin_bar' , 'handle_admin_bar');
function handle_admin_bar($content) {
// 'manage_options' is a capability assigned only to administrators
// here, the check for the admin dashboard is not necessary
if (!current_user_can('manage_options')) {
return false;
}
}
Here is a 6 lines code nugget that will remove the admin bar for non contributor users :
add_action( 'init', 'fb_remove_admin_bar', 0 );
function fb_remove_admin_bar() {
if (!current_user_can('edit_posts')) { // you can change the test here depending on what you want
add_filter( 'show_admin_bar', '__return_false', PHP_INT_MAX );
}
}
Put that in your function.php file or in your custom plugin.
Thanx all for helping. Eventually the problem was a maintenance plugin. When i disabled this it was working again.
Place the code in your theme's functions.php file
if (!current_user_can('manage_options')) {
add_filter('show_admin_bar', '__return_false');
}
Disable the WordPress Admin Bar Using CSS
You only have to copy and paste the CSS code below in Appearance > Customize > Additional CSS, or your style.css file.
The CSS code to disable the toolbar is:
#wpadminbar { display:none !important;}

Hide WordPress admin panel option

How I can hide WordPress admin panel options for all except one user. I want to hide some setting options and theme options for all users except me (username: jacob).
This code will hide admin bar for all users:
show_admin_bar( false );
And this one will prevent admin bar from being hidden:
show_admin_bar( false );
So you need to use code for the condition if the username is jacob then show the admin bar and hide it for all the others. So here is the complete code.
global $current_user;
get_currentuserinfo();
if ( is_user_logged_in() ) {
if($current_user->user_login == 'jacob') {
show_admin_bar( true );
} else {
show_admin_bar( false );
} } else {
show_admin_bar( false );
}
You can use this code inside your theme's functions.php or you can also create separate plugin for this.
Admin Bar Disabler plug-in can hide admin panel for users with roles. I expect you are administrator and rest of users are not (since they shouldn't see the panel), so you can let show Wordpress panel for admin role only. ;)
https://wordpress.org/plugins/admin-bar-disabler/
If you have users that are logging in, you can re-direct around the Admin - check perms..
Better yet, send them around it!!
Have a look here - https://wordpress.org/plugins/peters-login-redirect/
I use this on our church website and works great!
Thanks!
Add below code into your theme functions.php
global $current_user; get_currentuserinfo(); if ( is_user_logged_in() ) {
if($current_user->user_login == 'jacob') {
show_admin_bar( true );
} else {
show_admin_bar( false );
} } else { }
Hope this will help you

Restricting Wordpress Admin Options to Admins

I thought this would be an easy thing but many hours have gone by and still no results.
I am creating a Wordpress plug-in that should only appear in the dashboard if the user is an admin. I wrapped my hooks in the is_admin() method, but when I log in as a user who is just a subscriber, I still see the menu.
Isn't it just that easy???
Here's a code except starting right below the comment section to register the plugin... everything not shown is just functions doing their job ...
if( is_admin ){
add_action('admin_menu', 'ppm_talentexpo_add_page');
add_action('admin_menu', 'ppm_expos_submenu');
} // end is_admin
function ppm_talentexpo_add_page() {
$mypage = add_menu_page('Talent Expo', 'Talent Expos', 2, 'ppmtalentexpo', 'jwg_talentexpo_options_main_page', '/wp-admin/images/media-button-music.gif' , 21);
add_action( "admin_print_scripts-$mypage", 'jwg_ppmtalentexpo_admin_head' );
} // end function
It looks like you left out the parentheses when calling is_admin in the conditional.
Try
if( is_admin() ){
add_action('admin_menu', 'ppm_talentexpo_add_page');
add_action('admin_menu', 'ppm_expos_submenu');
}
Also if you're not using an older WordPress install, add_menu_page allows you to specify a capability that WordPress will check for. This lets WordPress manage showing the item or not.
So you can define a custom capabilty (or reuse an existing one), and the menu should take care of itself.
add_action('admin_menu', 'ppm_talentexpo_add_page');
add_action('admin_menu', 'ppm_expos_submenu');
function ppm_talentexpo_add_page() {
$mypage = add_menu_page('Talent Expo', 'Talent Expos', 'my_custom_talent_expos_capability', 'ppmtalentexpo', 'jwg_talentexpo_options_main_page', '/wp-admin/images/media-button-music.gif' , 21);
add_action( "admin_print_scripts-$mypage", 'jwg_ppmtalentexpo_admin_head' );
}

Resources