bp_get_add_switch_button( int $user_id, array $button_args = array() )

Returns a view as/back to button for a given user depending on the switching status.

Description

Checks to see if the admin user is already switched. If is switched, returns "Back to Admin" button; if not switched, returns "View As" button.

Parameters

$user_id

(Required) The user ID of the person we want to switch to.

$button_args

(Optional) See BP_Button class for more information.

Default value: array()

Return

(mixed) String of the button on success. Boolean false on failure.

Source

File: bp-members/bp-members-template.php

2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
function bp_get_add_switch_button( $user_id, $button_args = array() ) {
 
    if ( ! $user_id ) {
        return false;
    }
 
    $old_user = bp_current_member_switched();
 
    $button_args = wp_parse_args( $button_args, get_class_vars( 'BP_Button' ) );
 
    $user = get_userdata( $user_id );
    $link = BP_Core_Members_Switching::maybe_switch_url( $user );
 
    if ( ! $link ) {
        return;
    }
 
    $link = add_query_arg( array(
        'redirect_to' => urlencode( bp_core_get_user_domain( $user->ID ) ),
    ), $link );
 
    if ( $old_user && ( $old_user->ID === $user->ID || bp_is_my_profile() ) ) {
        $button = wp_parse_args(
            array(
                'id'                => 'member_switch',
                'component'         => 'members',
                'must_be_logged_in' => true,
                'block_self'        => false,
                'wrapper_class'     => 'switch-button back-to-admin',
                'wrapper_id'        => 'switch-button-' . $old_user->ID,
                'link_href'         => esc_url( $link ),
                'link_text'         => __( 'Back to Admin', 'buddyboss' ),
                'link_id'           => 'switch-' . $old_user->ID,
                'link_rel'          => 'stop',
                'link_class'        => 'switch-button back-to-admin stop bp-toggle-action-button outline',
            )
            , $button_args );
    } else {
        $button = wp_parse_args(
            array(
                'id'                => 'member_switch',
                'component'         => 'members',
                'must_be_logged_in' => true,
                'block_self'        => true,
                'wrapper_class'     => 'switch-button view-as',
                'wrapper_id'        => 'switch-button-' . $user_id,
                'link_href'         => esc_url( $link ),
                'link_text'         => __( 'View As', 'buddyboss' ),
                'link_id'           => 'switch-' . $user_id,
                'link_rel'          => 'start',
                'link_class'        => 'switch-button view-as start outline',
            )
            , $button_args );
    }
 
    /**
     * Filters the HTML for the follow button.
     *
     * @since BuddyBoss 1.0.0
     *
     * @param string $button HTML markup for follow button.
     */
    return bp_get_button( apply_filters( 'bp_get_add_switch_button', $button ) );
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.