*/ class AAM_Core_Config { /** * Core settings database option * * aam-utilities slug is used because AAM Utilities with v3.4 became a core * feature instead of independent extension. */ const OPTION = 'aam-utilities'; /** * Core config * * @var array * * @access protected */ protected static $config = array(); /** * Load core AAM settings * * @return void * * @access public */ public static function bootstrap() { // TODO: Remove in July 2019 add_filter( 'aam-configpress-compatibility-filter', 'AAM_Core_Compatibility::checkConfigPressCompatibility' ); if (is_multisite()) { self::$config = AAM_Core_Compatibility::normalizeConfigOptions( AAM_Core_API::getOption(self::OPTION, array(), 'site') ); } else { self::$config = AAM_Core_Compatibility::getConfig(); } } /** * Get config option * * @param string $option * @param mixed $default * * @return mixed * * @access public * @static */ public static function get($option, $default = null) { if (array_key_exists($option, self::$config)) { $response = self::$config[$option]; } else { $response = self::readConfigPress($option, $default); } return ($response ? self::normalize($response) : $response); } /** * Normalize config option * * @param string $setting * * @return string * * @access protected * @static */ protected static function normalize($setting) { return str_replace(array('{ABSPATH}'), array(ABSPATH), $setting); } /** * Set config * * @param string $option * @param mixed $value * * @return boolean * * @access public */ public static function set($option, $value) { self::$config[$option] = $value; //save config to database if (is_multisite()) { $result = AAM_Core_API::updateOption(self::OPTION, self::$config, 'site'); } else { $result = AAM_Core_API::updateOption(self::OPTION, self::$config); } return $result; } /** * Delete config option * * @param string $option * * @access public * @static */ public static function delete($option) { if (array_key_exists($option, self::$config)) { unset(self::$config[$option]); if (is_multisite()) { AAM_Core_API::updateOption(self::OPTION, self::$config, 'site'); } else { AAM_Core_API::updateOption(self::OPTION, self::$config); } } } /** * Get ConfigPress parameter * * @param string $param * @param mixed $default * * @return mixed * * @access public * @static */ protected static function readConfigPress($param, $default = null) { $config = AAM_Core_ConfigPress::get('aam.' . $param, $default); if (is_array($config) && isset($config['userFunc'])) { if (is_callable($config['userFunc'])) { $response = call_user_func($config['userFunc']); } else { $response = $default; } } else { $response = $config; } return $response; } }