wp_get_current_user

The timeline below displays how wordpress function wp_get_current_user has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Retrieves the current user object.
 *
 * Will set the current user, if the current user is not set. The current user
 * will be set to the logged-in person. If no user is logged-in, then it will
 * set the current user to 0, which is invalid and won't have any permissions.
 *
 * @since 2.0.3
 *
 * @see _wp_get_current_user()
 * @global WP_User $current_user Checks if the current user is set.
 *
 * @return WP_User Current WP_User instance.
 */
function wp_get_current_user()
{
    return _wp_get_current_user();
}

WordPress Version: 4.5

/**
 * Retrieve the current user object.
 *
 * Will set the current user, if the current user is not set. The current user
 * will be set to the logged-in person. If no user is logged-in, then it will
 * set the current user to 0, which is invalid and won't have any permissions.
 *
 * @since 2.0.3
 *
 * @see _wp_get_current_user()
 * @global WP_User $current_user Checks if the current user is set.
 *
 * @return WP_User Current WP_User instance.
 */
function wp_get_current_user()
{
    return _wp_get_current_user();
}

WordPress Version: 4.3

/**
 * Retrieve the current user object.
 *
 * @since 2.0.3
 *
 * @global WP_User $current_user
 *
 * @return WP_User Current user WP_User object
 */
function wp_get_current_user()
{
    global $current_user;
    get_currentuserinfo();
    return $current_user;
}

WordPress Version: 3.7

/**
 * Retrieve the current user object.
 *
 * @since 2.0.3
 *
 * @return WP_User Current user WP_User object
 */
function wp_get_current_user()
{
    global $current_user;
    get_currentuserinfo();
    return $current_user;
}