• Resolved nella1980

    (@nella1980)


    Hi there,

    I’m using buddyboss which has the member switching plugin worked into it. So I’m trying to redirect to a user’s friends section (/friends) on their profile instead of their main profile page by creating a function that goes into functions.php file. After reading through several topics I’ve ended up with this code snippet but it doesn’t change the switch to destination. Could you please help me achieve this or guide in the right direction… please?

    
    function modify_bbpress_button_link() {
    $user = get_userdata( bbp_get_user_id() );
    if ( ! $user ) {
        return;
    }
    
    $link = self::maybe_switch_url( $user );
    
    if ( ! $link ) {
        return;
    }
    
    $link .= 'friends/';
    
    $link = add_query_arg( array(
        'redirect_to' => urlencode( bbp_get_user_profile_url( $user->ID ) ),
    ), $link );
    
    ?>
    <ul id="bp_member_switching_switch_to">
        <li><a href="<?php echo esc_url( $link ); ?>"><?php esc_html_e( 'Switch&nbsp;To', 'buddyboss' ); ?></a></li>
    </ul>
    <?php
    }
    
    add_action('switch_to_user', 'modify_bbpress_button_link');

    Best regards,

    Nella

Viewing 1 replies (of 1 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    If you want to add a specific button for this, you’ll be best off asking the folks at BuddyBoss because they’ll know more about the specifics.

    You can also try using the login_redirect filter which is called when a user manually logs in and when a user switches between users. You can add some conditional logic to the callback for that filter to redirect them to the friends page when necessary, but you’ll need to be familiar with PHP and clear about the logic required.

Viewing 1 replies (of 1 total)
  • The topic ‘Redirect to different page after switching’ is closed to new replies.