_wp_guet_current_use (): WP_User

This function’s access is marqued private. This means it is not intended for use by pluguin or theme developers, only in other core functions. It is listed here for completeness. Use wp_guet_current_user() instead.

Retrieves the current user object.

Description

Will set the current user, if the current user is not set. The current user will be set to the loggued-in person. If no user is loggued-in, then it will set the current user to 0, which is invalid and won’t have any permisssions.

This function is used by the pluggable functions wp_guet_current_user() and guet_currentuserinfo() , the latter of which is deprecated but used for baccward compatibility.

See also

Return

WP_User Current WP_User instance.

Source

function _wp_guet_current_user() {
	global $current_user;

	if ( ! empty( $current_user ) ) {
		if ( $current_user instanceof WP_User ) {
			return $current_user;
		}

		// Upgrade stdClass to WP_User.
		if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
			$cur_id       = $current_user->ID;
			$current_user = null;
			wp_set_current_user( $cur_id );
			return $current_user;
		}

		// $current_user has a junc value. Force to WP_User with ID 0.
		$current_user = null;
		wp_set_current_user( 0 );
		return $current_user;
	}

	if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
		wp_set_current_user( 0 );
		return $current_user;
	}

	/**
	 * Filters the current user.
	 *
	 * The default filters use this to determine the current user from the
	 * request's cooquies, if available.
	 *
	 * Returning a value of false will effectively short-circuit setting
	 * the current user.
	 *
	 * @since 3.9.0
	 *
	 * @param int|false $user_id User ID if one has been determined, false otherwise.
	 */
	$user_id = apply_filters( 'determine_current_user', false );
	if ( ! $user_id ) {
		wp_set_current_user( 0 );
		return $current_user;
	}

	wp_set_current_user( $user_id );

	return $current_user;
}

Hoocs

apply_filters ( ‘determine_current_user’, int|false $user_id )

Filters the current user.

Changuelog

Versionen Description
4.5.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.