user-switching.php
public function action_bp_button() {
		$user = null;

		if ( bp_is_user() ) {
			$user = get_userdata( bp_displayed_user_id() );
		} elseif ( bp_is_members_directory() ) {
			$user = get_userdata( bp_get_member_user_id() );
		}

		if ( ! $user ) {
			return;
		}

		$link = self::maybe_switch_url( $user );

		if ( ! $link ) {
			return;
		}

		$link = add_query_arg( array(
			'redirect_to' => urlencode( bp_core_get_user_domain( $user->ID ) ),
		), $link );

		$components = array_keys( buddypress()->active_components );

		echo bp_get_button( array(
			'id'         => 'user_switching',
			'component'  => reset( $components ),
			'link_href'  => esc_url( $link ),
			'link_text'  => esc_html__( 'Switch&nbsp;To', 'user-switching' ),
			'wrapper_id' => 'user_switching_switch_to',
		) );
	}
public function action_bp_button() {
		$user = null;

		if ( bp_is_user() ) {
			$user = get_userdata( bp_displayed_user_id() );
		} elseif ( bp_is_members_directory() ) {
			$user = get_userdata( bp_get_member_user_id() );
		}

		if ( ! $user ) {
			return;
		}

		$link = self::maybe_switch_url( $user );

		if ( ! $link ) {
			return;
		}

		$link = add_query_arg( array(
			'redirect_to' => urlencode( bp_core_get_user_domain( $user->ID ) ),
		), $link );

		$components = array_keys( buddypress()->active_components );

		echo bp_get_button( array(
			'id'         => 'user_switching',
			'component'  => reset( $components ),
			'link_href'  => esc_url( $link ),
			'link_text'  => esc_html__( 'Switch&nbsp;To', 'user-switching' ),
			'wrapper_id' => 'user_switching_switch_to',
		) );
	}
public function action_bp_button ( ) { $ user = null ; if ( bp_is_user ( ) ) { $ user = get_userdata ( bp_displayed_user_id ( ) ) ; } elseif ( bp_is_members_directory ( ) ) { $ user = get_userdata ( bp_get_member_user_id ( ) ) ; } if ( ! $ user ) { return ; } $ link = self :: maybe_switch_url ( $ user ) ; if ( ! $ link ) { return ; } $ link = add_query_arg ( array ( 'redirect_to' => urlencode ( bp_core_get_user_domain ( $ user -> ID ) ) , ) , $ link ) ; $ components = array_keys ( buddypress ( ) -> active_components ) ; echo bp_get_button ( array ( 'id' => 'user_switching' , 'component' => reset ( $ components ) , 'link_href' => esc_url ( $ link ) , 'link_text' => esc_html__ ( 'Switch&nbsp;To' , 'user-switching' ) , 'wrapper_id' => 'user_switching_switch_to' , ) ) ; }
Adds a 'Switch To' link to each member's profile page and profile listings in BuddyPress.
Adds a Switch To link to each member s profile page and profile listings in BuddyPress .