Skip to:
Content

BuddyPress.org

Ticket #6501: 6501.02.patch

File 6501.02.patch, 2.3 KB (added by r-a-y, 4 years ago)
  • src/bp-core/bp-core-caps.php

     
    263263/**
    264264 * Check whether the current user has a given capability.
    265265 *
    266  * Can be passed blog ID, or will use the root blog by default.
    267  *
    268266 * @since BuddyPress (1.6.0)
    269267 *
    270  * @param string $capability Capability or role name.
    271  * @param int $blog_id Optional. Blog ID. Defaults to the BP root blog.
     268 * @param string    $capability Capability or role name.
     269 * @param array|int $args {
     270 *     Array of extra arguments applicable to the capability check.
     271 *     @type int   $blog_id Optional. Blog ID. Defaults to the BP root blog.
     272 *     @type mixed $a,...   Optional. Extra arguments applicable to the capability check.
     273 * }
    272274 * @return bool True if the user has the cap for the given blog.
    273275 */
    274 function bp_current_user_can( $capability, $blog_id = 0 ) {
     276function bp_current_user_can( $capability, $args = array() ) {
     277        $blog_id = 0;
     278
     279        // Backward compatibility for older $blog_id parameter
     280        if ( is_int( $args ) ) {
     281                $blog_id = $args;
     282                $args = array();
     283
     284        // New format for second parameter
     285        } elseif ( is_array( $args ) && isset( $args['blog_id'] ) ) {
     286                // Get the blog ID if set
     287                $blog_id = (int) $args['blog_id'];
     288                unset( $args['blog_id'] );
     289        }
    275290
    276291        // Use root blog if no ID passed
    277292        if ( empty( $blog_id ) ) {
    278293                $blog_id = bp_get_root_blog_id();
    279294        }
    280295
    281         $retval = current_user_can_for_blog( $blog_id, $capability );
     296        $args   = array( $blog_id, $capability, $args );
     297        $retval = call_user_func_array( 'current_user_can_for_blog', $args );
    282298
    283299        /**
    284300         * Filters whether or not the current user has a given capability.
    285301         *
    286302         * @since BuddyPress (1.6.0)
     303         * @since BuddyPress (2.4.0) Pass $args variable.
    287304         *
    288305         * @param bool   $retval     Whether or not the current user has the capability.
    289306         * @param string $capability The capability being checked for.
    290307         * @param int    $blog_id    Blog ID. Defaults to the BP root blog.
     308         * @param array  $args       Array of extra arguments passed.
    291309         */
    292         return (bool) apply_filters( 'bp_current_user_can', $retval, $capability, $blog_id );
     310        return (bool) apply_filters( 'bp_current_user_can', $retval, $capability, $blog_id, $args );
    293311}
    294312
    295313/**