get_current_user_id() WordPress Function

The get_current_user_id() function is used to retrieve the current user's ID. This function is useful for checking if a user is logged in or not. If the user is not logged in, the function will return 0.

get_current_user_id() #

Gets the current user’s ID.


Return

(int) The current user's ID, or 0 if no user is logged in.


Top ↑

Source

File: wp-includes/user.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 );
}


Top ↑

Changelog

Changelog
VersionDescription
MU (3.0.0)Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More