1

I was moving something in my web to add a class to all my images, and now i have this message:

[15-Oct-2019 10:44:01 UTC] PHP Notice: Trying to get property 'post_title' of non-object in /home/public_html/wp-includes/nav-menu.php on line 825

[15-Oct-2019 10:44:01 UTC] PHP Notice: Trying to get property 'ID' of non-object in /home/public_html/wp-includes/nav-menu.php on line 825

[15-Oct-2019 10:44:01 UTC] PHP Notice: Trying to get property 'ID' of non-object in /home/public_html/wp-includes/nav-menu.php on line 829

What could be happen? I have made rollback but the message still appear. Is it dangerous?

10
  • Can you share with us the code referenced by those warnings? – Tom J Nowell Oct 15 '19 at 12:16
  • This is exactly the message: [15-Oct-2019 10:44:01 UTC] PHP Notice: Trying to get property 'post_title' of non-object in /home/public_html/wp-includes/nav-menu.php on line 825 [15-Oct-2019 10:44:01 UTC] PHP Notice: Trying to get property 'ID' of non-object in /home/public_html/wp-includes/nav-menu.php on line 825 [15-Oct-2019 10:44:01 UTC] PHP Notice: Trying to get property 'ID' of non-object in /home/public_html/wp-includes/nav-menu.php on line 829 – Edu Sorel Oct 15 '19 at 13:20
  • It sounds like further up the stack trace something is calling wp_nav_menu, however, line 825 of nav-menu.php doesn't reference post_title, it's a check for trashed values. Have you modified WP Core files in `wp-includes? github.com/WordPress/WordPress/blob/master/wp-includes/… – Tom J Nowell Oct 15 '19 at 13:37
  • I dont modify nothing. I just add code in my theme, I have an section to add Javascript Code. And I download the plugin Woody - Insert Header, footer. To add the code there too. But in WP-CORE or WP-includes. Nothing. – Edu Sorel Oct 15 '19 at 14:00
  • Do you think I should contact with my host and make roll-back from yesterday? – Edu Sorel Oct 15 '19 at 14:01
1

The root problem here is assumptions.

For example lets say we have an array here:

$test = [
    'foo' => 'bar'
];

If we run echo $test['foo']; we should see bar, but what if we ran echo $test['bananas'];? There is no bananas entry in that array, so PHP will notice this, throw a warning/notice similar to the one you're seeing, then fill in the missing value with '' or null.

This also happens with objects, e.g. if we take a classic post object and try to do this: echo $post->odijfnvlkdsfnvlkjdsnvkljdfnv;, we'll get a warning/notice

The same is true of your code. Most likely, the code calls an API but never checks if it was succesful, and just assumes it was. Or, a variable is misspelt.

You can check for these things with guards such as if ( !empty( ... ) ) {, or by checking return values on WP functions to see if they returned what you expected them to, or if something went wrong.

What could be happen? I have made rollback but the message still appear. Is it dangerous?

Yes and no, there are possible consequences of this, and it depends a lot on what you're doing and how it could interact. Because you're assuming the values are good when they aren't, or using things that don't exist, PHP will substitute a placeholder value. That value is a false-ish value, and might mess up your logic, or lead to unexpected situations. That could be cryptic errors, or avenues to exploit security.

The biggest issue is when PHP is configured to show these warnings on the frontend, which can break REST XMLRPC and AJAX, as well as anything that changes HTTP headers to do things

The most annoying issue though, is that debugging with a PHP error log becomes almost impossible due to the huge numbers of warnings this would generate. Anything of interest becomes buried under a deluge of notices about object properties and array keys being access that don't exist.

1
  • Thanks for the big and clear explanation. And No, the message not appear in my interfaz.That's good for me... Although I dont know if I should leave things like that. Or I could contact with my host to do roll-back. What do you say? I have unistalled the pluging that I installed, and delete the codes that I entered. But the message still appear – Edu Sorel Oct 15 '19 at 13:17
1

The properties listed in your notices are all properties of the $post object. The notices are indicating that where this is used, the $post object is not defined (i.e. it is not an existing object).

This can occur as a result of plugins/themes and/or a combination of those things, or custom code. Based on your description ("I was moving something in my web to add a class to all my images"), what you are doing may be intending to use the $post object, but it is not actually defined where you are trying to use it.

This may be as simple as applying it as a "global" variable in your code (assuming this is a code snippet). If so, try adding this:

global $post;

Or, provide some more detail on what you changed (and what you had before the change).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.