/** * save the settings * * @since 2.0.5 * @author jkudish * @return void */ public function save() { // some hooks do_action('tribe_settings_save'); do_action('tribe_settings_save_tab_' . $this->currentTab); // we'll need this later $parent_options = array(); /** * loop through each validated option and either * save it as is or figure out its parent option ID * (in that case, it's a serialized option array and * will be saved in the next loop) */ if (!empty($this->validated)) { foreach ($this->validated as $field_id => $validated_field) { // get the value and filter it $value = $validated_field->value; $value = apply_filters('tribe_settings_save_field_value', $value, $field_id, $validated_field); // figure out the parent option [could be set to false] and filter it if (is_network_admin()) { $parent_option = isset($validated_field->field['parent_option']) ? $validated_field->field['parent_option'] : TribeEvents::OPTIONNAMENETWORK; } if (!is_network_admin()) { $parent_option = isset($validated_field->field['parent_option']) ? $validated_field->field['parent_option'] : TribeEvents::OPTIONNAME; } $parent_option = apply_filters('tribe_settings_save_field_parent_option', $parent_option, $field_id); // some hooks do_action('tribe_settings_save_field', $field_id, $value, $validated_field); do_action('tribe_settings_save_field_' . $field_id, $value, $validated_field); if (!$parent_option) { if (is_network_admin()) { update_site_option($field_id, $value); } else { update_option($field_id, $value); } } else { // set the parent option $parent_options[$parent_option][$field_id] = $value; } } } /** * loop through parent option arrays * and save them * NOTE: in the case of the main option Tribe Options, * this will save using the TribeEvents:setOptions method. */ foreach ($parent_options as $option_id => $new_options) { // get the old options if ($option_id == TribeEvents::OPTIONNAME) { $old_options = (array) get_option($option_id); } else { $old_options = (array) get_site_option($option_id); } // set the options by parsing old + new and filter that $options = apply_filters('tribe_settings_save_option_array', wp_parse_args($new_options, $old_options), $option_id); if ($option_id == TribeEvents::OPTIONNAME) { // save using the TribeEvents method TribeEvents::setOptions($options); } elseif ($option_id == TribeEvents::OPTIONNAMENETWORK) { TribeEvents::setNetworkOptions($options); } else { // save using regular WP method if (is_network_admin()) { update_site_option($option_id, $options); } else { update_option($option_id, $options); } } } do_action('tribe_settings_after_save'); do_action('tribe_settings_after_save_' . $this->currentTab); remove_action('shutdown', array($this, 'deleteOptions')); add_option('tribe_settings_sent_data', $_POST); add_option('tribe_settings_errors', $this->errors); add_option('tribe_settings_major_error', $this->major_error); wp_redirect(add_query_arg(array('saved' => true), $this->url)); exit; }