WP_Community_Events::get_events_transient_key()protectedWP 4.8.0

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.

Method of the class: WP_Community_Events{}

No Hooks.

Return

String|false. Transient key on success, false on failure.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_events_transient_key( $location );
$location(array) (required)
Should contain 'latitude' and 'longitude' indexes.

Changelog

Since 4.8.0 Introduced.

WP_Community_Events::get_events_transient_key() code WP 6.5.2

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;
}