Cleanup options save.

git-svn-id: http://svn.automattic.com/wordpress/trunk@3054 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-11-12 09:36:20 +00:00
parent 64948b825d
commit 3f20184aa3
8 changed files with 23 additions and 31 deletions

View File

@ -92,7 +92,7 @@ if ($action == 'retrospam') {
</fieldset>
<p class="submit">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="'default_pingback_flag','default_ping_status','default_comment_status','comments_notify','moderation_notify','comment_moderation','require_name_email','comment_whitelist','comment_max_links','moderation_keys','blacklist_keys','open_proxy_check'" />
<input type="hidden" name="page_options" value="default_pingback_flag,default_ping_status,default_comment_status,comments_notify,moderation_notify,comment_moderation,require_name_email,comment_whitelist,comment_max_links,moderation_keys,blacklist_keys,open_proxy_check" />
<input type="submit" name="Submit" value="<?php _e('Update Options') ?>" />
</p>
</form>

View File

@ -11,7 +11,7 @@ include('admin-header.php');
<h2><?php _e('General Options') ?></h2>
<form name="form1" method="post" action="options.php">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="'blogname','blogdescription','siteurl','admin_email','users_can_register','gmt_offset','date_format','time_format','home','start_of_week','comment_registration','default_role'" />
<input type="hidden" name="page_options" value="blogname,blogdescription,siteurl,admin_email,users_can_register,gmt_offset,date_format,time_format,home,start_of_week,comment_registration,default_role" />
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="top">
<th width="33%" scope="row"><?php _e('Weblog title:') ?></th>

View File

@ -63,7 +63,7 @@ echo "\n\t<option value='$i' $selected>$i</option>";
</p>
<p class="submit">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="'hack_file','use_fileupload','fileupload_realpath','fileupload_url','fileupload_allowedtypes','fileupload_maxk','fileupload_maxk','fileupload_minlevel','use_geo_positions','use_linksupdate'" />
<input type="hidden" name="page_options" value="hack_file,use_fileupload,fileupload_realpath,fileupload_url,fileupload_allowedtypes,fileupload_maxk,fileupload_maxk,fileupload_minlevel,use_geo_positions,use_linksupdate" />
<input type="submit" name="Submit" value="<?php _e('Update Options') ?> &raquo;" />
</p>
</form>

View File

@ -12,7 +12,7 @@ include('admin-header.php');
<form id="personal-options" method="post" action="options-personal-update.php">
<fieldset>
<p><?php _e('Personal options are just for you, they don&#8217;t affect other users on blog.'); ?><input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="'rich_editing'<?php do_action('personal_option_list'); ?>" /></p>
<input type="hidden" name="page_options" value="rich_editing<?php do_action('personal_option_list'); ?>" /></p>
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="top">
<th width="33%" scope="row"><?php _e('Editing:') ?></th>

View File

@ -55,7 +55,7 @@ include('admin-header.php');
</p>
<p class="submit">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="'posts_per_page','what_to_show','posts_per_rss','rss_use_excerpt','blog_charset','gzipcompression' " />
<input type="hidden" name="page_options" value="posts_per_page,what_to_show,posts_per_rss,rss_use_excerpt,blog_charset,gzipcompression" />
<input type="submit" name="Submit" value="<?php _e('Update Options') ?> &raquo;" />
</p>
</form>

View File

@ -89,7 +89,7 @@ endforeach;
<p class="submit">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="'default_post_edit_rows','use_smilies','rich_editing','ping_sites','mailserver_url', 'mailserver_port','mailserver_login','mailserver_pass','default_category','default_email_category'" />
<input type="hidden" name="page_options" value="default_post_edit_rows,use_smilies,rich_editing,ping_sites,mailserver_url,mailserver_port,mailserver_login,mailserver_pass,default_category,default_email_category" />
<input type="submit" name="Submit" value="<?php _e('Update Options') ?> &raquo;" />
</p>
</form>

View File

@ -33,40 +33,32 @@ case 'update':
if (!$_POST['page_options']) {
foreach ($_POST as $key => $value) {
$option_names[] = "'$key'";
$options[] = "'$key'";
}
$option_names = implode(',', $option_names);
} else {
$option_names = stripslashes($_POST['page_options']);
$options = explode(',', stripslashes($_POST['page_options']));
}
$options = $wpdb->get_results("SELECT $wpdb->options.option_id, option_name, option_type, option_value, option_admin_level FROM $wpdb->options WHERE option_name IN ($option_names)");
// Save for later.
$old_siteurl = get_settings('siteurl');
$old_home = get_settings('home');
// HACK
// Options that if not there have 0 value but need to be something like "closed"
$nonbools = array('default_ping_status', 'default_comment_status');
if ($options) {
$options = apply_filters( 'options_to_update' , $options );
foreach ($options as $option) {
$old_val = $option->option_value;
$new_val = trim($_POST[$option->option_name]);
if( in_array($option->option_name, $nonbools) && ( $new_val == '0' || $new_val == '') )
$new_val = 'closed';
if ($new_val !== $old_val) {
$result = $wpdb->query("UPDATE $wpdb->options SET option_value = '$new_val' WHERE option_name = '$option->option_name'");
wp_cache_set($option->option_name, $new_val, 'options');
$any_changed++;
}
// HACK
// Options that if not there have 0 value but need to be something like "closed"
$nonbools = array('default_ping_status', 'default_comment_status');
if ($options) {
foreach ($options as $option) {
$option = trim($option);
$value = trim(stripslashes($_POST[$option]));
if( in_array($option, $nonbools) && ( $value == '0' || $value == '') )
$value = 'closed';
if ( update_option($option, $value) )
$any_changed++;
}
}
unset($cache_settings); // so they will be re-read
get_settings('siteurl'); // make it happen now
} // end if options
if ($any_changed) {
if ($any_changed) {
// If siteurl or home changed, reset cookies.
if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) {
// If home changed, write rewrite rules to new location.

View File

@ -342,7 +342,7 @@ function update_option($option_name, $newvalue) {
// If the new and old values are the same, no need to update.
$oldvalue = get_option($option_name);
if ( $newvalue == $oldvalue )
return true;
return false;
if ( false === $oldvalue ) {
add_option($option_name, $newvalue);