$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - How to find error in my code when the error message is pointing to WP core file?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - How to find error in my code when the error message is pointing to WP core file?

matteradmin8PV0评论

While testing a plugin of mine with 4.5 RC of WordPress, after turning on debug in wp-config.php, I noticed an error showing up in a core WP file

Notice: Trying to get property of non-object in /wp-includes/post-template.php on line 289

Through process of elimination (turning off all other plugins until finding the message again), I am thinking this is caused by the options page of my plugin (I suppose it could be the main custom post page possibly), but there is no error message to help point me to where. The error points to a core WP file.

This error does not show up everywhere in the admin, only on certain pages such as on the main pages of Plugins, Dashboard, Users, Comments, Appearance, Settings, and on my options page itself, but oddly NOT on any other edit or post pages of my plugin or posts, or pages, or media of the site.

The code on that line in core is

if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )

and the strange thing is, my options page has no post content relation, only options, so not sure why this function (part of "get_the_content") is even being called. And since there is no more specific error message than the above, nor one that refers to a line in MY code, I am having trouble finding what part of my code could even be kicking this off.

Can someone recommend a way to troubleshoot this better? Some tool with better, more specific error reporting, or things to try to find and fix the problem? I know it is just a NOTICE, and not fatal, but I would still like to fix it if possible.

Thanks.

While testing a plugin of mine with 4.5 RC of WordPress, after turning on debug in wp-config.php, I noticed an error showing up in a core WP file

Notice: Trying to get property of non-object in /wp-includes/post-template.php on line 289

Through process of elimination (turning off all other plugins until finding the message again), I am thinking this is caused by the options page of my plugin (I suppose it could be the main custom post page possibly), but there is no error message to help point me to where. The error points to a core WP file.

This error does not show up everywhere in the admin, only on certain pages such as on the main pages of Plugins, Dashboard, Users, Comments, Appearance, Settings, and on my options page itself, but oddly NOT on any other edit or post pages of my plugin or posts, or pages, or media of the site.

The code on that line in core is

if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )

and the strange thing is, my options page has no post content relation, only options, so not sure why this function (part of "get_the_content") is even being called. And since there is no more specific error message than the above, nor one that refers to a line in MY code, I am having trouble finding what part of my code could even be kicking this off.

Can someone recommend a way to troubleshoot this better? Some tool with better, more specific error reporting, or things to try to find and fix the problem? I know it is just a NOTICE, and not fatal, but I would still like to fix it if possible.

Thanks.

Share Improve this question asked Apr 4, 2016 at 14:41 StephenStephen 9713 gold badges12 silver badges32 bronze badges 1
  • xdebug ? It must be some action/filters! – Sumit Commented Apr 4, 2016 at 15:01
Add a comment  | 

1 Answer 1

Reset to default 1

I figured out what was causing this, but it was by trial and error since there was no good debug info. And the error was in the main (custom post calling) part of my plugin, NOT in the options as I had surmised earlier. I ended up finding out that I needed to be using

'content'  => $p->post_content

in my query/foreach loop in place of

'content'  => get_the_content($p->ID)

and that the error line in the original debug (line 289) was failing on a function called "get_the_content" (ie, the one I was using), which ended up being clear after the fact (although it would have been nice if that particular line in my code had been indicated in the debug). Anyway, this would not work without a global $post variable, which caused all kinds of other content problems. But simply pulling the content directly (instead of via the get_the_content function) has solved my issue. Hope this helps someone else.

Post a comment

comment list (0)

  1. No comments so far