Changeset 11052
- Timestamp:
- 09/01/2016 12:50:06 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
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 /** -
trunk/src/bp-xprofile/bp-xprofile-caps.php
r10825 r11052 29 29 30 30 // You may pass args manually: $field_id, $profile_user_id. 31 $field_id = isset( $args[0] ) ? (int)$args[0] : bp_get_the_profile_field_id();32 $profile_user_id = isset( $args[1] ) ? (int)$args[1] : bp_displayed_user_id();31 $field_id = ! empty( $args[0] ) ? (int) $args[0] : bp_get_the_profile_field_id(); 32 $profile_user_id = isset( $args[1] ) ? (int) $args[1] : bp_displayed_user_id(); 33 33 34 34 // Visibility on the fullname field is not editable. -
trunk/tests/phpunit/testcases/core/caps.php
r10377 r11052 47 47 } 48 48 49 /**50 * @group bp_xprofile_change_field_visibility51 */52 public function test_bp_current_user_can_should_pass_null_in_args_parameter_if_empty() {53 $u = $this->factory->user->create();54 $this->set_current_user( $u );55 56 /**57 * Fake bp_get_the_profile_field_id() to pretend we're in the field loop and58 * to avoid notices when checking 'bp_xprofile_change_field_visibility' cap59 */60 $GLOBALS['field'] = new stdClass;61 $GLOBALS['field']->id = 1;62 63 // Capture the cap's $args64 add_filter( 'bp_xprofile_map_meta_caps', array( $this, 'check_cap_args' ), 10, 4 );65 66 // Use a cap check that depends on a null value for a cap's args67 bp_current_user_can( 'bp_xprofile_change_field_visibility' );68 69 // Assert!70 $this->assertEquals( null, $this->test_args[0] );71 72 // Reset73 remove_filter( 'bp_xprofile_map_meta_caps', array( $this, 'check_cap_args' ), 10, 4 );74 unset( $GLOBALS['field'], $this->test_args );75 }76 77 49 public function grant_cap_foo( $allcaps, $caps ) { 78 50 if ( bp_is_root_blog() ) {
Note: See TracChangeset
for help on using the changeset viewer.