WordPress.org

Make WordPress Core

Changeset 37018


Ignore:
Timestamp:
03/16/2016 05:47:41 PM (4 years ago)
Author:
ocean90
Message:

Responsive images: Skip images with a missing $image_meta['file'] value.

Props joemcgill.
See [37002].
Fixes #35480.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r37002 r37018  
    986986    $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );
    987987
    988     if ( empty( $image_meta['sizes'] ) || strlen( $image_meta['file'] ) < 4 ) {
     988    if ( empty( $image_meta['sizes'] ) || ! isset( $image_meta['file'] ) || strlen( $image_meta['file'] ) < 4 ) {
    989989        return false;
    990990    }
  • trunk/tests/phpunit/tests/media.php

    r37002 r37018  
    11851185
    11861186        // File name is incorrect
     1187        $image_meta3 = $image_meta;
     1188        $image_meta3['file'] = '/';
     1189        $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) );
     1190
     1191        // File name is incorrect
    11871192        $image_meta4 = $image_meta;
    1188         $image_meta4['file'] = '/';
     1193        unset( $image_meta4['file'] );
    11891194        $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta4 ) );
    11901195
    11911196        // Intermediate size is string instead of array.
    1192         $image_meta3 = $image_meta;
    1193         $image_meta3['sizes']['medium_large'] = '';
     1197        $image_meta5 = $image_meta;
     1198        $image_meta5['sizes']['medium_large'] = '';
    11941199        unset( $srcset[768] );
    11951200        $expected_srcset = implode( ', ', $srcset );
    1196         $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) );
     1201        $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta5 ) );
    11971202    }
    11981203
Note: See TracChangeset for help on using the changeset viewer.