WordPress 主题开发:出现未定义索引错误

发布于 2024-09-09 03:39:51 字数 1400 浏览 3 评论 0原文

你好,我是一名 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小帐篷 2024-09-16 03:39:51
146. foreach ($options as $value) {
147.   update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }

产生此错误的代码位(上面)没有检查 $_REQUEST[ $value['id'] ] 是否存在。您收到的错误表明事实并非如此(只有在启用了完整错误检查的情况下您才会收到此通知)。代码的其他部分在使用该变量之前检查它是否存在(因此它们没问题),并且建议您应该在这里执行相同的操作。

你说你的主题在调试关闭时工作正常,所以这表明你只需要在使用它之前检查这个变量是否存在。像(替换上面的两行):

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

但是,虽然这应该可以防止你的“错误”(它们实际上只是通知),但我不熟悉wordpress主题,所以不能确定是否这是预期的行为,或者是否存在潜在的错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文