get_current_user_id

Get the current user's ID.

Description

(int) get_current_user_id(); 

Returns (int)

The current user's ID


Usage

  1. if ( !function_exists( 'get_current_user_id' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_current_user_id(); 
  7.  

Defined (1)

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

/wp-includes/user.php  
  1. function get_current_user_id() { 
  2. if ( ! function_exists( 'wp_get_current_user' ) ) 
  3. return 0; 
  4. $user = wp_get_current_user(); 
  5. return ( isset( $user->ID ) ? (int) $user->ID : 0 );