[wp-trac] [WordPress Trac] #53949: WP_Media_List_Table::prepare_items(): fix PHP warning

WordPress Trac noreply at wordpress.org
Thu Aug 19 12:43:17 UTC 2021


#53949: WP_Media_List_Table::prepare_items(): fix PHP warning
--------------------------------------+-----------------------------
 Reporter:  jrf                       |       Owner:  SergeyBiryukov
     Type:  defect (bug)              |      Status:  closed
 Priority:  normal                    |   Milestone:  5.9
Component:  Administration            |     Version:
 Severity:  normal                    |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------
Changes (by SergeyBiryukov):

 * owner:  (none) => SergeyBiryukov
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"51638" 51638]:
 {{{
 #!CommitTicketReference repository="" revision="51638"
 Media: Check the return type of `_get_cron_array()` in
 `WP_Media_List_Table::prepare_items()`.

 The following warnings could, in very select circumstances, be shown:
 {{{
 // PHP 8.0 and higher:
 Warning: foreach() argument must be of type array|object, bool given

 // PHP 5.6 – 7.4
 Warning: Invalid argument supplied for foreach()
 }}}

 In `WP_Media_List_Table::prepare_items()`, the cron info array is
 retrieved via a call to `_get_cron_array()`, but as the documentation
 (correctly) states, the return type of that function is `array|false`,
 where `false` is returned for a virgin site, with no cron jobs scheduled
 yet.

 However, no type check is done on the return value, and the method just
 blindly continues by using it in a `foreach`.

 Fixed by adding validation for the returned value from `_get_cron_array()`
 and only running the `foreach` when the returned value is an array.

 Reference:
 [https://developer.wordpress.org/reference/functions/_get_cron_array/
 WordPress Developer Resources: _get_cron_array()]

 Follow-up to [48417].

 Props jrf, hellofromTonya, mukesh27.
 Fixes #53949.
 }}}

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


More information about the wp-trac mailing list