Hi there, I have a general WP login issue, which I hope you can help me with.
I’m using this code snippet below, to disable WP dashboard, for other users than admins.
Anyway, sometimes users without admin status, are able to log into their dashboard. This happens after a second login attempt with this cookie warning:
Error: Cookies are blocked or do not understand by your browser. You must enable cookies
to using WordPress.https://imgur.com/gTqUE0f
https://imgur.com/m9kAV6xHere’s the code snippet I have added to avoid dashboard access for others than admins:
//Disable Admin Bar for All Users Except for Administrators add_action( 'after_setup_theme', 'remove_admin_bar' ); function remove_admin_bar() { if ( ! current_user_can( 'administrator' ) && ! is_admin() ) { show_admin_bar( false ); } }
https://stackoverflow.com/questions/8194649/disable-the-admin-bar-for-all-users-except-admin
How can this happen anyway?
Thanks!
Regards
CarstenHello Carsten,
Please try the following code. If you want to hide admin bar from non administrator and do not want to give access them to dashboard.
// To hide admin bar to non administrator. add_action('after_setup_theme', function(){ if ( is_super_admin() ) { return; } show_admin_bar( false ); if ( is_admin() && ! wp_doing_ajax() ) { wp_safe_redirect( home_url() ); exit; } });
Please do let me know if it works or not.
Regards
Ravi- This reply was modified 4 years, 4 months ago by Ravi.
Hi Carsten,
Ravi is away, so I am updating the code.Please use this snippet
// To hide admin bar to non administrator. add_action( 'init', function () { if ( is_super_admin() ) { return; } show_admin_bar( false ); if ( is_admin() && ! wp_doing_ajax() ) { wp_safe_redirect( home_url( '/' ) ); exit; } } );
Does it work fro you?
Hi,
Avoid using ‘after_setup_theme’. The current user is not set at this hook, so it should not be used.Regards
Brajesh
You must be logged in to reply to this topic.