[wp-trac] [WordPress Trac] #55247: SVG logos generate warnings from _wp_get_image_size_from_meta()

WordPress Trac noreply at wordpress.org
Tue Oct 1 12:12:19 UTC 2024


#55247: SVG logos generate warnings from _wp_get_image_size_from_meta()
--------------------------+------------------------------
 Reporter:  gillespieza   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  5.9
 Severity:  minor         |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Description changed by sabernhardt:

Old description:

> If I set an SVG image as my logo in the customizer, my debug log gets
> filled with the following notices:
>
> ``` PHP Notice:  Trying to access array offset on value of type bool in
> /{redacted}/wp-includes/media.php on line 1182 ```
>
> Looking at that file, that section refers to the following function:
>
> {{{#!php
> <?php
> function _wp_get_image_size_from_meta( $size_name, $image_meta ) {
>         if ( 'full' === $size_name ) {
>                 return array(
>                         absint( $image_meta['width'] ),
>                         absint( $image_meta['height'] ),
>                 );
>         } elseif ( ! empty( $image_meta['sizes'][ $size_name ] ) ) {
>                 return array(
>                         absint( $image_meta['sizes'][ $size_name
> ]['width'] ),
>                         absint( $image_meta['sizes'][ $size_name
> ]['height'] ),
>                 );
>         }
>
>         return false;
> }
> }}}
>

> I suspect what's happening here is the function is assuming there will
> always be a height and width meta, which doesn't exist with SVG file
> types.

New description:

 If I set an SVG image as my logo in the customizer, my debug log gets
 filled with the following notices:

 ` PHP Notice:  Trying to access array offset on value of type bool in
 /{redacted}/wp-includes/media.php on line 1182 `

 Looking at that file,
 [https://core.trac.wordpress.org/browser/tags/5.9/src/wp-
 includes/media.php#L1178 that section] refers to the following function:

 {{{#!php
 <?php
 function _wp_get_image_size_from_meta( $size_name, $image_meta ) {
         if ( 'full' === $size_name ) {
                 return array(
                         absint( $image_meta['width'] ),
                         absint( $image_meta['height'] ),
                 );
         } elseif ( ! empty( $image_meta['sizes'][ $size_name ] ) ) {
                 return array(
                         absint( $image_meta['sizes'][ $size_name
 ]['width'] ),
                         absint( $image_meta['sizes'][ $size_name
 ]['height'] ),
                 );
         }

         return false;
 }
 }}}


 I suspect what's happening here is the function is assuming there will
 always be a height and width meta, which doesn't exist with SVG file
 types.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55247#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list