# wp_ajax_get_community_events()

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

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

## Сигнатура

```php
wp_ajax_get_community_events()
```

## Описание

Обрабатывает Ajax-запросы для событий сообщества

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

Файл: `wp-admin/includes/ajax-actions.php:368`

```php
function wp_ajax_get_community_events() {
	require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';

	check_ajax_referer( 'community_events' );

	$search         = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : '';
	$timezone       = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : '';
	$user_id        = get_current_user_id();
	$saved_location = get_user_option( 'community-events-location', $user_id );
	$events_client  = new WP_Community_Events( $user_id, $saved_location );
	$events         = $events_client->get_events( $search, $timezone );
	$ip_changed     = false;

	if ( is_wp_error( $events ) ) {
		wp_send_json_error(
			array(
				'error' => $events->get_error_message(),
			)
		);
	} else {
		if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) {
			$ip_changed = true;
		} elseif ( isset( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) && $saved_location['ip'] !== $events['location']['ip'] ) {
			$ip_changed = true;
		}

		/*
		 * The location should only be updated when it changes. The API doesn't always return
		 * a full location; sometimes it's missing the description or country. The location
		 * that was saved during the initial request is known to be good and complete, though.
		 * It should be left intact until the user explicitly changes it (either by manually
		 * searching for a new location, or by changing their IP address).
		 *
		 * If the location was updated with an incomplete response from the API, then it could
		 * break assumptions that the UI makes (e.g., that there will always be a description
		 * that corresponds to a latitude/longitude location).
		 *
		 * The location is stored network-wide, so that the user doesn't have to set it on each site.
		 */
		if ( $ip_changed || $search ) {
			update_user_meta( $user_id, 'community-events-location', $events['location'] );
		}

		wp_send_json_success( $events );
	}
}
```

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

- 4.8.0 — Introduced.

## Связанные

Использует: `WP_Community_Events::__construct`, `WP_Community_Events`, [`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_unslash`](https://chugunov.pro/api-wordpress/functions/wp_unslash/), [`check_ajax_referer`](https://chugunov.pro/api-wordpress/functions/check_ajax_referer/), [`wp_send_json_error`](https://chugunov.pro/api-wordpress/functions/wp_send_json_error/), [`wp_send_json_success`](https://chugunov.pro/api-wordpress/functions/wp_send_json_success/), [`get_current_user_id`](https://chugunov.pro/api-wordpress/functions/get_current_user_id/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).

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