Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/20/2015 01:54:56 PM (5 years ago)
Author:
boonebgorges
Message:

Convert second parameter of bp_current_user_can() to an $args array.

This makes the syntax simpler for the vast majority of use cases, where an
explicit blog_id doesn't need to be specified. It also makes it possible to
pass additional arguments, such as an item_id, to bp_current_user_can().

An integer passed as the second parameter will trigger the backward-
compatibility layer.

Props thebrandonallen, r-a-y.
See #5121. Fixes #6501.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/caps.php

    r9956 r9957  
    2525    }
    2626
     27    /**
     28     * @ticket BP6501
     29     */
     30    public function test_bp_current_user_can_should_respect_blog_id_passed_in_args_array() {
     31        if ( ! is_multisite() ) {
     32            $this->markTestSkipped( __METHOD__ . ' requires multisite.' );
     33        }
     34
     35        $b = $this->factory->blog->create();
     36        $u = $this->factory->user->create();
     37
     38        $this->set_current_user( $u );
     39
     40        add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
     41        $can  = bp_current_user_can( 'foo', array( 'blog_id' => bp_get_root_blog_id() ) );
     42        $cant = bp_current_user_can( 'foo', array( 'blog_id' => $b ) );
     43        remove_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
     44
     45        $this->assertTrue( $can );
     46        $this->assertFalse( $cant );
     47    }
     48
    2749    public function grant_cap_foo( $allcaps, $caps ) {
    2850        if ( bp_is_root_blog() ) {
Note: See TracChangeset for help on using the changeset viewer.