WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 4 months ago

#43201 closed defect (bug) (fixed)

PHP Warning: count(): Parameter must be an array or an object that implements Countable in /wp-includes/media.php on line 1206

Reported by: codegrau Owned by: SergeyBiryukov
Milestone: 4.9.5 Priority: normal
Severity: normal Version: 4.9.2
Component: Media Keywords: good-first-bug has-patch fixed-major
Focuses: Cc:

Description

PHP Warning:

count(): Parameter must be an array or an object that implements Countable in /wp-includes/media.php on line 1206

Attachments (1)

43201.diff (559 bytes) - added by mrmadhat 4 months ago.

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
4 months ago

  • Component changed from General to Media
  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to 4.9.4

Hi @codegrau, welcome to WordPress Trac! Thanks for the report.

This sounds like a plugin incorrectly using the wp_calculate_image_srcset filter and returning a non-array. That said, we should make sure $sources is an array before calling count().

Last edited 4 months ago by SergeyBiryukov (previous) (diff)

This ticket was mentioned in Slack in #core-media by mike. View the logs.


4 months ago

@mrmadhat
4 months ago

#3 @mrmadhat
4 months ago

Added a patch that checks $sources is an array before calling count()

#4 @SergeyBiryukov
4 months ago

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

In 42639:

Media: Avoid a PHP warning in wp_calculate_image_srcset() if a plugin returns a non-array value via wp_calculate_image_srcset filter.

Props mrmadhat, codegrau.
Fixes #43201.

#5 @SergeyBiryukov
4 months ago

  • Keywords has-patch fixed-major added; needs-patch removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 4.9.4 consideration.

#6 @dd32
4 months ago

  • Milestone changed from 4.9.4 to 4.9.5

Bumping, 4.9.4 has been released.

#7 @SergeyBiryukov
4 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 42669:

Media: Avoid a PHP warning in wp_calculate_image_srcset() if a plugin returns a non-array value via wp_calculate_image_srcset filter.

Props mrmadhat, codegrau.
Merges [42639] to the 4.9 branch.
Fixes #43201.

Note: See TracTickets for help on using tickets.