/** * Validate all settings. * * @param array $input RAW input values. * @return array Validated input values. */ public function validate_settings($input) { /* Validate all settings before saving to the database. */ // Saving the pod setup details. if (isset($input['submit_setup'])) { $input['pod'] = trim(sanitize_text_field($input['pod']), ' /'); $input['username'] = sanitize_text_field($input['username']); $input['password'] = sanitize_text_field($input['password']); // If password is blank, it hasn't been changed. // If new password is equal to the encrypted password already saved, it was just passed again. It happens everytime update_option('wp_to_diaspora_settings') is called. if ('' === $input['password'] || $this->get_option('password') === $input['password']) { $input['password'] = $this->get_option('password'); } else { $input['password'] = WP2D_Helpers::encrypt($input['password']); } } // Saving the default options. if (isset($input['submit_defaults'])) { if (!isset($input['enabled_post_types'])) { $input['enabled_post_types'] = array(); } // Checkboxes. $this->validate_checkboxes(array('post_to_diaspora', 'fullentrylink'), $input); // Single Selects. $this->validate_single_selects('display', $input); // Multiple Selects. $this->validate_multi_selects('tags_to_post', $input); // Get unique, non-empty, trimmed tags and clean them up. $this->validate_tags($input['global_tags']); // Clean up the list of aspects. If the list is empty, only use the 'Public' aspect. $this->validate_aspects_services($input['aspects'], array('public')); // Clean up the list of services. $this->validate_aspects_services($input['services']); } // Reset to defaults. if (isset($input['reset_defaults'])) { // Set the input to the default options. $input = self::$_default_options; // Don't reset the fetched lists of pods, aspects and services. unset($input['pod_list']); unset($input['aspects_list']); unset($input['services_list']); } // Unset all unused input fields. unset($input['submit_defaults']); unset($input['reset_defaults']); unset($input['submit_setup']); // Parse inputs with default options and return. return wp_parse_args($input, array_merge(self::$_default_options, self::$_options)); }
/** * Initialise upgrade sequence. */ public function upgrade() { // Get the current options, or assign defaults. $options = WP2D_Options::instance(); $version = $options->get_option('version'); // If the versions differ, this is probably an update. Need to save updated options. if (WP2D_VERSION !== $version) { // Password is stored encrypted since version 1.2.7. // When upgrading to it, the plain text password is encrypted and saved again. if (version_compare($version, '1.2.7', '<')) { $options->set_option('password', WP2D_Helpers::encrypt((string) $options->get_option('password'))); } if (version_compare($version, '1.3.0', '<')) { // The 'user' setting is renamed to 'username'. $options->set_option('username', $options->get_option('user')); $options->set_option('user', null); // Save tags as arrays instead of comma seperated values. $global_tags = $options->get_option('global_tags'); $options->set_option('global_tags', $options->validate_tags($global_tags)); } if (version_compare($version, '1.4.0', '<')) { // Turn tags_to_post string into an array. $tags_to_post_old = $options->get_option('tags_to_post'); $tags_to_post = array_filter(array(false !== strpos($tags_to_post_old, 'g') ? 'global' : null, false !== strpos($tags_to_post_old, 'c') ? 'custom' : null, false !== strpos($tags_to_post_old, 'p') ? 'post' : null)); $options->set_option('tags_to_post', $tags_to_post); } // Update version. $options->set_option('version', WP2D_VERSION); $options->save(); } }