Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/03/2024 06:19:06 PM (9 months ago)
Author:
espellcaste
Message:

A user is no longer de-authenticated when making REST API requests.

We are introducing a new BP_LoggedIn_User class to fetch data about a BuddyPress logged-in user. This new addition fixes an issue where a user could be de-authenticated when making REST API requests.

Props dcavins, DJPaul, johnjamesjacoby, and imath.

Closes https://github.com/buddypress/buddypress/pull/395
See #9229 and #9145
Fixes #7658

File:
1 edited

Legend:

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

    r13980 r14070  
    2020
    2121    public function tear_down() {
    22         self::set_current_user( $this->reset_user_id );
     22        wp_set_current_user( $this->reset_user_id );
    2323        parent::tear_down();
    2424    }
     
    3232        $u = self::factory()->user->create();
    3333
    34         self::set_current_user( $u );
     34        wp_set_current_user( $u );
    3535
    3636        add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
     
    5454        $u = self::factory()->user->create();
    5555
    56         self::set_current_user( $u );
     56        wp_set_current_user( $u );
    5757
    5858        add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
     
    8888        );
    8989
    90         self::set_current_user( $u );
     90        wp_set_current_user( $u );
    9191
    9292        $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Administrator can `bp_moderate` on default WordPress config' );
     
    108108        );
    109109
    110         self::set_current_user( $u );
     110        wp_set_current_user( $u );
    111111
    112112        $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Users having a `manage_options` cap into their role can `bp_moderate`' );
     
    130130        );
    131131
    132         self::set_current_user( $u1 );
     132        wp_set_current_user( $u1 );
    133133
    134134        $email = self::factory()->post->create(
     
    140140        $this->assertTrue( current_user_can( 'edit_post', $email ), 'Administrator should be able to edit emails they created' );
    141141
    142         self::set_current_user( $u2 );
     142        wp_set_current_user( $u2 );
    143143
    144144        $this->assertTrue( current_user_can( 'edit_post', $email ), 'Administrator should be able to edit emails others created when BuddyPress is not network activated' );
     
    171171        switch_to_blog( $this->blog_id );
    172172
    173         self::set_current_user( $u1 );
     173        wp_set_current_user( $u1 );
    174174        $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Only Super Admins can `bp_moderate` when BuddyPress is network activated' );
    175175
    176         self::set_current_user( $u2 );
     176        wp_set_current_user( $u2 );
    177177
    178178        $this->assertFalse( bp_current_user_can( 'bp_moderate' ), 'Regular Admins cannot `bp_moderate` when BuddyPress is network activated' );
     
    219219        restore_current_blog();
    220220
    221         self::set_current_user( $u1 );
     221        wp_set_current_user( $u1 );
    222222        $this->assertTrue( current_user_can( 'edit_post', $email ), 'Super Admins should be able to edit emails they created' );
    223223
    224         self::set_current_user( $u2 );
     224        wp_set_current_user( $u2 );
    225225        $this->assertFalse( current_user_can( 'edit_post', $email ), 'Administrator should not be able to edit emails others created when BuddyPress is network activated' );
    226226
Note: See TracChangeset for help on using the changeset viewer.