Changeset 11052 for trunk/src/bp-core/bp-core-caps.php
- Timestamp:
- 09/01/2016 12:50:06 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/bp-core-caps.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-caps.php
r10909 r11052 244 244 * @since 1.6.0 245 245 * @since 2.4.0 Second argument modified to accept an array, rather than `$blog_id`. 246 * @since 2.7.0 Deprecated $args['blog_id'] in favor of $args['site_id']. 246 247 * 247 248 * @param string $capability Capability or role name. 248 249 * @param array|int $args { 249 250 * Array of extra arguments applicable to the capability check. 250 * @type int $blog_id Optional. Blog ID. Defaults to the BP root blog. 251 * @type int $site_id Optional. Blog ID. Defaults to the BP root blog. 252 * @type int $blog_id Deprecated. Use $site_id instead. 251 253 * @type mixed $a,... Optional. Extra arguments applicable to the capability check. 252 254 * } … … 254 256 */ 255 257 function bp_current_user_can( $capability, $args = array() ) { 256 $blog_id = 0;257 258 258 // Backward compatibility for older $blog_id parameter. 259 259 if ( is_int( $args ) ) { 260 260 $blog_id = $args; 261 261 $args = array(); 262 $args['site_id'] = $args; 262 263 263 264 // New format for second parameter. 264 265 } elseif ( is_array( $args ) && isset( $args['blog_id'] ) ) { 265 266 // Get the blog ID if set, but don't pass along to `current_user_can_for_blog()`. 266 $ blog_id= (int) $args['blog_id'];267 $args['site_id'] = (int) $args['blog_id']; 267 268 unset( $args['blog_id'] ); 268 269 } 269 270 270 // Backward compatibility for older bp_current_user_can() checks. 271 if ( empty( $args ) ) { 272 $args = null; 273 } 271 // Cast $args as an array. 272 $args = (array) $args; 274 273 275 274 // Use root blog if no ID passed. 276 if ( empty( $ blog_id) ) {277 $ blog_id= bp_get_root_blog_id();278 } 279 280 $args = array( $blog_id, $capability, $args );281 $retval = call_user_func_array( 'current_user_can_for_blog', $args );275 if ( empty( $args['site_id'] ) ) { 276 $args['site_id'] = bp_get_root_blog_id(); 277 } 278 279 // Call bp_user_can(). 280 $retval = bp_user_can( bp_loggedin_user_id(), $capability, $args ); 282 281 283 282 /** … … 286 285 * @since 1.6.0 287 286 * @since 2.4.0 Pass `$args` variable. 287 * @since 2.7.0 Change format of $args variable array. 288 288 * 289 289 * @param bool $retval Whether or not the current user has the capability. 290 290 * @param string $capability The capability being checked for. 291 291 * @param int $blog_id Blog ID. Defaults to the BP root blog. 292 * @param array $args Array of extra arguments passed.293 */ 294 return (bool) apply_filters( 'bp_current_user_can', $retval, $capability, $ blog_id, $args );292 * @param array $args Array of extra arguments as originally passed. 293 */ 294 return (bool) apply_filters( 'bp_current_user_can', $retval, $capability, $args['site_id'], $args ); 295 295 } 296 296 … … 320 320 321 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 ); 322 $retval = call_user_func_array( 'user_can', array( $user_id, $capability, $args ) ); 324 323 325 324 /**
Note: See TracChangeset
for help on using the changeset viewer.