我使用下一段代码来保存主题的选项(通过使用Wp设置API),但当我调试它时,我会得到\'Notice: Undefined index: action\' 错误/通知。
为了修复它,我在第一个$\\u请求之前添加了“isset()”。现在通知没有出现,但当我单击“保存”按钮时,选项没有保存。我做错了什么?我怎样才能修复它?提前谢谢你。
function mytheme_add_admin() {
global $themename, $options;
if ( isset( $_GET[\'page\'] ) && $_GET[\'page\'] === basename(__FILE__) ) {
if(isset( $_REQUEST["action"] ) && $_REQUEST["action"] === \'save\') {
foreach ($options as $value) {
update_option( $value[\'id\'], $_REQUEST[ $value[\'id\'] ] ); }
foreach ($options as $value) {
if( isset( $_REQUEST[ $value[\'id\'] ] ) ) { update_option( $value[\'id\'], $_REQUEST[ $value[\'id\'] ] ); } else { delete_option( $value[\'id\'] ); } }
header("Location: themes.php?page=theme-options.php&saved=true");
die;
} else if(isset( $_REQUEST["action"] ) && $_REQUEST["action"] === \'reset\') {
foreach ($options as $value) {
delete_option( $value[\'id\'] ); }
header("Location: themes.php?page=theme-options.php&reset=true");
die;
}
}
add_theme_page($themename." Options", "".$themename." Options", \'edit_themes\', basename(__FILE__), \'mytheme_admin\');
}