[wp-trac] [WordPress Trac] #54149: Audit `get_comment()` response checks.

WordPress Trac noreply at wordpress.org
Tue Sep 21 02:14:45 UTC 2021


#54149: Audit `get_comment()` response checks.
------------------------------+-----------------------------
 Reporter:  costdev           |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Comments          |    Version:  trunk
 Severity:  normal            |   Keywords:
  Focuses:  coding-standards  |
------------------------------+-----------------------------
 There are currently 164 calls to `get_comment()` across 36 files in the
 codebase (see attached file), with more pending with at least one upcoming
 PR.

 Some of these calls check the response of `get_comment()` in one of the
 following ways:

 {{{#!php
 <?php
 $comment = get_comment( $comment_id );

 if ( $comment ) {...
 if ( ! $comment ) {...

 $comment ?...
 ! $comment ? ...

 if ( empty( $comment->comment_ID ) {...
 if ( ! empty( $comment->comment_ID ) {...
 }}}

 Some do not check the response at all. A
 [https://wordpress.slack.com/archives/C02RQBWTW/p1630738445035900
 discussion on Slack] between myself and @jrf led to the suggestion that we
 audit the use of `get_comment()`.

 @hellofromtonya suggested two alternative checks on the response:

 {{{#!php
 <?php
 if ( ! $comment instanceof WP_Comment ) {...

 if ( null === $comment ) {...
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54149>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list