Skip to:
Content

BuddyPress.org

Changeset 10909


Ignore:
Timestamp:
06/28/2016 04:25:49 PM (9 years ago)
Author:
djpaul
Message:

Introduce bp_user_can, which supports user_can for BuddyPress' multisite configurations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-caps.php

    r10899 r10909  
    296296
    297297/**
     298 * Check whether the specified user has a given capability on a given site.
     299 *
     300 * @since 2.7.0
     301 *
     302 * @param int       $user_id
     303 * @param string    $capability Capability or role name.
     304 * @param array|int $args {
     305 *     Array of extra arguments applicable to the capability check.
     306 *
     307 *     @type int   $site_id Optional. Site ID. Defaults to the BP root blog.
     308 *     @type mixed $a,...   Optional. Extra arguments applicable to the capability check.
     309 * }
     310 * @return bool True if the user has the cap for the given parameters.
     311 */
     312function bp_user_can( $user_id, $capability, $args = array() ) {
     313    $site_id = bp_get_root_blog_id();
     314
     315    // Get the site ID if set, but don't pass along to user_can().
     316    if ( isset( $args['site_id'] ) ) {
     317        $site_id = (int) $args['site_id'];
     318        unset( $args['site_id'] );
     319    }
     320
     321    $switched = is_multisite() ? switch_to_blog( $site_id ) : false;
     322    $args     = array( $user_id, $capability, $args );
     323    $retval   = call_user_func_array( 'user_can', $args );
     324
     325    /**
     326     * Filters whether or not the specified user has a given capability on a given site.
     327     *
     328     * @since 2.7.0
     329     *
     330     * @param bool   $retval     Whether or not the current user has the capability.
     331     * @param int    $user_id
     332     * @param string $capability The capability being checked for.
     333     * @param int    $site_id    Site ID. Defaults to the BP root blog.
     334     * @param array  $args       Array of extra arguments passed.
     335     */
     336    $retval = (bool) apply_filters( 'bp_user_can', $retval, $user_id, $capability, $site_id, $args );
     337
     338    if ( $switched ) {
     339        restore_current_blog();
     340    }
     341
     342    return $retval;
     343}
     344
     345/**
    298346 * Temporary implementation of 'bp_moderate' cap.
    299347 *
Note: See TracChangeset for help on using the changeset viewer.