[wp-trac] [WordPress Trac] #50367: Avoid layout shifting due to images not having dimension attributes

WordPress Trac noreply at wordpress.org
Thu Jul 2 18:36:41 UTC 2020


#50367: Avoid layout shifting due to images not having dimension attributes
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:  flixos90
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  5.5
Component:  Media                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  needs-testing has-patch has-unit-    |     Focuses:
  tests needs-dev-note                           |
-------------------------------------------------+-------------------------
Changes (by Otto42):

 * status:  closed => reopened
 * resolution:  fixed =>


Comment:

 Specific example:
 https://developer.wordpress.org/themes/functionality/widgets/

 The image on this page (showing a text widget) doesn't come from here, but
 from an upload to make.wordpress.org, likely where the code was
 originally. The code for that block is this:

 {{{
 <!-- wp:image {"align":"center","id":2135,"className":"wp-image-2135"} -->
 <div class="wp-block-image wp-image-2135"><figure class="aligncenter"><img
 src="https://make.wordpress.org/docs/files/2013/06/widget_visual.png"
 alt="Sample Editable Widget" class="wp-image-2135"/><figcaption>A widget
 form in the admin area.</figcaption></figure></div>
 <!-- /wp:image -->
 }}}

 The code in wp_filter_content_tags() assumes that the "wp-image-2135" is
 the attachment ID, which it is, on another site entirely.

 That gets passed as the attachment_id to
 wp_img_tag_add_width_and_height_attr(), which calls
 wp_get_attachment_metadata() with it, which will come back with no data
 because there's nothing for it to get (or worse case, come back with the
 data for a different attachment), and then that gets passed without a
 sanity check into wp_image_src_get_dimensions(). Thus, warnings generated.

 The code that gets the attachment number should at least verify that that
 is the right attachment, somehow, before taking actions using it.

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


More information about the wp-trac mailing list