WordPress.org

Make WordPress Core

Ticket #35488: 35488.1.diff

File 35488.1.diff, 946 bytes (added by donmhico, 4 months ago)

Refresh the patch and added a unit test.

  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index 4edb9929f6..a06bcdcadc 100644
    if ( ! function_exists( 'wp_logout' ) ) : 
    568568        function wp_logout() {
    569569                wp_destroy_current_session();
    570570                wp_clear_auth_cookie();
     571                wp_set_current_user( 0 );
    571572
    572573                /**
    573574                 * Fires after a user is logged-out.
  • tests/phpunit/tests/pluggable.php

    diff --git tests/phpunit/tests/pluggable.php tests/phpunit/tests/pluggable.php
    index e711f3b8bc..aeb96936a8 100644
    class Tests_Pluggable extends WP_UnitTestCase { 
    319319                return $signatures;
    320320        }
    321321
     322        /**
     323         * @ticket 35488
     324         */
     325        function testWpLogoutShouldSetCurrentUserIdToZero() {
     326
     327                $user_id = self::factory()->user->create();
     328
     329                wp_set_current_user( $user_id );
     330
     331                wp_logout();
     332
     333                $this->assertEquals( 0, get_current_user_id() );
     334
     335        }
     336
    322337}