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

WordPress Trac noreply at wordpress.org
Tue Sep 21 03:07:29 UTC 2021


#54149: Audit `get_comment()` response checks.
----------------------------+-------------------------------
 Reporter:  costdev         |       Owner:  (none)
     Type:  task (blessed)  |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Comments        |     Version:  trunk
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:  coding-standards
----------------------------+-------------------------------

Comment (by costdev):

 The [https://developer.wordpress.org/reference/functions/get_comment/
 Docs] state:

 > **Return**
 > (WP_Comment|array|null) Depends on $output value.

 The default is `OBJECT (WP_Comment)`.

 Should an `$output` value of `ARRAY_A` or `ARRAY_N` be supplied, I'll
 change:

 {{{#!php
 <?php

     if ( $comment instanceof WP_Comment ) {}
 }}}

 to:

 {{{#!php
 <?php

     if ( is_array( $comment ) && ! empty( $comment ) ) {}

     // Or would this be a better option to protect against
     // any current/future possible `array( false )` output?

     if ( is_array( $comment ) && ! empty( array_filter( $comment ) ) ) {}

 }}}

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


More information about the wp-trac mailing list