# wp_localize_community_events()

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

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

## Сигнатура

```php
wp_localize_community_events()
```

## Описание

Локализует данные о событиях сообщества, которые нужно передать в dashboard.js.

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

Файл: `wp-includes/script-loader.php:2042`

```php
function wp_localize_community_events() {
	if ( ! wp_script_is( 'dashboard' ) ) {
		return;
	}

	require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';

	$user_id            = get_current_user_id();
	$saved_location     = get_user_option( 'community-events-location', $user_id );
	$saved_ip_address   = $saved_location['ip'] ?? false;
	$current_ip_address = WP_Community_Events::get_unsafe_client_ip();

	/*
	 * If the user's location is based on their IP address, then update their
	 * location when their IP address changes. This allows them to see events
	 * in their current city when travelling. Otherwise, they would always be
	 * shown events in the city where they were when they first loaded the
	 * Dashboard, which could have been months or years ago.
	 */
	if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) {
		$saved_location['ip'] = $current_ip_address;
		update_user_meta( $user_id, 'community-events-location', $saved_location );
	}

	$events_client = new WP_Community_Events( $user_id, $saved_location );

	wp_localize_script(
		'dashboard',
		'communityEventsData',
		array(
			'nonce'       => wp_create_nonce( 'community_events' ),
			'cache'       => $events_client->get_cached_events(),
			'time_format' => get_option( 'time_format' ),
		)
	);
}
```

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

- 4.8.0 — Introduced.

## Связанные

Использует: `WP_Community_Events::__construct`, `WP_Community_Events`, `WP_Community_Events::get_unsafe_client_ip`, [`wp_script_is`](https://chugunov.pro/api-wordpress/functions/wp_script_is/), [`wp_localize_script`](https://chugunov.pro/api-wordpress/functions/wp_localize_script/), [`update_user_meta`](https://chugunov.pro/api-wordpress/functions/update_user_meta/), [`get_user_option`](https://chugunov.pro/api-wordpress/functions/get_user_option/), [`wp_create_nonce`](https://chugunov.pro/api-wordpress/functions/wp_create_nonce/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/), [`get_current_user_id`](https://chugunov.pro/api-wordpress/functions/get_current_user_id/).

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