Make WordPress Core

Changeset 46467


Ignore:
Timestamp:
10/12/2019 03:08:56 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Users: Make sure wp_logout() clears current user, so that a subsequent call to is_user_logged_in() works as expected.

Props sebastian.pisula, donmhico, roytanck, juliobox.
Fixes #35488.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r46462 r46467  
    572572        wp_destroy_current_session();
    573573        wp_clear_auth_cookie();
     574        wp_set_current_user( 0 );
    574575
    575576        /**
  • trunk/tests/phpunit/tests/user/capabilities.php

    r45607 r46467  
    17511751     */
    17521752    function test_cpt_with_page_capability_type() {
    1753 
    17541753        register_post_type(
    17551754            'page_capability',
     
    18001799    }
    18011800
    1802     public function testNonLoggedInUsersHaveNoCapabilities() {
    1803 
     1801    public function test_non_logged_in_users_have_no_capabilities() {
    18041802        $this->assertFalse( is_user_logged_in() );
    18051803
     
    18171815        $this->assertFalse( current_user_can( 'do_not_allow' ), 'Non-logged-in user should not have the do_not_allow capability' );
    18181816    }
     1817
     1818    /**
     1819     * @ticket 35488
     1820     */
     1821    function test_wp_logout_should_clear_current_user() {
     1822        $user_id = self::factory()->user->create();
     1823        wp_set_current_user( $user_id );
     1824
     1825        wp_logout();
     1826
     1827        $this->assertEquals( 0, get_current_user_id() );
     1828
     1829    }
     1830
    18191831
    18201832    protected $_role_test_wp_roles_role;
Note: See TracChangeset for help on using the changeset viewer.