WP_Interactivity_API::state()
Gets and/or sets the initial state of an Interactivity API store for a given namespace.
If state for that store namespace already exists, it merges the new provided state with the existing one.
When no namespace is specified, it returns the state defined for the current value in the internal namespace stack during a process_directives call.
Метод класса: WP_Interactivity_API{}
Хуков нет.
Возвращает
Массив
. The current state for the specified store namespace. This will be the updated state if a $state argument was provided.
Использование
$WP_Interactivity_API = new WP_Interactivity_API(); $WP_Interactivity_API->state( ?string $store_namespace, ?array $state ): array;
- ?string $store_namespace **
- -
По умолчанию: null - ?array $state **
- -
По умолчанию: null
Список изменений
С версии 6.5.0 | Введена. |
С версии 6.6.0 | The $store_namespace param is optional. |
Код WP_Interactivity_API::state() WP Interactivity API::state WP 6.7.1
public function state( ?string $store_namespace = null, ?array $state = null ): array { if ( ! $store_namespace ) { if ( $state ) { _doing_it_wrong( __METHOD__, __( 'The namespace is required when state data is passed.' ), '6.6.0' ); return array(); } if ( null !== $store_namespace ) { _doing_it_wrong( __METHOD__, __( 'The namespace should be a non-empty string.' ), '6.6.0' ); return array(); } if ( null === $this->namespace_stack ) { _doing_it_wrong( __METHOD__, __( 'The namespace can only be omitted during directive processing.' ), '6.6.0' ); return array(); } $store_namespace = end( $this->namespace_stack ); } if ( ! isset( $this->state_data[ $store_namespace ] ) ) { $this->state_data[ $store_namespace ] = array(); } if ( is_array( $state ) ) { $this->state_data[ $store_namespace ] = array_replace_recursive( $this->state_data[ $store_namespace ], $state ); } return $this->state_data[ $store_namespace ]; }