WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#45811 closed defect (bug) (duplicate)

debug warnings generated on 404 feed

Reported by: wpmuguru Owned by:
Milestone: Priority: normal
Severity: minor Version: 5.0.2
Component: Query Keywords:
Focuses: Cc:

Description

When a site has a plugin active that use is_singular with a $post_type parameter in template_redirect (or similar hook) debug warnings of

PHP Notice: Trying to get property of non-object

when a non-existent /some-slug/feed/ url is requested.

Original discussion: https://github.com/woocommerce/woocommerce/issues/21756

Change History (2)

#1 @peterwilsoncc
2 years ago

This problem occurs because \WP_Query::is_singular() does not check if get_queried_object() returns null before checking for get_queried_object()->post_type.

Adding a check to the core function beforehand should solve the problem. I will need to check if it's needed for \WP_Query::is_single() and other related functions.

Others will know the history of is_singular() better than I, so I will leave it for someone else to decide if a fix should go into core.

---

@wpmuguru FYI: I hit this bug recently for the template_redirect hook and worked around it with the code:

<?php

if ( get_queried_object() === null && ! is_singular( 'post_type' ) ) {
    return;
}

/* Function code */

But you've probably figured that out :)

#2 @SergeyBiryukov
2 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the report, we're already tracking this issue in #29660.

Note: See TracTickets for help on using tickets.