I’ve made a custom plugin, but somehow I’ve made something that fills up my debug.log
with garbage. It looks a bit like something this is faulty in the WordPress-core, but I’m not 100% sure.
Here is an extract of one of the 3 errors, that get’s repeated 5 times per page request:
PHP Notice: Trying to get property 'ID' of non-object in /wp/wp-includes/class-wp-query.php on line 4044
PHP Stack trace:
PHP 1. {main}() /index.php:0
PHP 2. require() /index.php:4
PHP 3. wp() /wp/wp-blog-header.php:16
PHP 4. WP->main() /wp/wp-includes/functions.php:1291
PHP 5. WP->parse_request() /wp/wp-includes/class-wp.php:750
PHP 6. apply_filters() /wp/wp-includes/class-wp.php:379
PHP 7. WP_Hook->apply_filters() /wp/wp-includes/plugin.php:189
PHP 8. MyCustomClass->some_method() /wp/wp-includes/class-wp-hook.php:303
PHP 9. WP_Query->is_front_page() /wp-content/plugins/my-custom-made-plugin/my-custom-made-plugin.php:115
PHP 10. WP_Query->is_page() /wp/wp-includes/class-wp-query.php:3954
How I read the error-log statement
To sum up the error, this is how I read the error-log:
—
Trace#7: WP_Hook->apply_filters() /wp/wp-includes/plugin.php:189
I register MyCustomClass
(from my Plugin) on the filter: request
, like this:
add_filter( 'request', [ $this, 'some_method' ], 1, 1 );
—
Trace#8: MyCustomClass->some_method() /wp/wp-includes/class-wp-hook.php:303
MyCustomClass->some_method()
calls is_front_page()
, like this:
public function some_method( $query ) {
$my_query = new WP_Query();
$my_query->parse_query( $query );
if ( $my_query->is_admin() || $my_query->is_home() || $my_query->is_front_page() ) {
return $query;
}
...
...
—
Trace#9: WP_Query->is_front_page() /wp-content/plugins/my-custom-made-plugin/my-custom-made-plugin.php:115
From there, the is_front_page()
is called:
WordPress Core function: https://github.com/WordPress/WordPress/blob/5.8.3/wp-includes/class-wp-query.php#L3954
—
Trace#10 WP_Query->is_page() /wp/wp-includes/class-wp-query.php:3954
Which calls is_page()
:
WordPress Core function: https://github.com/WordPress/WordPress/blob/5.8.3/wp-includes/class-wp-query.php#L4044
—
Which throws the PHP Notice: Trying to get property ‘ID’ of non-object in /wp/wp-includes/class-wp-query.php on line 4044
Since I assume there is no ID
on $page_obj
.
BUT WHY?!
Does WordPress Core lack a check, if there is an ID
on that $page_obj
or am I using the function incorrectly?
Full Debug.log extract
This is what I get in the debug.log
-file. And these below-written lines are written 5 times per page load, which is approximately 180 lines added to the debug.log
, for every page that is loaded.
PHP Notice: Trying to get property 'ID' of non-object in /wp/wp-includes/class-wp-query.php on line 4044
PHP Stack trace:
PHP 1. {main}() /index.php:0
PHP 2. require() /index.php:4
PHP 3. wp() /wp/wp-blog-header.php:16
PHP 4. WP->main() /wp/wp-includes/functions.php:1291
PHP 5. WP->parse_request() /wp/wp-includes/class-wp.php:750
PHP 6. apply_filters() /wp/wp-includes/class-wp.php:379
PHP 7. WP_Hook->apply_filters() /wp/wp-includes/plugin.php:189
PHP 8. MyCustomClass->some_method() /wp/wp-includes/class-wp-hook.php:303
PHP 9. WP_Query->is_front_page() /wp-content/plugins/my-custom-made-plugin/my-custom-made-plugin.php:115
PHP 10. WP_Query->is_page() /wp/wp-includes/class-wp-query.php:3954
PHP Notice: Trying to get property 'post_title' of non-object in /wp/wp-includes/class-wp-query.php on line 4046
PHP Stack trace:
PHP 1. {main}() /index.php:0
PHP 2. require() /index.php:4
PHP 3. wp() /wp/wp-blog-header.php:16
PHP 4. WP->main() /wp/wp-includes/functions.php:1291
PHP 5. WP->parse_request() /wp/wp-includes/class-wp.php:750
PHP 6. apply_filters() /wp/wp-includes/class-wp.php:379
PHP 7. WP_Hook->apply_filters() /wp/wp-includes/plugin.php:189
PHP 8. MyCustomClass->some_method() /wp/wp-includes/class-wp-hook.php:303
PHP 9. WP_Query->is_front_page() /wp-content/plugins/my-custom-made-plugin/my-custom-made-plugin.php:115
PHP 10. WP_Query->is_page() /wp/wp-includes/class-wp-query.php:3954
PHP Notice: Trying to get property 'post_name' of non-object in /wp/wp-includes/class-wp-query.php on line 4048
PHP Stack trace:
PHP 1. {main}() /index.php:0
PHP 2. require() /index.php:4
PHP 3. wp() /wp/wp-blog-header.php:16
PHP 4. WP->main() /wp/wp-includes/functions.php:1291
PHP 5. WP->parse_request() /wp/wp-includes/class-wp.php:750
PHP 6. apply_filters() /wp/wp-includes/class-wp.php:379
PHP 7. WP_Hook->apply_filters() /wp/wp-includes/plugin.php:189
PHP 8. MyCustomClass->some_method() /wp/wp-includes/class-wp-hook.php:303
PHP 9. WP_Query->is_front_page() /wp-content/plugins/my-custom-made-plugin/my-custom-made-plugin.php:115
PHP 10. WP_Query->is_page() /wp/wp-includes/class-wp-query.php:3954
Ideas and info
Dumping my_query
If I add a dump before calling is_front_page()
, then I can see that the method is available on that query:
public function some_method( $query ) {
$my_query = new WP_Query();
$my_query->parse_query( $query );
vardump( $my_query ); // HERE! is_front_page() is available.
if ( $my_query->is_admin() || $my_query->is_home() || $my_query->is_front_page() ) {
return $query;
}
...
...
System info
- WordPress version
5.8.3