views:

35

answers:

1

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:

Notice: Undefined index: ang_temp in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php  on line 147

Notice: Undefined index: ang_breadcrumbs in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147

Notice: Undefined index: ang_hide_social in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147

Notice: Undefined index: ang_hide_tw in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147

Notice: Undefined index: ang_hide_fb in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147

Notice: Undefined index: ang_hide_ms in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147

Notice: Undefined index: ang_hide_rss in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php on line 147

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.php:147) in C:\xampp\htdocs\wordpress\wp-content\themes\Angelia\functions.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.

+1  A: 
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.

w3d
thank you so much that made sense. replaced the lines with your lines. and then replaced lines 149-152 with# if( isset( $_REQUEST[ $value['id'] ] ) ) {# $optionvar[$value['id']] = $_REQUEST[ $value['id']];# } else {# $optionvar[$value['id']] = null;Now works without a single error. :DThank you so much for pointing out the error cause
Towfiq
You're very welcome. You say you then replaced lines 149-152 with _that_ code. _That_ code was already there when I looked at your original script(?) and actually gave me the idea that it was probably missing from the code above which was causing your problem. If you don't mind me asking, what version of WordPress is this theme for?
w3d
that code was already there. The theme is for wordpress 3.0
Towfiq