0
votes

I have installed buddypress and now want that all users/members except admin should be redirected to groups page after login. I have written the code in a file mu-plugins/bp-custom.php

<?php add_filter("login_redirect", "bp_my_groups_redirect",10,3);
function bp_my_groups_redirect($redirect_to_calculated,$redirect_url_specified,$user) {
if(empty($redirect_to_calculated))
{
    $redirect_to_calculated=admin_url();
}
setcookie("bp-groups-scope", "personal");
/*if the user is not site admin,redirect to his/her groups*/
if (current_user_can('create_users'))
    return $redirect_to_calculated;
else
    return "/groups";   
}
?>

But, now all the members are getting redirected to groups page along with administrators. I want to redirect the administrators to wp dashboard. Please let me know the correct code.

1

1 Answers

0
votes

EDIT: Try this

<?php 
function my_groups_redirect() {

    if ( ! current_user_can( 'manage_options' ) ) {
        bp_core_redirect( home_url() . '/groups/' );
        exit;
    }
}
add_filter( 'login_redirect', 'my_groups_redirect');
?>

Note: I'm not sure what the URL of the groups page is. In my example above, non-admin users will be redirected to example.com/groups - feel free to change the redirect location to suit you.