WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#34437 closed defect (bug) (fixed)

The image_downsize filter in wp_prepare_attachment_for_js throws an undefined offset notice.

Reported by: justinbusa Owned by: joemcgill
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.3.1
Component: Media Keywords: has-patch
Focuses: Cc:
PR Number:

Description

The following code in the wp_prepare_attachment_for_js function throws an undefined offset notice...

if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) {
    if ( ! $downsize[3] )
        continue;

When isset is added, the noticed goes away...

if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) {
    if ( ! isset( $downsize[3] ) )
        continue;

Attachments (2)

image_downsize.patch (503 bytes) - added by justinbusa 4 years ago.
34437.diff (577 bytes) - added by joemcgill 3 years ago.

Download all attachments as: .zip

Change History (9)

#1 @justinbusa
4 years ago

  • Keywords has-patch added

#2 @justinbusa
4 years ago

  • Keywords dev-feedback added

#3 @joemcgill
3 years ago

  • Keywords reporter-feedback added; dev-feedback removed
  • Owner set to joemcgill
  • Status changed from new to reviewing

Good catch @justinbusa. However, wouldn't using isset() there make that conditional return true if $downsize[3] were set to false through a filter on image_downsize? Perhaps using empty() would be better?

@joemcgill
3 years ago

#4 @joemcgill
3 years ago

  • Keywords reporter-feedback removed
  • Milestone changed from Awaiting Review to 4.7
  • Status changed from reviewing to accepted

34437.diff iterates on image_downsize.patch to use empty() instead of ! isset() to avoid skipping over instances where $downsize[3] has been set to false.

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


3 years ago

This ticket was mentioned in Slack in #core by helen. View the logs.


3 years ago

#7 @joemcgill
3 years ago

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

Fixed in [39107].

Note: See TracTickets for help on using tickets.