Skip to content

Commit a8259b8

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@46467 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5729349 commit a8259b8

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/wp-includes/pluggable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ function wp_authenticate( $username, $password ) {
571571
function wp_logout() {
572572
wp_destroy_current_session();
573573
wp_clear_auth_cookie();
574+
wp_set_current_user( 0 );
574575

575576
/**
576577
* Fires after a user is logged-out.

tests/phpunit/tests/user/capabilities.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,6 @@ function test_require_edit_others_posts_if_post_type_doesnt_exist() {
17501750
* @ticket 17253
17511751
*/
17521752
function test_cpt_with_page_capability_type() {
1753-
17541753
register_post_type(
17551754
'page_capability',
17561755
array(
@@ -1799,8 +1798,7 @@ function test_cpt_with_page_capability_type() {
17991798

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

18061804
$caps = $this->getAllCapsAndRoles();
@@ -1817,6 +1815,20 @@ public function testNonLoggedInUsersHaveNoCapabilities() {
18171815
$this->assertFalse( current_user_can( 'do_not_allow' ), 'Non-logged-in user should not have the do_not_allow capability' );
18181816
}
18191817

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+
1831+
18201832
protected $_role_test_wp_roles_role;
18211833
/**
18221834
* @ticket 23016

0 commit comments

Comments
 (0)