bp_user_can( int $user_id, string $capability, array|int $args = array() )
Check whether the specified user has a given capability on a given site.
Description
Parameters
- $user_id
-
(Required)
- $capability
-
(Required) Capability or role name.
- $args
-
(Optional) Array of extra arguments applicable to the capability check.
- 'site_id'
(int) Optional. Site ID. Defaults to the BP root blog. - 'a,...'
(mixed) Optional. Extra arguments applicable to the capability check.
Default value: array()
- 'site_id'
Return
(bool) True if the user has the cap for the given parameters.
Source
File: bp-core/bp-core-caps.php
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | function bp_user_can( $user_id , $capability , $args = array () ) { $site_id = bp_get_root_blog_id(); // Get the site ID if set, but don't pass along to user_can(). if ( isset( $args [ 'site_id' ] ) ) { $site_id = (int) $args [ 'site_id' ]; unset( $args [ 'site_id' ] ); } $switched = is_multisite() ? switch_to_blog( $site_id ) : false; $retval = call_user_func_array( 'user_can' , array ( $user_id , $capability , $args ) ); /** * Filters whether or not the specified user has a given capability on a given site. * * @since BuddyPress 2.7.0 * * @param bool $retval Whether or not the current user has the capability. * @param int $user_id * @param string $capability The capability being checked for. * @param int $site_id Site ID. Defaults to the BP root blog. * @param array $args Array of extra arguments passed. */ $retval = (bool) apply_filters( 'bp_user_can' , $retval , $user_id , $capability , $site_id , $args ); if ( $switched ) { restore_current_blog(); } return $retval ; } |
Changelog
Version | Description |
---|---|
BuddyPress 2.7.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.