.hide_note_suggest_activation * track.bunnycdn_signup * track.stackpath_signup */ class ConfigState { private $_data; private $_is_master; /** * Constructor */ public function __construct( $is_master ) { $this->_is_master = $is_master; if ( $is_master ) $data_raw = get_site_option( 'w3tc_state' ); else $data_raw = get_option( 'w3tc_state' ); $this->_data = @json_decode( $data_raw, true ); if ( !is_array( $this->_data ) ) { $this->_data = array(); $this->apply_defaults(); $this->save(); } } /** * Returns value * * @param string $key * @param string $default * @return mixed */ public function get( $key, $default ) { if ( !isset( $this->_data[$key] ) ) return $default; return $this->_data[$key]; } /** * Returns string value * * @param string $key * @param string $default * @param boolean $trim * @return string */ public function get_string( $key, $default = '', $trim = true ) { $value = (string)$this->get( $key, $default ); return $trim ? trim( $value ) : $value; } /** * Returns integer value * * @param string $key * @param integer $default * @return integer */ public function get_integer( $key, $default = 0 ) { return (integer)$this->get( $key, $default ); } /** * Returns boolean value * * @param string $key * @param boolean $default * @return boolean */ public function get_boolean( $key, $default = false ) { $v = $this->get( $key, $default ); if ( $v === 'false' || $v === 0 ) $v = false; return (boolean)$v; } /** * Returns array value * * @param string $key * @param array $default * @return array */ public function get_array( $key, $default = array() ) { return (array)$this->get( $key, $default ); } /** * Sets config value * * @param string $key * @param string $value * @return value set */ public function set( $key, $value ) { $this->_data[$key] = $value; } public function reset() { $this->_data = array(); $this->apply_defaults(); } /** * Saves modified config */ public function save() { if ( $this->_is_master ) update_site_option( 'w3tc_state', json_encode( $this->_data ) ); else update_option( 'w3tc_state', json_encode( $this->_data ) ); } private function apply_defaults() { $this->set( 'common.install', time() ); $this->set( 'common.install_version', W3TC_VERSION ); } }