WordPress.org

Make WordPress Core

Changeset 52217


Ignore:
Timestamp:
11/19/2021 05:54:43 PM (3 weeks ago)
Author:
audrasjb
Message:

Twenty Twenty-One: Prevent notice thrown in twenty_twenty_one_get_attachment_image_attributes().

Calling twenty_twenty_one_get_attachment_image_attributes() was causing an Undefined index: width|height notice to be thrown when the result from wp_get_attachment_metadata() does not set any value to $meta. This change adds an isset() check to prevent it.

Props wetah, hasanuzzamanshamim.
Fixes #54464.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwentyone/inc/template-functions.php

    r51875 r52217  
    458458    } elseif ( $attachment && is_object( $attachment ) && $attachment->ID ) {
    459459        $meta = wp_get_attachment_metadata( $attachment->ID );
    460         if ( $meta['width'] && $meta['height'] ) {
     460        if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) {
    461461            $width  = (int) $meta['width'];
    462462            $height = (int) $meta['height'];
Note: See TracChangeset for help on using the changeset viewer.