Make WordPress Core

Changeset 58341 for trunk


Ignore:
Timestamp:
06/05/2024 12:21:46 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Login and Registration: Declare globals at the top of wp_signon() for consistency.

Follow-up to [10437], [32637], [58333].

See #58901.

Location:
trunk
Files:
2 edited

Legend:

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

    r58333 r58341  
    2626 *
    2727 * @global string $auth_secure_cookie
     28 * @global wpdb   $wpdb               WordPress database abstraction object.
    2829 *
    2930 * @param array       $credentials {
     
    3940 */
    4041function wp_signon( $credentials = array(), $secure_cookie = '' ) {
     42        global $auth_secure_cookie, $wpdb;
     43
    4144        if ( empty( $credentials ) ) {
    4245                $credentials = array(
     
    99102        $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials );
    100103
    101         global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie().
     104        // XXX ugly hack to pass this to wp_authenticate_cookie().
    102105        $auth_secure_cookie = $secure_cookie;
    103106
     
    112115        wp_set_auth_cookie( $user->ID, $credentials['remember'], $secure_cookie );
    113116
    114         /**
    115          * @global wpdb $wpdb WordPress database abstraction object.
    116          */
    117         global $wpdb;
    118 
    119         // Flush `user_activation_key` if exists after successful login.
     117        // Clear `user_activation_key` after a successful login.
    120118        if ( ! empty( $user->user_activation_key ) ) {
    121119                $wpdb->update(
     
    124122                                'user_activation_key' => '',
    125123                        ),
    126                         array( 'ID' => $user->ID ),
    127                         array( '%s' ),
    128                         array( '%d' )
     124                        array( 'ID' => $user->ID )
    129125                );
    130126
    131                 // Empty user_activation_key object.
    132127                $user->user_activation_key = '';
    133128        }
     
    142137         */
    143138        do_action( 'wp_login', $user->user_login, $user );
     139
    144140        return $user;
    145141}
     
    307303 */
    308304function wp_authenticate_cookie( $user, $username, $password ) {
     305        global $auth_secure_cookie;
     306
    309307        if ( $user instanceof WP_User ) {
    310308                return $user;
     
    316314                        return new WP_User( $user_id );
    317315                }
    318 
    319                 global $auth_secure_cookie;
    320316
    321317                if ( $auth_secure_cookie ) {
  • trunk/tests/phpunit/tests/auth.php

    r58333 r58341  
    425425
    426426        /**
    427          * Ensure that the user_activation_key is cleared (if available) after a successful login.
     427         * Ensure that `user_activation_key` is cleared after a successful login.
    428428         *
    429429         * @ticket 58901
     430         *
     431         * @covers ::wp_signon
    430432         */
    431433        public function test_user_activation_key_after_successful_login() {
    432434                global $wpdb;
    433435
    434                 $reset_key                    = get_password_reset_key( $this->user );
    435                 $user                         = wp_signon(
     436                $password_reset_key = get_password_reset_key( $this->user );
     437                $user               = wp_signon(
    436438                        array(
    437439                                'user_login'    => self::USER_LOGIN,
     
    439441                        )
    440442                );
     443
    441444                $activation_key_from_database = $wpdb->get_var(
    442445                        $wpdb->prepare( "SELECT user_activation_key FROM $wpdb->users WHERE ID = %d", $this->user->ID )
    443446                );
    444447
    445                 $this->assertNotWPError( $reset_key, 'The password reset key was not created.' );
     448                $this->assertNotWPError( $password_reset_key, 'The password reset key was not created.' );
    446449                $this->assertNotWPError( $user, 'The user was not authenticated.' );
    447                 $this->assertEmpty( $user->user_activation_key, 'The `user_activation_key` was not empty on the user object returned by `wp_signon` function.' );
     450                $this->assertEmpty( $user->user_activation_key, 'The `user_activation_key` was not empty on the user object returned by `wp_signon()` function.' );
    448451                $this->assertEmpty( $activation_key_from_database, 'The `user_activation_key` was not empty in the database.' );
    449452        }
Note: See TracChangeset for help on using the changeset viewer.