WordPress at a glance

get_current_user_id() WP 3.0.0

Get the current user's ID.

Works based on: wp_get_current_user()
1 time = 0.000012s = very fast | 50000 times = 0.01s = 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.5.1

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

From tag: Users (_user)

More from category: Other

vladlu 100vlad.lu
Editors: kama 100
4 comments
    Log In . Register