Redirect to different page after switching

[ad_1]

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="https://projectdmc.org/support/topic/redirect-to-different-page-after-switching/<?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

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer