This won’t check for ‘normal’ admins unless network mode is disabled.
Try if ( ! current_user_can( 'manage_options' ) ) {
Hi @henrywright,
Thanks for reply. Switched the super_admin for your suggestion and no difference unfortunately.
Try putting return $redirect_to;
after your condition. It’s currently wrapped inside it.
p.s. the site im working on (offline), isn’t part of a multisite setup. Network mode should be off by default right (and therefore the !is_super_admin()
should do the same job as !is_admin()
)?
Just to note, is_admin() checks if the dashboard is being viewed, not the user’s capabilities.
https://codex.wordpress.org/Function_Reference/is_admin
Ahh that’s interesting. Read the is_super_admin()
function codex page and assumed from what it said that is_admin()
did essentially the same thing.
Anyway tried your suggestion of moving return $redirect_to
out of the braces but nothing changed. Also removed the braces altogether (as below) and no change. (Tried with the super_admin() in there too.)
//Redirect all users except admin to Activity page when login button pressed
function bpmc_redirect_login( $redirect_to, $set_for, $user ) {
if( ! current_user_can('manage_options') )
$redirect_to = bp_core_get_user_domain($user->id) . 'activity/';
return $redirect_to;
}
add_filter('login_redirect', 'bpmc_redirect_login', 11, 3);
The code should work now. I can’t see anything wrong with it. Are you sure the user account you’re logging in with has admin capabilities?
I’ve set up two users to test various things on site during development, one with Administrator and one with Subscriber roles. That’s what the wp dash is confirming under users.
I also have another function to hide the wp admin bar at the top of the page which includes the is_super_admin(). When its active, the admin bar is removed for the subscriber but not the admin user as intended. So can only assume that there is a problem with my redirect function itself or perhaps its clashing with something else (though I have no other plugins atm).
//Remove wordpress admin bar for all except admin
function bpmc_remove_admin_bar() {
if( !is_super_admin() )
add_filter( 'show_admin_bar', '__return_false' );
}
add_action('wp', 'bpmc_remove_admin_bar');
Try if ( !is_super_admin( $current_user_id))
Or use the WP filter
function hide_my_admin_bar() {
// by user role
if ( current_user_can( 'manage_settings' ) ) {
return true; // Show for admins
} else {
return false; // Hide for other users
}
}
add_filter( 'show_admin_bar', 'hide_my_admin_bar' );
Hi @danbp,
My code for hiding the admin bar already works, but thanks anyway. I was just giving Henry an example of another function where the is_super_admin()
was working. It was the earlier function in this thread (re. login redirect) where it wasn’t having an effect and all users were being directed to the link, without excluding the admin user.
Cheers
@mcuk there must be something conflicting. Try raising the priority from 11 to 999 temporarily just in case you have anything else hooked to login_redirect
@henrywright. I raised the priority to 999 and went one step further by creating a new bp_functions php to put it in by itself (and put the original in another location). Didn’t make any difference. All users still directed to the stated page.
Anyway don’t waste your time on it, I appreciate the input. It’s not a huge deal. Was just a little confused as I haven’t seen anyone else on the forums have the same issue, which suggests that if the code is correct then there’s something else going on locally within my setup. Might reveal itself in time!