wp_validate_logged_in_cookie

Validates the logged-in cookie.

Description

(int|false) wp_validate_logged_in_cookie( (int|bool) $user_id ); 

Checks the logged-in cookie if the previous auth cookie could not be validated and parsed.

This is a callback for the filter, rather than API.

Returns (int|false)

User ID if validated, false otherwise. If a user ID from an earlier filter callback is received, that value is returned.

Parameters (1)

0. $user_id (int|bool)
The user ID (or false) as received from the determine_current_user filter.

Usage

  1. if ( !function_exists( 'wp_validate_logged_in_cookie' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // The user ID (or false) as received from the 
  5. // determine_current_user filter. 
  6. $user_id = null; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = wp_validate_logged_in_cookie($user_id); 
  10.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function wp_validate_logged_in_cookie( $user_id ) { 
  2. if ( $user_id ) { 
  3. return $user_id; 
  4.  
  5. if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) ) { 
  6. return false; 
  7.  
  8. return wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' );