BP_Core_Members_Switching::maybe_switch_url( WP_User $user )

Returns the switch to or switch back URL for a given user.

Description

Parameters

$user

(WP_User) (Required) The user to be switched to.

Return

(string|false) The required URL, or false if there's no old user or the user doesn't have the required capability.

Source

File: bp-members/classes/class-bp-core-members-switching.php

	public static function maybe_switch_url( WP_User $user ) {
		$old_user = self::get_old_user();

		if ( $old_user && ( $old_user->ID === $user->ID || bp_is_my_profile() ) ) {
			return self::switch_back_url( $old_user );
		} elseif ( current_user_can( 'switch_to_user', $user->ID ) || user_can( $old_user, 'switch_to_user', $user->ID ) ) {
			return self::switch_to_url( $user );
		} else {
			return false;
		}
	}

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.