我的主题有一些选项页。我在add\\u menu\\u page,add\\u submenu\\u page上做了这个。我还通过register\\u setting获得了设置,在那里我获得了add\\u settings\\u部分和add\\u settings\\u字段。字段回调函数来自一个自动生成我的字段的类。然后,我构建了一个表单回调函数(用于add\\uu(sub)menu\\u页面,如下所示。
public function render() {
$this->notify();
?>
<div class="wrap">
<div id="icon-themes" class="icon32"><br /></div>
<h2><?php echo $this->page_title; ?></h2>
<p><?php _e(\'The developer mode allows access to some of your most important rapid prototyping tools.\', MY_TEXTDOMAIN); ?></p>
<div class="postbox-container">
<div class="postbox ">
<div class="inside">
<form action="options.php" method="post">
<?php
settings_fields( MY_OPTIONS );
do_settings_sections(__FILE__);
?>
<p class="submit">
<input class="button-primary" name="Submit" type="submit" value="<?php _e(\'Save Changes\', MY_TEXTDOMAIN); ?>" />
</p>
</form>
<form method="post">
<p class="submit">
<input class="button-secondary" name="Reset" type="submit" value="<?php _e(\'reset\', MY_TEXTDOMAIN); ?>" />
<input name="action" type="hidden" value="reset" />
</p>
</form>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<?php
}
private function notify() {
if ( isset($_POST[\'save\']) ) :
?>
<div id="message" class="updated fade">
<p><?php sprintf(__(\'$1$s Options update %2$ssuccessfull%3$s.\', MY_TEXTDOMAIN), $this->name, \'<strong>\', \'</strong>\'); ?></p>
</div>
<?php
elseif ( isset($_POST[\'reset\']) ) :
delete_option( MY_OPTIONS );
?>
<div id="message" class="updated fade">
<p><?php sprintf(__(\'$1$s Options have been %2$sdeleted%3$s.\', MY_TEXTDOMAIN), $this->name, \'<strong>\', \'</strong>\'); ?></p>
</div>
<?php
endif;
}
(这都是在一节课上完成的)
我可以设置默认值,更改和保存它们,一切都很好。但有一个问题仍然存在:我无法删除我的选项,也无法将它们重置为默认值。有人知道如何做到这一点吗?谢谢