Tribe__Context::get( string $key, mixed|null $default = null, bool $force = false )

Gets a value reading it from the location(s) defined in the `Tribe__Context::$props


Parameters

$key

(string) (Required) The key of the variable to fetch.

$default

(mixed|null) (Optional) The default value to return if not found.

Default value: null

$force

(bool) (Optional) Whether to force the re-fetch of the value from the context or not; defaults to false.

Default value: false


Top ↑

Return

(mixed) The value from the first location that can provide it or the default value if not found.


Top ↑

Source

File: src/Tribe/Context.php

	public function get( $key, $default = null, $force = false ) {
		/**
		 * Filters the value of a context variable skipping all of its logic.
		 *
		 * @since 4.9.5
		 *
		 * @param  mixed   $value    The value for the key before it's fetched from the context.
		 * @param  string  $key      The key of the value to fetch from the context.
		 * @param  mixed   $default  The default value that should be returned if the value is
		 *                           not set in the context.
		 * @param  bool    $force    Whether to force the re-fetch of the value from the context or
		 *                           not; defaults to `false`.
		 */
		$value = apply_filters( "tribe_context_pre_{$key}", null, $key, $default, $force );
		if ( null !== $value ) {
			return $value;
		}

		$value     = $default;
		$locations = $this->get_locations();

		if ( ! $force && isset( $this->request_cache[ $key ] ) ) {
			$value = $this->request_cache[ $key ];
		} elseif ( ! empty( $locations[ $key ]['read'] ) ) {
			foreach ( $locations[ $key ]['read'] as $location => $keys ) {
				$the_value = $this->$location( (array) $keys, $default );

				if ( $default !== $the_value ) {
					$value = $the_value;
					break;
				}
			}
		}

		/**
		 * Filters the value fetched from the context for a key.
		 *
		 * Useful for testing and local override.
		 *
		 * @since 4.9.5
		 *
		 * @param  mixed  $value  The value as fetched from the context.
		 */
		$value = apply_filters( "tribe_context_{$key}", $value );

		return $value;
	}

Top ↑

Changelog

Changelog
Version Description
4.9.5 Introduced.