| 1 | Index: capabilities.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- capabilities.php (revision 23176) |
|---|
| 4 | +++ capabilities.php (working copy) |
|---|
| 5 | @@ -1365,6 +1365,37 @@ |
|---|
| 6 | } |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | + * Whether a particular user has capability or role. |
|---|
| 10 | + * |
|---|
| 11 | + * @since 3.5.1 |
|---|
| 12 | + * |
|---|
| 13 | + * @param int|object $user User ID or object. |
|---|
| 14 | + * @param int $blog_id Blog ID |
|---|
| 15 | + * @param string $capability Capability or role name. |
|---|
| 16 | + * @return bool |
|---|
| 17 | + */ |
|---|
| 18 | +function user_can_for_blog( $user, $blog_id, $capability ) { |
|---|
| 19 | + if ( is_multisite() ) |
|---|
| 20 | + switch_to_blog( $blog_id ); |
|---|
| 21 | + |
|---|
| 22 | + if ( ! is_object( $user ) ) |
|---|
| 23 | + $user = get_userdata( $user ); |
|---|
| 24 | + |
|---|
| 25 | + if ( ! $user || ! $user->exists() ) |
|---|
| 26 | + return false; |
|---|
| 27 | + |
|---|
| 28 | + $args = array_slice( func_get_args(), 3 ); |
|---|
| 29 | + $args = array_merge( array( $capability ), $args ); |
|---|
| 30 | + |
|---|
| 31 | + $can = call_user_func_array( array( $user, 'has_cap' ), $args ); |
|---|
| 32 | + |
|---|
| 33 | + if ( is_multisite() ) |
|---|
| 34 | + restore_current_blog(); |
|---|
| 35 | + |
|---|
| 36 | + return $can; |
|---|
| 37 | +} |
|---|
| 38 | + |
|---|
| 39 | +/** |
|---|
| 40 | * Retrieve role object. |
|---|
| 41 | * |
|---|
| 42 | * @see WP_Roles::get_role() Uses method to retrieve role object. |
|---|