WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get current user id

Description

Returns the ID of the current user.

Use the init or any subsequent action to call this function. Calling it outside of an action can lead to troubles.

Usage

 <?php $user_ID get_current_user_id(); ?> 

Returns

(int) 
The user's ID, if there is a current user; otherwise 0.

Changelog

Since: Version 3.0

Source Code

get_current_user_id() is located in wp-includes/user.php.

Related

Get User Functions:

Current User Functions: get_current_user_id(), get_currentuserinfo(), wp_get_current_user(), wp_set_current_user(), current_user_can(), current_user_can_for_blog()

See also index of Function Reference and index of Template Tags.