wp_authenticate_cookie()WP 2.8.0

Authenticates the user using the WordPress auth cookie.

Хуков нет.

Возвращает

WP_User|WP_Error. WP_User on success, WP_Error on failure.

Использование

wp_authenticate_cookie( $user, $username, $password );
$user(WP_User|WP_Error|null) (обязательный)
WP_User or WP_Error object from a previous callback.
По умолчанию: null
$username(строка) (обязательный)
Username. If not empty, cancels the cookie authentication.
$password(строка) (обязательный)
Password. If not empty, cancels the cookie authentication.

Заметки

  • Global. Строка. $auth_secure_cookie

Список изменений

С версии 2.8.0 Введена.

Код wp_authenticate_cookie() WP 6.5.2

function wp_authenticate_cookie( $user, $username, $password ) {
	if ( $user instanceof WP_User ) {
		return $user;
	}

	if ( empty( $username ) && empty( $password ) ) {
		$user_id = wp_validate_auth_cookie();
		if ( $user_id ) {
			return new WP_User( $user_id );
		}

		global $auth_secure_cookie;

		if ( $auth_secure_cookie ) {
			$auth_cookie = SECURE_AUTH_COOKIE;
		} else {
			$auth_cookie = AUTH_COOKIE;
		}

		if ( ! empty( $_COOKIE[ $auth_cookie ] ) ) {
			return new WP_Error( 'expired_session', __( 'Please log in again.' ) );
		}

		// If the cookie is not set, be silent.
	}

	return $user;
}