# _wp_get_current_user()

URL: https://chugunov.pro/api-wordpress/functions/_wp_get_current_user/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 4.5.0.

## Сигнатура

```php
_wp_get_current_user(): WP_User
```

## Описание

Устанавливает текущего пользователя, если он ещё не задан. Текущим пользователем становится авторизованный человек. Если ни один пользователь не авторизован, текущим пользователем будет установлен 0, что является недопустимым значением и не даёт никаких прав доступа.
Эта функция используется подключаемыми функциями wp_get_current_user() и get_currentuserinfo() , последняя из которых устарела, но сохранена для обратной совместимости.
См. alsowp_get_current_user()

## Возвращаемое значение

`WP_User` — WP_User

## Исходный код

Файл: `wp-includes/user.php:3786`

```php
function _wp_get_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 junk 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 cookies, 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;
}
```

## История изменений

- 4.5.0 — Introduced.

## Связанные

Использует: [`wp_set_current_user`](https://chugunov.pro/api-wordpress/functions/wp_set_current_user/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`get_currentuserinfo`](https://chugunov.pro/api-wordpress/functions/get_currentuserinfo/), [`wp_get_current_user`](https://chugunov.pro/api-wordpress/functions/wp_get_current_user/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_wp_get_current_user/
