WordPress at Your Fingertips

get_current_user_id() WP 3.0.0

Get the current user's ID.

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

#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.

Code of get_current_user_id() WP 5.8.1

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 );
}

Users (_user)

Other

vladlu 100vlad.lu
Editors: Kama 101
4 comments
    Log In