WordPress Theme development: Getting Undefined index error

hello I am a wordpress theme developer. i created a theme which works fine in WP_DEBUG=False but gets undefined index error when I set WP_DEBUG=True

My theme has an options page, whenever i click on save i get these errors:

Read More
Notice: Undefined index: ang_temp in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php  on line 147

Notice: Undefined index: ang_breadcrumbs in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php on line 147

Notice: Undefined index: ang_hide_social in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php on line 147

Notice: Undefined index: ang_hide_tw in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php on line 147

Notice: Undefined index: ang_hide_fb in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php on line 147

Notice: Undefined index: ang_hide_ms in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php on line 147

Notice: Undefined index: ang_hide_rss in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php on line 147

Warning: Cannot modify header information - headers already sent by (output started at C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php:147) in C:xampphtdocswordpresswp-contentthemesAngeliafunctions.php on line 156

Here is my themes functions.php
I don’t know what I am doing wrong. I have very very little knowledge about php. Hope guys with php knowledge or wordpress theme development knowledge can help.

Related posts

Leave a Reply

1 comment

  1. 146. foreach ($options as $value) {
    147.   update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    

    The bit of code which is producing this error (above) is not checking whether $_REQUEST[ $value['id'] ] exists. The errors you are getting suggest that it doesn’t (you will only get this notice with full error checking enabled). Other parts of your code are checking the existence of this variable before using it (so they are OK) and would suggest you should be doing the same here.

    You say your theme works OK when debug is off, so this would suggest that you only need to check the existence of this variable before using it. Something like (replacing the 2 lines above):

    foreach ($options as $value) {
      if (isset($_REQUEST[ $value['id'] ])) {
        update_option( $value['id'], $_REQUEST[ $value['id'] ] );
      }
    }
    

    However, although this should prevent your ‘errors’ (they are only notices really), I’m unfamiliar with wordpress themes so can’t say for sure whether this is expected behaviour or whether there is something underlying which is at fault.