WordPress at Your Fingertips
rgbcode is looking for WordPress developers.

get_current_user_id()WP 3.0.0

Get the current user's ID.

Returns 0 if used in an unauthorized REST request. One way to authorize a REST request is to specify nonce code. Read more about REST authorization.

1 time — 0.000012 sec (very fast) | 50000 times — 0.01 sec (speed of light) | PHP 7.1.2, WP 4.7.4

No Hooks.

Return

Int. The current user's ID, or 0 if no user is logged in.

Usage

get_current_user_id();

Examples

0

#1 Get current user ID for further processing

$cur_user_id = get_current_user_id();
echo $cur_user_id; //> 5

Changelog

Since 3.0.0 Introduced.

get_current_user_id() code WP 6.6.2

function get_current_user_id() {
	if ( ! function_exists( 'wp_get_current_user' ) ) {
		return 0;
	}
	$user = wp_get_current_user();
	return ( isset( $user->ID ) ? (int) $user->ID : 0 );
}
vladlu 100vlad.lu
Editors: Kama 418
4 comments
    Log In