[wp-trac] [WordPress Trac] #57239: Notice undefined array keys width and height when using full svg image

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


#57239: Notice undefined array keys width and height when using full svg image
--------------------------+------------------------------
 Reporter:  joeyjanson    |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  6.1.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+------------------------------

Comment (by sabernhardt):

 The `_wp_get_image_size_from_meta()` docblock says it returns "false if
 the size isn't present in the meta data," and SVG images do not have
 `width` or `height` for full-size in the metadata. If this function is
 where the change should be made, returning `false` when the dimensions are
 not set could be more appropriate than an array of zeroes.

 {{{
 if ( ! isset( $image_meta['width'] ) || ! isset( $image_meta['height'] ) )
 {
         return false;
 }
 }}}

 However, #55247 seems to report an error when the function returns `false`
 (the function using it might have needed to account for a Boolean
 response).

 I found two uses of the function in core:
 - [https://github.com/WordPress/wordpress-
 develop/blob/ff3bb8d6d08f4e3fa75c56d53a4843662b0014d7/src/wp-
 includes/media.php#L1576 wp_calculate_image_sizes()], which checks for
 Boolean but not whether the array has missing parts
 - [https://github.com/WordPress/wordpress-
 develop/blob/5568273c2973e71f2fe9f05b8157eba57949b3f9/src/wp-
 includes/widgets/class-wp-widget-media-image.php#L218-L219 classic Image
 widget], which accounts for `empty`

 ----

 Also related to missing SVG metadata:
 - #57813 mentions `wp_get_missing_image_subsizes()` and
 `wp_image_src_get_dimensions()`.
 - The `wp_get_attachment_metadata()` function can show
 [https://wordpress.org/support/topic/php-warning-issue/#post-18048012
 notices on the image attachment pag]e when the theme template expects
 `width` and `height` in the array (if the themes need editing, that
 includes Twenty Ten to Twenty Sixteen, plus Twenty Nineteen and Twenty
 Twenty-One).

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


More information about the wp-trac mailing list