user-switching.php
public function filter_user_has_cap( array $user_caps, array $required_caps, array $args, WP_User $user ) {
		if ( 'switch_to_user' === $args[0] ) {
			if ( array_key_exists( 'switch_users', $user_caps ) ) {
				$user_caps['switch_to_user'] = $user_caps['switch_users'];
				return $user_caps;
			}

			$user_caps['switch_to_user'] = ( user_can( $user->ID, 'edit_user', $args[2] ) && ( $args[2] !== $user->ID ) );
		} elseif ( 'switch_off' === $args[0] ) {
			if ( array_key_exists( 'switch_users', $user_caps ) ) {
				$user_caps['switch_off'] = $user_caps['switch_users'];
				return $user_caps;
			}

			$user_caps['switch_off'] = user_can( $user->ID, 'edit_users' );
		}

		return $user_caps;
	}
public function filter_user_has_cap( array $user_caps, array $required_caps, array $args, WP_User $user ) {
		if ( 'switch_to_user' === $args[0] ) {
			if ( array_key_exists( 'switch_users', $user_caps ) ) {
				$user_caps['switch_to_user'] = $user_caps['switch_users'];
				return $user_caps;
			}

			$user_caps['switch_to_user'] = ( user_can( $user->ID, 'edit_user', $args[2] ) && ( $args[2] !== $user->ID ) );
		} elseif ( 'switch_off' === $args[0] ) {
			if ( array_key_exists( 'switch_users', $user_caps ) ) {
				$user_caps['switch_off'] = $user_caps['switch_users'];
				return $user_caps;
			}

			$user_caps['switch_off'] = user_can( $user->ID, 'edit_users' );
		}

		return $user_caps;
	}
public function filter_user_has_cap ( array $ user_caps , array $ required_caps , array $ args , WP_User $ user ) { if ( 'switch_to_user' === $ args [ 0 ] ) { if ( array_key_exists ( 'switch_users' , $ user_caps ) ) { $ user_caps [ 'switch_to_user' ] = $ user_caps [ 'switch_users' ] ; return $ user_caps ; } $ user_caps [ 'switch_to_user' ] = ( user_can ( $ user -> ID , 'edit_user' , $ args [ 2 ] ) && ( $ args [ 2 ] !== $ user -> ID ) ) ; } elseif ( 'switch_off' === $ args [ 0 ] ) { if ( array_key_exists ( 'switch_users' , $ user_caps ) ) { $ user_caps [ 'switch_off' ] = $ user_caps [ 'switch_users' ] ; return $ user_caps ; } $ user_caps [ 'switch_off' ] = user_can ( $ user -> ID , 'edit_users' ) ; } return $ user_caps ; }
Filters a user's capabilities so they can be altered at runtime.

This is used to:
- Grant the 'switch_to_user' capability to the user if they have the ability to edit the user they're trying to
switch to (and that user is not themselves).
- Grant the 'switch_off' capability to the user if they can edit other users.

Important: This does not get called for Super Admins. See filter_map_meta_cap() below.

@param bool[]   $user_caps     Array of key/value pairs where keys represent a capability name and boolean values
represent whether the user has that capability.
@param string[] $required_caps Required primitive capabilities for the requested capability.
@param array    $args {
Arguments that accompany the requested capability check.

@type string    $0 Requested capability.
@type int       $1 Concerned user ID.
@type mixed  ...$2 Optional second and further parameters.
}
@param WP_User  $user          Concerned user object.
@return bool[] Concerned user's capabilities.
Filters a user s capabilities so they can be altered at runtime .