WordPress.org

Make WordPress Core

Ticket #26706: 26706.3.diff

File 26706.3.diff, 2.5 KB (added by nacin, 7 years ago)

Alternative filter name, validate_auth_cookie.

  • src/wp-includes/default-filters.php

     
    301301add_filter( 'authenticate', 'wp_authenticate_username_password',  20, 3 );
    302302add_filter( 'authenticate', 'wp_authenticate_spam_check',         99    );
    303303
     304// Default user checking filters
     305add_filter( 'validate_auth_cookie', 'wp_validate_auth_cookie' );
     306add_filter( 'validate_auth_cookie', 'wp_validate_logged_in_cookie', 20 );
     307
    304308unset($filter, $action);
  • src/wp-includes/pluggable.php

     
    9797                return false;
    9898        }
    9999
    100         if ( ! $user = wp_validate_auth_cookie() ) {
    101                  if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) || !$user = wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' ) ) {
    102                         wp_set_current_user( 0 );
    103                         return false;
    104                  }
     100        /**
     101         * Determine the current user based on request data.
     102         *
     103         * The default filters use this to determine the current user from the
     104         * request's cookies, if available.
     105         *
     106         * @since 3.9.0
     107         *
     108         * @param int|boolean $user_id User ID if determined, or false otherwise.
     109         */
     110        $user_id = apply_filters( 'validate_auth_cookie', false );
     111        if ( ! $user_id ) {
     112                wp_set_current_user( 0 );
     113                return false;
    105114        }
    106115
    107         wp_set_current_user( $user );
     116        wp_set_current_user( $user_id );
    108117}
    109118endif;
    110119
  • src/wp-includes/user.php

     
    220220}
    221221
    222222/**
     223 * Validates logged in cookie.
     224 *
     225 * Checks the logged_in cookie if the previous auth cookie could not be
     226 * validated and parsed.
     227 *
     228 * This is a callback for the validate_auth_cookie filter, rather than API.
     229 *
     230 * @since 3.9.0
     231 *
     232 * @param mixed $user The user ID (or null) as received from the validate_auth_cookie filter.
     233 * @return int|boolean User ID if validated, or false otherwise.
     234 */
     235function wp_validate_logged_in_cookie( $user_id ) {
     236        if ( $user_id ) {
     237                return $user_id;
     238        }
     239
     240        if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) ) {
     241                return false;
     242        }
     243
     244        return wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' );
     245}
     246
     247/**
    223248 * Number of posts user has written.
    224249 *
    225250 * @since 3.0.0