Tribe__Context::get_state( array|null $fields = null, bool $whitelist = true )
Returns the current context state in a format suitable to hydrate a Redux-like store on the front-end.
Contents
This method is a filtered wrapper around the the Tribe__Context::to_array method to allow the customization of the format when producing a store-compatible state.
Parameters
- $fields
-
(array|null) (Optional) An optional whitelist or blacklist of fields to include depending on the value of the
$whitelistparameter; defaults to returning all available fields.Default value: null
- $whitelist
-
(bool) (Optional) Whether the list of fields provided in the
$fieldsparameter should be treated as a whitelist (true) or blacklist (false).Default value: true
Return
(array)
Source
File: src/Tribe/Context.php
public function get_state( array $fields = null, $whitelist = true ) {
$state = $this->to_array();
$is_global_context = tribe_context() === $this;
if ( null !== $fields ) {
$state = $whitelist
? array_intersect_key( $state, array_combine( $fields, $fields ) )
: array_diff_key( $state, array_combine( $fields, $fields ) );
}
/**
* Filters the Redux store compatible state produced from the current context.
*
* @since 4.9.5
*
* @param array $state The Redux store compatible state produced from the current context.
* @param bool $is_global_context Whether the context producing the state is the global one
* or a modified clone of it.
* @param Tribe__Context The context object producing the state.
*/
$state = apply_filters( 'tribe_context_state', $state, $is_global_context, $this );
if ( $is_global_context ) {
/**
* Filters the Redux store compatible state produced from the global context.
*
* While the `tribe_context_state` filter will apply to all contexts producing a
* state this filter will only apply to the global context.
*
* @since 4.9.5
*
* @param array $state The Redux store compatible state produced from the global context.
* @param Tribe__Context The global context object producing the state.
*/
$state = apply_filters( 'tribe_global_context_state', $state, $this );
}
return $state;
}
Changelog
| Version | Description |
|---|---|
| 4.9.5 | Introduced. |