Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#32093 closed defect (bug) (fixed)

Inconsistent class names between get_image_tag() and wp_get_image_attachment()

Reported by: tychay's profile tychay Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: Cc:

Description

get_image_tag() generates size class attribute as size-[size], while wp_get_attachment_image() generates size class attribute as attachment-[size].

Since the former is called when inserting any image via get_image_send_to_editor(), while the latter is basically called when in plugins, post thumbnails, and the gallery shortcode, it would be best to settle on size-[size] as the likelihood of it breaking downstream code is smaller.

However at this point there are a number of plugins and themes that try to modify post thumbnails and they will break if they hook off of it. (e.g a css class modifying .attachment-thumbnails, or the mobile minileven theme in jetpack, also the site logo tool copies the improperly generated class.) So you may not want to fix this bug, or you may want to make the function generate both classes.

To understand why this is a bug, for s--ts-and-giggles, try registering sizes that have the name "meta" in many themes (the wp-admin uses that class on divs in the upload and a number of themes like twenty thirteen have modeled themselves after it), or install the Isabelle theme and register and use sizes "caption" or "desc" (they'll get centered no matter what).

Not sure it can be fixed at this point, but probably deserves a trac item so it can be searched for as a RESOLVED WONTFIX

Attachments (1)

32093.diff (569 bytes) - added by wonderboymusic 10 years ago.

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
10 years ago

  • Component changed from General to Media

#2 @wonderboymusic
10 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.4

#3 @joemcgill
10 years ago

I would prefer adding size-{size}, as the OP suggests, to wp_get_attachment_image() rather than adding attachment-{size} to get_post_image() unless there's a reason not to. Seems likely that there would potentially be less collisions with other things using .attachment-{foo} class selectors in their CSS.

#4 @wonderboymusic
10 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34629:

Add size-$size class to <img> in wp_get_attachment_image().

Fixes #32093.

#5 @wonderboymusic
10 years ago

In 34633:

After [34629], update unit tests to reflect this change.

See #32093.

#6 @wonderboymusic
10 years ago

In 34657:

After [34629], use $size_class instead of $size.

See #32093.

Note: See TracTickets for help on using tickets.