[wp-trac] [WordPress Trac] #52814: Avoid notices in `get_post_comments_feed_link()`

WordPress Trac noreply at wordpress.org
Tue Jun 8 21:03:14 UTC 2021


#52814: Avoid notices in `get_post_comments_feed_link()`
-------------------------------------------------+-------------------------
 Reporter:  dd32                                 |       Owner:
                                                 |  SergeyBiryukov
     Type:  defect (bug)                         |      Status:  reviewing
 Priority:  low                                  |   Milestone:  5.8
Component:  Feeds                                |     Version:
 Severity:  trivial                              |  Resolution:
 Keywords:  has-patch has-unit-tests has-        |     Focuses:
  testing-info                                   |
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * keywords:  has-patch has-unit-tests => has-patch has-unit-tests has-
     testing-info


Comment:

 == Testing Instructions

 === Setup:

 Create a must-use file in `wp-content/mu-plugins/test.php` and paste this
 code into the file:

 {{{#!php
 <?php

 add_action( 'loop_start', function() {
     if ( is_admin() ) {
         return;
     }

     $post_id = PHP_INT_MAX;
     $link    = get_post_comments_feed_link( $post_id );
 } );
 }}}

 === Test

 - Load the home page
 - In less than PHP 8, a notice is generated. In PHP 8, a warning is
 generated like this one:

 {{{
 [08-Jun-2021 20:51:04 UTC] PHP Warning:  Attempt to read property
 "post_type" on null in /[path to your project]/wp-includes/link-
 template.php on line 752
 [08-Jun-2021 20:51:04 UTC] PHP Stack trace:
 [08-Jun-2021 20:51:04 UTC] PHP   1. {main}() /[path to your
 project]/index.php:0
 [08-Jun-2021 20:51:04 UTC] PHP   2. require() /[path to your
 project]/index.php:17
 [08-Jun-2021 20:51:04 UTC] PHP   3. require_once() /U[path to your project
 ]/wp-blog-header.php:19
 [08-Jun-2021 20:51:04 UTC] PHP   4. include() /[path to your project]/wp-
 includes/template-loader.php:106
 [08-Jun-2021 20:51:04 UTC] PHP   5. the_post() /[path to your project]/wp-
 content/themes/twentytwenty/index.php:88
 [08-Jun-2021 20:51:04 UTC] PHP   6. WP_Query->the_post() /[path to your
 project]/wp-includes/query.php:975
 [08-Jun-2021 20:51:04 UTC] PHP   7. do_action_ref_array() /[path to your
 project]/wp-includes/class-wp-query.php:3326
 [08-Jun-2021 20:51:04 UTC] PHP   8. WP_Hook->do_action() /[path to your
 project]/wp-includes/plugin.php:518
 [08-Jun-2021 20:51:04 UTC] PHP   9. WP_Hook->apply_filters() /[path to
 your project]/wp-includes/class-wp-hook.php:327
 [08-Jun-2021 20:51:04 UTC] PHP  10. {closure:/[path to your project]/wp-
 content/mu-plugins/test.php:3-10}() /[path to your project]/wp-includes
 /class-wp-hook.php:303
 [08-Jun-2021 20:51:04 UTC] PHP  11. get_post_comments_feed_link() /[path
 to your project]/wp-content/mu-plugins/test.php:9
 }}}

 - Apply the PR
 - Retest => Result: Page should render and no warning/notice generated

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52814#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list