0

I recently try to learn create a theme options page for my custom theme, is follow the tutorial from stackoverflow and other resource. but the script show an error

if ($_GET['page'] == basename(__FILE__)) {
    if ('save' == $_REQUEST['formaction']) {
        foreach ($options as $value) {
            if( isset( $_REQUEST[ $value['id'] ] ) ) {
                update_option( $value['id'], $_REQUEST[ $value['id'] ]  );
            }
            else {
                delete_option( $value['id'] );
            }
        }

        foreach ($spawned_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=options.php&saved=true");
        die;
    }
    else if('reset_all' == $_REQUEST['formaction']) {
        foreach ($options as $value) {
            delete_option( $value['id'] );
        }

        foreach ($spawned_options as $value) {
            delete_option( $value['id'] );
        }
        header("Location: themes.php?page=options.php&".$_REQUEST['formaction']."=true");
        die;
    }

}

I got error on this line

if ($_GET['page'] == basename(__FILE__)) {
    if ('save' == $_REQUEST['formaction']) {

The error message say "Notice: Undefined index: page ....." and "Notice: Undefined index: formaction ...."

  • don't reinvent the wheel!!!!!!!! either integrate with the cutomize4r or use the settings API. – Mark Kaplun Apr 7 '18 at 5:56
1

You need to check if those values actually exist first.

You can use isset() for this. By adding something similar to the follow at the top of your function.

if ( isset( $_GET['page'], $_REQUEST['formaction'] ) ) {
    return;
}

http://php.net/manual/en/function.isset.php

  • I have fixed it after add isset on the script. But i've got a error message on my text input area.. <br /><b>Notice</b>: get_settings is <strong>deprecated</strong> since version 2.1.0! Use get_option() instead. in <b>/home/wendy93/public_html/domain_addon/ericliputra.com/wp-includes/functions.php</b> on line <b>3839</b><br /> – GaroPpo Apr 7 '18 at 20:47
  • I think that error is pretty self explanatory. However if you still need help with it you should make a new question. If I have answered your first correctly please mark this answer as correct. – ngearing Apr 7 '18 at 21:36
  • just found the error.. I used a old script that use get_settings(), which is since version 2.1.0 the get_settings is changed to get_option().. LMAO.. So, i just changed it from get_settings() to get_option to fix the issue.. Thanks for your time and reply.. Hehe – GaroPpo Apr 9 '18 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.