WordPress 主题开发:出现未定义索引错误
你好,我是一名 WordPress 主题开发人员。我创建了一个在 WP_DEBUG=False 中工作正常的主题,但当我设置 WP_DEBUG=True 时出现未定义的索引错误
我的主题有一个选项页面,每当我单击“保存”时,我都会收到这些错误:
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
这是我的主题 functions.php 我不知道我做错了什么。我对php的了解非常非常少。希望有php知识或者wordpress主题开发知识的朋友能够帮忙。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
产生此错误的代码位(上面)没有检查
$_REQUEST[ $value['id'] ]
是否存在。您收到的错误表明事实并非如此(只有在启用了完整错误检查的情况下您才会收到此通知)。代码的其他部分在使用该变量之前检查它是否存在(因此它们没问题),并且建议您应该在这里执行相同的操作。你说你的主题在调试关闭时工作正常,所以这表明你只需要在使用它之前检查这个变量是否存在。像(替换上面的两行):
但是,虽然这应该可以防止你的“错误”(它们实际上只是通知),但我不熟悉wordpress主题,所以不能确定是否这是预期的行为,或者是否存在潜在的错误。
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):
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.