BP_Core_Members_Switching::filter_user_has_cap( bool[] $user_caps, string[] $required_caps, array $args, WP_User $user )
Filters a user’s capabilities so they can be altered at runtime.
Description
This is used to:
- Grant the ‘bp_member_switch_to’ 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.
Parameters
- $user_caps
-
(Required) Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability.
- $required_caps
-
(Required) Required primitive capabilities for the requested capability.
- $args
-
(Required) Arguments that accompany the requested capability check
- $user
-
(Required) Concerned user object.
Return
(bool[]) Concerned user's capabilities.
Source
File: bp-members/classes/class-bp-core-members-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; }
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.