|[ Index ]||
PHP Cross Reference of WordPress
Administration: Community Events class.
|File Size:||465 lines (16 kb)|
|Included or required:||0 times|
|Includes or requires:||0 files|
|__construct( $user_id, $user_location = false ) X-Ref|
|Constructor for WP_Community_Events.|
param: int $user_id WP user ID.
param: bool|array $user_location Stored location data for the user.
|get_events( $location_search = '', $timezone = '' ) X-Ref|
|Gets data about events near a particular location.|
Cached events will be immediately returned if the `user_location` property
is set for the current user, and cached events exist for that location.
Otherwise, this method sends a request to the w.org Events API with location
data. The API will send back a recognized location based on the data, along
with nearby events.
The browser's request for events is proxied with this method, rather
than having the browser make the request directly to api.wordpress.org,
because it allows results to be cached server-side and shared with other
users and sites in the network. This makes the process more efficient,
since increasing the number of visits that get cached data means users
don't have to wait as often; if the user's browser made the request
directly, it would also need to make a second request to WP in order to
pass the data for caching. Having WP make the request also introduces
the opportunity to anonymize the IP before sending it to w.org, which
mitigates possible privacy concerns.
param: string $location_search Optional. City name to help determine the location.
param: string $timezone Optional. Timezone to help determine the location.
return: array|WP_Error A WP_Error on failure; an array with location and events on
|get_request_args( $search = '', $timezone = '' ) X-Ref|
|Builds an array of args to use in an HTTP request to the w.org Events API.|
param: string $search Optional. City search string. Default empty string.
param: string $timezone Optional. Timezone string. Default empty string.
return: array The request args.
|Determines the user's actual IP address and attempts to partially|
anonymize an IP address by converting it to a network ID.
Geolocating the network ID usually returns a similar location as the
actual IP, but provides some privacy for the user.
$_SERVER['REMOTE_ADDR'] cannot be used in all cases, such as when the user
is making their request through a proxy, or when the web server is behind
a proxy. In those cases, $_SERVER['REMOTE_ADDR'] is set to the proxy address rather
than the user's actual address.
Modified from https://stackoverflow.com/a/2031935/450127, MIT license.
Modified from https://github.com/geertw/php-ip-anonymizer, MIT license.
SECURITY WARNING: This function is _NOT_ intended to be used in
circumstances where the authenticity of the IP address matters. This does
_NOT_ guarantee that the returned address is valid or accurate, and it can
be easily spoofed.
return: string|false The anonymized address on success; the given address
|coordinates_match( $a, $b ) X-Ref|
|Test if two pairs of latitude/longitude coordinates match each other.|
param: array $a The first pair, with indexes 'latitude' and 'longitude'.
param: array $b The second pair, with indexes 'latitude' and 'longitude'.
return: bool True if they match, false if they don't.
|get_events_transient_key( $location ) X-Ref|
|Generates a transient key based on user location.|
This could be reduced to a one-liner in the calling functions, but it's
intentionally a separate function because it's called from multiple
functions, and having it abstracted keeps the logic consistent and DRY,
which is less prone to errors.
param: array $location Should contain 'latitude' and 'longitude' indexes.
return: bool|string false on failure, or a string on success.
|cache_events( $events, $expiration = false ) X-Ref|
|Caches an array of events data from the Events API.|
param: array $events Response body from the API request.
param: int|bool $expiration Optional. Amount of time to cache the events. Defaults to false.
return: bool true if events were cached; false if not.
|Gets cached events.|
return: array|false An array containing `location` and `events` items
|format_event_data_time( $response_body ) X-Ref|
|Adds formatted date and time items for each event in an API response.|
This has to be called after the data is pulled from the cache, because
the cached events are shared by all users. If it was called before storing
the cache, then all users would see the events in the localized data/time
of the user who triggered the cache refresh, rather than their own.
param: array $response_body The response which contains the events.
return: array The response with dates and times formatted.
|trim_events( $response_body ) X-Ref|
|Prepares the event list for presentation.|
Discards expired events, and makes WordCamps "sticky." Attendees need more
advanced notice about WordCamps than they do for meetups, so camps should
appear in the list sooner. If a WordCamp is coming up, the API will "stick"
it in the response, even if it wouldn't otherwise appear. When that happens,
the event will be at the end of the list, and will need to be moved into a
higher position, so that it doesn't get trimmed off.
since: 4.9.7 Stick a WordCamp to the final list.
param: array $response_body The response body which contains the events.
return: array The response body with events trimmed.
|maybe_log_events_response( $message, $details ) X-Ref|
|Logs responses to Events API requests.|
param: string $message A description of what occurred.
param: array $details Details that provide more context for the
|Generated: Thu Jan 23 01:00:04 2020||Cross-referenced by PHPXref 0.7.1|