HEX
Server: Apache/2.4.65 (Debian)
System: Linux wordpress-7cb4c6b6f6-4fw4s 5.15.0-131-generic #141-Ubuntu SMP Fri Jan 10 21:18:28 UTC 2025 x86_64
User: www-data (33)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/jet-engine/includes/components/listings/components/state.php
<?php
namespace Jet_Engine\Listings\Components;

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

/**
 * Define state manager class
 */
class State {

	protected $state = [];

	protected $parents = [];

	/**
	 * Set current state
	 * 
	 * @param array $state Array of state values to set
	 */
	public function set( $state = [] ) {

		if ( ! empty( $this->state ) ) {
			$this->parents[] = $this->state;
		}

		if ( ! empty( $state['heading_text'] ) ) {
			$state['heading_text_copy'] = $state['heading_text'];
		}

		$this->state = $state;
	}

	/**
	 * Empty current state
	 * or reset to latest parent
	 */
	public function reset() {

		$initial_state = [];

		if ( ! empty( $this->parents ) ) {
			$latest_parent = count( $this->parents ) - 1;
			if ( isset( $this->parents[ $latest_parent ] ) ) {
				$initial_state = $this->parents[ $latest_parent ];
				unset( $this->parents[ $latest_parent ] );
				$this->parents = array_values( $this->parents );
			}
		}

		$this->state = $initial_state;

	}

	/**
	 * Get current component state
	 * 
	 * @return array|mixed Get current state or specific field value
	 */
	public function get( $field = null, $default = '' ) {

		if ( ! $field ) {
			return $this->state;
		}

		$field_value = isset( $this->state[ $field ] ) ? $this->state[ $field ] : $default;

		return apply_filters( 'jet-engine/listings/components/state/get', $field_value, $field, $this );

	}

}