WordPress.org

Make WordPress Core

Changeset 23873


Ignore:
Timestamp:
03/29/2013 08:51:35 PM (9 years ago)
Author:
markjaquith
Message:

Sanity checks on image metadata to avoid warnings, etc.

fixes #23733. props wonderboymusic.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-header.php

    r23554 r23873  
    664664        } else {
    665665            $data = wp_get_attachment_metadata( $attachment_id );
    666             $height = $data[ 'height' ];
    667             $width = $data[ 'width' ];
     666            $height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0;
     667            $width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0;
    668668            unset( $data );
    669669        }
  • trunk/wp-admin/includes/image-edit.php

    r23563 r23873  
    1414    $note = '';
    1515
    16     if ( is_array($meta) && isset($meta['width']) )
     16    if ( isset( $meta['width'], $meta['height'] ) )
    1717        $big = max( $meta['width'], $meta['height'] );
    1818    else
     
    2222
    2323    $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
    24     $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig'])
    25         && $backup_sizes['full-orig']['file'] != basename($meta['file']);
     24    $can_restore = false;
     25    if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) )
     26        $can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] );
    2627
    2728    if ( $msg ) {
     
    6465    <input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
    6566    <input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
    66     <input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo $meta['width']; ?>" />
    67     <input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo $meta['height']; ?>" />
     67    <input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
     68    <input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
    6869
    6970    <div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
     
    8384        <div class="imgedit-help">
    8485        <p><?php _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that if you make the image larger it may become fuzzy.'); ?></p>
     86        <?php if ( isset( $meta['width'], $meta['height'] ) ): ?>
    8587        <p><?php printf( __('Original dimensions %s'), $meta['width'] . '&times;' . $meta['height'] ); ?></p>
     88        <?php endif ?>
    8689        <div class="imgedit-submit">
    87         <span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo $meta['width']; ?>" />&times;<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo $meta['height']; ?>" />
     90        <span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />&times;<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
    8891        <span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span></span>
    8992        <input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" />
     
    500503                    @unlink($delpath);
    501504                }
    502             } else {
     505            } elseif ( isset( $meta['width'], $meta['height'] ) ) {
    503506                $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
    504507            }
  • trunk/wp-admin/includes/media.php

    r23768 r23873  
    11281128    $media_dims = '';
    11291129    $meta = wp_get_attachment_metadata( $post->ID );
    1130     if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
     1130    if ( isset( $meta['width'], $meta['height'] ) )
    11311131        $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
    11321132    $media_dims = apply_filters( 'media_meta', $media_dims, $post );
     
    23692369    $media_dims = '';
    23702370    $meta = wp_get_attachment_metadata( $post->ID );
    2371     if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
     2371    if ( isset( $meta['width'], $meta['height'] ) )
    23722372        $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
    23732373    $media_dims = apply_filters( 'media_meta', $media_dims, $post );
  • trunk/wp-includes/media.php

    r23869 r23873  
    165165        }
    166166    }
    167     if ( !$width && !$height && isset($meta['width'], $meta['height']) ) {
     167    if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) {
    168168        // any other type: use the real image
    169169        $width = $meta['width'];
     
    781781        $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
    782782        $image_meta  = wp_get_attachment_metadata( $id );
    783         $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
     783
     784        $orientation = '';
     785        if ( isset( $image_meta['height'], $image_meta['width'] ) )
     786            $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
    784787
    785788        $output .= "<{$itemtag} class='gallery-item'>";
     
    16271630        }
    16281631
    1629         $sizes['full'] = array(
    1630             'height'      => $meta['height'],
    1631             'width'       => $meta['width'],
    1632             'url'         => $attachment_url,
    1633             'orientation' => $meta['height'] > $meta['width'] ? 'portrait' : 'landscape',
    1634         );
     1632        $sizes['full'] = array( 'url' => $attachment_url );
     1633
     1634        if ( isset( $meta['height'], $meta['width'] ) ) {
     1635            $sizes['full']['height'] = $meta['height'];
     1636            $sizes['full']['width'] = $meta['width'];
     1637            $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape';
     1638        }
    16351639
    16361640        $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
  • trunk/wp-includes/theme.php

    r23633 r23873  
    10141014        $header_images[$header_index]['url'] =  $url;
    10151015        $header_images[$header_index]['thumbnail_url'] =  $url;
    1016         $header_images[$header_index]['width'] = $header_data['width'];
    1017         $header_images[$header_index]['height'] = $header_data['height'];
     1016        if ( isset( $header_data['width'] ) )
     1017            $header_images[$header_index]['width'] = $header_data['width'];
     1018        if ( isset( $header_data['height'] ) )
     1019            $header_images[$header_index]['height'] = $header_data['height'];
    10181020    }
    10191021
Note: See TracChangeset for help on using the changeset viewer.