You Do Not want to post /wp-admin/options.php from the front end , 这是个坏主意,可能会引起问题。
要从前端更新选项,只需使用update\\u option()并确保正确验证即可。下面是一个使用代码进行小修复的示例:
<?php
if (isset($_POST[\'stylesheet\']) && isset($_POST[\'action\']) && $_POST[\'action\'] == "update_theme"){
if (wp_verify_nonce($_POST[\'theme_front_end\'],\'update-options\')){
update_option(\'my_theme-style\',$_POST[\'stylesheet\']);
}else{
?><div class="error"><?php echo \'update failed\'; ?></div><?php}
}
?>
<form id="save-theme" name="save-theme" action="" method="post">
<select name="stylesheet">
<?php $selected = get_option(\'my_theme-style\');
<option>Select Theme</option>
<option value="1" <?php if ($selected == 1) echo \'selected="selected"\'; ?>>Red</option>
<option value="2" <?php if ($selected == 2) echo \'selected="selected"\'; ?>>Dark</option>
<option value="3" <?php if ($selected == 3) echo \'selected="selected"\'; ?>>White</option>
</select>
<?php wp_nonce_field(\'update-options\',\'theme_front_end\'); ?>
<input type="hidden" name="action" value="update_theme">
<input type="submit" name="update-options" value="Save">
</form>
现在,假设选项键或名称是my\\u theme-style。