WP_Community_Events::get_events_transient_key() WordPress Method

The WP_Community_Events::get_events_transient_key() method is used to generate a transient key for storing and retrieving community events data. This transient key is based on the current date and time, and is used to ensure that the community events data is always up-to-date.

WP_Community_Events::get_events_transient_key( array $location ) #

Generates a transient key based on user location.


Description

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.


Top ↑

Parameters

$location

(array)(Required)Should contain 'latitude' and 'longitude' indexes.


Top ↑

Return

(string|false) Transient key on success, false on failure.


Top ↑

Source

File: wp-admin/includes/class-wp-community-events.php

	protected function get_events_transient_key( $location ) {
		$key = false;

		if ( isset( $location['ip'] ) ) {
			$key = 'community-events-' . md5( $location['ip'] );
		} elseif ( isset( $location['latitude'], $location['longitude'] ) ) {
			$key = 'community-events-' . md5( $location['latitude'] . $location['longitude'] );
		}

		return $key;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.