protected function build_options() { // Get all options and merge them $options = $this->options_default; foreach ($this->option_keys as $option) { $db_options = $this->bridge->get_option($option); $db_options = self::normalize_options($db_options); // check for obsolete keys and remove them from db if ($obsolete_keys = array_diff_key($db_options, $this->options_default)) { foreach ($obsolete_keys as $obsolete_key => $value) { unset($db_options[$obsolete_key]); } // commit the removal $this->bridge->update_option($option, $db_options); } $options = array_merge($options, $db_options); // also check for global options if in Multi-site if (self::is_multisite()) { $db_options = $this->bridge->get_site_option($option); $db_options = self::normalize_options($db_options); $site_option_need_update = false; // merge site options into the options array, overwrite // any options with same keys $temp = array(); foreach ($db_options as $k => $o) { if (in_array($k, $this->site_options)) { $temp[$k] = $o; } else { // remove obsolete options $site_option_need_update = true; unset($db_options[$k]); } } $options = array_merge($options, $temp); if ($site_option_need_update) { $this->bridge->update_site_option($option, $temp); } } } $this->options = $options; $this->current_options = $options; }