WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/09/2014 03:22:13 PM (7 years ago)
Author:
nacin
Message:

Allow for custom authentication handlers for all requests.

Turn the logic used by wp_get_current_user() into a determine_current_user filter.

props rmccue.
fixes #26706.

File:
1 edited

Legend:

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

    r27354 r27484  
    218218    }
    219219    return $user;
     220}
     221
     222/**
     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 determine_current_user filter, rather than API.
     229 *
     230 * @since 3.9.0
     231 *
     232 * @param int|boolean $user The user ID (or false) as received from the determine_current_user filter.
     233 * @return int|boolean User ID if validated, or false otherwise. If it receives a user ID from
     234 *                     an earlier filter callback, that value is returned.
     235 */
     236function wp_validate_logged_in_cookie( $user_id ) {
     237    if ( $user_id ) {
     238        return $user_id;
     239    }
     240
     241    if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) ) {
     242        return false;
     243    }
     244
     245    return wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' );
    220246}
    221247
Note: See TracChangeset for help on using the changeset viewer.