I use the next code in order to save the options of my theme (by using the Wp Settings API), but when I debug it, I get the 'Notice: Undefined index: action' error/notification.
In order to fix it, I added "isset()" before the first $_REQUEST. Now the notification is not apperaring, but the options are not saved when I click the 'SAVE' button. What I'm doing wrong? How can I fix it? Thank you in advance.
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');
}
var_dump($_REQUEST);
at the beginning of your function. What does it output?