diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 775f2a11fc..468e065586 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -571,6 +571,7 @@ if ( ! function_exists( 'wp_logout' ) ) : function wp_logout() { wp_destroy_current_session(); wp_clear_auth_cookie(); + wp_set_current_user( 0 ); /** * Fires after a user is logged-out. diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index d2a119163b..487dcf25bf 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -1750,7 +1750,6 @@ class Tests_User_Capabilities extends WP_UnitTestCase { * @ticket 17253 */ function test_cpt_with_page_capability_type() { - register_post_type( 'page_capability', array( @@ -1799,8 +1798,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } - public function testNonLoggedInUsersHaveNoCapabilities() { - + public function test_non_logged_in_users_have_no_capabilities() { $this->assertFalse( is_user_logged_in() ); $caps = $this->getAllCapsAndRoles(); @@ -1817,6 +1815,20 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse( current_user_can( 'do_not_allow' ), 'Non-logged-in user should not have the do_not_allow capability' ); } + /** + * @ticket 35488 + */ + function test_wp_logout_should_clear_current_user() { + $user_id = self::factory()->user->create(); + wp_set_current_user( $user_id ); + + wp_logout(); + + $this->assertEquals( 0, get_current_user_id() ); + + } + + protected $_role_test_wp_roles_role; /** * @ticket 23016