WordPress.org

Make WordPress Core

Opened 10 months ago

Closed 10 months ago

Last modified 8 months ago

#51818 closed defect (bug) (fixed)

Invalid value in foreach in debug_data()

Reported by: paulschreiber Owned by: SergeyBiryukov
Milestone: 5.7 Priority: normal
Severity: normal Version: 5.2
Component: Site Health Keywords: has-patch
Focuses: Cc:

Description

Also filed as https://github.com/WordPress/health-check/issues/388

### Feature request/bug description

I'm seeing this warning:

Warning: Invalid argument supplied for foreach() in /home/customer/www/empirejustice.org/public_html/
wp-content/plugins/health-check/includes/class-health-check-debug-data.php on line 59

related code:

<?php
  59                 foreach ( $core_updates as $core => $update ) {
  60                         if ( 'upgrade' === $update->response ) {
  61                                 // translators: %s: Latest WordPress version number.
  62                                 $core_update_needed = ' ' . sprintf( __( '(Latest version: %s)', 'health-chec     k' ), $update->version );
  63                         } else {
  64                                 $core_update_needed = '';
  65                         }
  66                 }

Debugging, I see $core_updates is false. I suspect this is because of Siteground's own updater.

Adding an if ( is_array( $core_updates ) ) { check avoids the problem.

Change History (5)

This ticket was mentioned in Slack in #core-site-health by paulschreiber. View the logs.


10 months ago

#2 @SergeyBiryukov
10 months ago

  • Component changed from General to Site Health
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.7
  • Version set to 5.2

Thanks for the report! Introduced in [44986] / #46573.

Yes, since get_core_updates() returns false on failure, it makes sense to account for that value as well.

Moving to 5.7, as 5.6 is already in RC stage, and this does not appear to be a recent regression.

This ticket was mentioned in PR #754 on WordPress/wordpress-develop by paulschreiber.


10 months ago

  • Keywords has-patch added; needs-patch removed

#4 @SergeyBiryukov
10 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 49676:

Site Health: Check if $core_updates is an array before iterating on it.

This avoids a PHP warning if get_core_updates() returns false.

Props paulschreiber.
Fixes #51818.

Note: See TracTickets for help on using tickets.