/** * validates the config form output, fills in any gaps by using the defaults, * and ensures that arrayed items are stored as such */ function postie_validate_settings($in) { if (defined('POSTIE_DEBUG')) { var_dump($in); } $out = array(); // use the default as a template: // if a field is present in the defaults, we want to store it; otherwise we discard it $allowed_keys = get_postie_config_defaults(); foreach ($allowed_keys as $key => $default) { $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default; } // some fields are always forced to lower case: $lowercase = array('authorized_addresses', 'smtp', 'supported_file_types', 'video1types', 'video2types', 'audiotypes'); foreach ($lowercase as $field) { $out[$field] = is_array($out[$field]) ? array_map(strtolower, $out[$field]) : strtolower($out[$field]); } $arrays = get_arrayed_settings(); foreach ($arrays as $sep => $fields) { foreach ($fields as $field) { if (!is_array($out[$field])) { $out[$field] = explode($sep, trim($out[$field])); } foreach ($out[$field] as $key => $val) { $tst = trim($val); if (empty($tst)) { unset($out[$field][$key]); } else { $out[$field][$key] = $tst; } } } } UpdatePostieConfig($out); return $out; }
function activate_postie() { static $init = false; $options = get_option('postie-settings'); if ($init) { return; } if (!$options) { $options = array(); } $default_options = get_postie_config_defaults(); $old_config = array(); $updated = false; $migration = false; /* global $wpdb; $GLOBALS["table_prefix"]. "postie_config"; $result = $wpdb->get_results("SELECT label,value FROM $postietable ;"); */ $result = GetConfig(); if (is_array($result)) { foreach ($result as $key => $val) { $old_config[strtolower($key)] = $val; } } // overlay the options on top of each other: // the current value of $options takes priority over the $old_config, which takes priority over the $default_options $options = array_merge($default_options, $old_config, $options); $options = postie_validate_settings($options); update_option('postie-settings', $options); $init = true; // $wpdb->query("DROP TABLE IF EXISTS $postietable"); // safely updated options, so we can remove the old table return $options; }