• I have a wordpress / buddypress multi-site and use the BP Profile as Homepage plugin to redirect users to their profile upon login. I see in the documentation a way to redirect users to a URL and wonder if there’s a way to ensure users are directed to the same location upon login? If not is there a known buddypress profile URL I can use?

    Any responses appreciated.

    https://www.ads-software.com/plugins/wordpress-social-login/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m trying the same thing.

    WSL has a filter called “wsl_hook_process_login_alter_redirect_to”.

    my attempt bellow in my-theme/functions.php:

    function wsl_redirect_to( $redirect_to, $user_id )
    {
        $user = get_userdata($user_id);
    
        if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
            if( $user->has_cap( 'administrator' ) ) {
                $redirect_to = admin_url();
            } else {
                $redirect_to = home_url('/members/'. $user->user_nicename );
            }
        }
        return $redirect_to;
    }
    add_filter( 'wsl_hook_process_login_alter_redirect_to', 'wsl_redirect_to', 10, 2 );

    But when this filter is triggered, the user not yet was created by the WSL.
    I’m find a way for this works.

    (P.S.: Sorry my english)

    My dirty solution, but i don’t see another alternative, furthermore the filter to redirect is inaccessible after user authentication.

    /**
     * WordPress function for redirecting users on login based on user role
     */
    function wsl_after_user_registration( $user_id, $provider, $hybridauth_user_profile, $redirect_to )
    {
        $user = get_userdata($user_id);
    
        if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
            if( $user->has_cap( 'administrator' ) ) {
                $redirect_to = admin_url();
            } else {
                $redirect_to = home_url('/members/'. $user->user_nicename);
            }
        }
    
        add_action( 'wsl_clear_user_php_session' );
        wp_safe_redirect( $redirect_to );
        die();
    }
    add_action('wsl_hook_process_login_before_wp_safe_redirect', 'wsl_after_user_registration', 10, 5 );

    Inspiration here:
    https://www.ads-software.com/support/topic/new-user-redirect?replies=10

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect options’ is closed to new replies.