zedzedzed / table-of-contents-plus

https://wordpress.org/plugins/table-of-contents-plus/
GNU General Public License v2.0
53 stars 27 forks source link

fix: Trying to get property 'ID' of non-object #143

Closed jonas-hoebenreich closed 1 year ago

jonas-hoebenreich commented 3 years ago

When using TOC in a widget, post may not always be defined. To avoid a php error the plugin should abort in time.

zedzedzed commented 3 years ago

Thanks for the PR. Are you able to let me know under what conditions I can replicate the problem? Eg does it occur on special pages like 404?

jonas-hoebenreich commented 3 years ago

Hi zedzedzed, thanks for replying. Please excuse my monosyllabic PR. The error occurs when using TOC in the sidebar of the Knowledge Base overview page of Basepress (https://wordpress.org/plugins/basepress/). I honestly didn't delve deeper into the underlying reason, I was already satisfied with the fix when the error was no longer generated for every page load. Overall, I don't think it's a bad approach to always look for zero safety. Because there will probably always be some edge cases where $wp_query->post is not defined. Best regards from Munich, Jonas