/** * Construct function * Protected to make sure it isn't declared elsewhere * * @since 1.6 * @access protected */ protected function __construct() { self::$_instance = $this; $this->vaa_store = View_Admin_As($this)->store(); if (!is_admin()) { add_action('vaa_view_admin_as_init', array($this, 'vaa_init')); } }
/** * init function to store data from the main class and enable functionality based on the current view * * @since 1.5 * @access public * @return void */ public final function load_vaa($vaa) { $this->vaa = $vaa; if (null == $vaa) { $this->vaa = View_Admin_As($this); } $this->store = $this->vaa->store(); }
/** * Store settings based on allowed settings * Also merges with the default settings * * @since 1.5 * @since 1.6 Moved to this class from main class * @access public * * @param array $settings * @param string $type global / user * @return bool */ public function store_settings($settings, $type) { if ($type == 'global') { $current = $this->get_settings(); $defaults = $this->get_defaultSettings(); $allowed = $this->get_allowedSettings(); } elseif ($type == 'user') { $current = $this->get_userSettings(); $defaults = $this->get_defaultUserSettings(); $allowed = $this->get_allowedUserSettings(); } else { return false; } if (!is_array($current)) { $current = $defaults; } foreach ($settings as $setting => $value) { // Only allow the settings when it exists in the defaults and the value exists in the allowed settings if (array_key_exists($setting, $defaults) && in_array($value, $allowed[$setting])) { $current[$setting] = $value; // Some settings need a reset if (in_array($setting, array('view_mode'))) { View_Admin_As($this)->view()->reset_view(); } } } if ($type == 'global') { $new = $this->validate_settings(wp_parse_args($current, $defaults), 'global'); return $this->update_optionData($new, 'settings', true); } elseif ($type == 'user') { $new = $this->validate_settings(wp_parse_args($current, $defaults), 'user'); return $this->update_userMeta($new, 'settings', true); } return false; }