Php 添加一个按钮以重置WordPress主题选项
我已经为WordPress主题创建了一个主题选项页面,我需要添加一个重置按钮来清除所有用户定义的主题选项设置 我听说这个功能可以完成任务Php 添加一个按钮以重置WordPress主题选项,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我已经为WordPress主题创建了一个主题选项页面,我需要添加一个重置按钮来清除所有用户定义的主题选项设置 我听说这个功能可以完成任务 function reset_mytheme_options() { remove_theme_mods(); } add_action( 'after_switch_theme', 'reset_mytheme_options' ); 但是,我不知道如何在单击按钮时运行此功能 那么,这个函数能满足我的需要吗?如果是这样的话,如何在点击按钮时运行它
function reset_mytheme_options() {
remove_theme_mods();
}
add_action( 'after_switch_theme', 'reset_mytheme_options' );
但是,我不知道如何在单击按钮时运行此功能
那么,这个函数能满足我的需要吗?如果是这样的话,如何在点击按钮时运行它?正如您提到的,您正在使用设置API,然后您可以通过这种方式实现
submit_按钮(uuu('Reset'),'secondary','Reset',false)代码>
register\u设置('option\u group'、'options\u name'、'save\u theme\u option')代码>
reset
按钮提交表单时,请检查重置请求并返回默认设置function save_theme_option($input) {
if (isset($_POST['reset'])) {
add_settings_error('settingName', 'SettingSlug', __('Your settings has been changed defualt setting.', 'text-domain'), 'updated');
return array('a' => 1, 'b' => 2); //Default settings
}
return $input;
}
正如您所提到的,您正在使用设置API,然后您可以通过这种方式实现
submit_按钮(uuu('Reset'),'secondary','Reset',false)代码>
register\u设置('option\u group'、'options\u name'、'save\u theme\u option')代码>
reset
按钮提交表单时,请检查重置请求并返回默认设置function save_theme_option($input) {
if (isset($_POST['reset'])) {
add_settings_error('settingName', 'SettingSlug', __('Your settings has been changed defualt setting.', 'text-domain'), 'updated');
return array('a' => 1, 'b' => 2); //Default settings
}
return $input;
}
您的主题选项是否使用theme_mods或Settings API?您的主题选项是否使用theme_mods或Settings API?