Make WordPress Core

Opened 12 years ago

Last modified 5 years ago

#21221 new enhancement

Image title and alt attribute content should be texturized.

Reported by: stephdau's profile stephdau Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: Media Keywords: dev-feedback has-patch
Focuses: Cc:

Description

gallery_shortcode() texturizes the caption shown underneath images in galleries.

For consistency, alt and title tags content should also be texturized.
This is also valuable for developers extending the gallery shortcode or output, such as with the WordPress.com (and Jetpack) Gallery Carousel feature, as it provides i18n'd texturization, for EG.

See attached patch, which:

  • uses wptexturize() in wp_get_attachment_image() directly (/wp-includes/media.php), which makes it work with gallries, attachment pages, etc.
  • also uses wptexturize() in get_image_tag() (/wp-includes/media.php), for consistency.
  • uses wptexturize() in wp_get_attachment_link() (/wp-includespost-template.php), for consistency

Attachments (5)

21221.diff (2.3 KB) - added by stephdau 12 years ago.
21221.2.diff (1.3 KB) - added by brianhogg 9 years ago.
patch refresh
unit_tests_21221.diff (1.1 KB) - added by welcher 9 years ago.
First pass unit test
21221.3.diff (2.5 KB) - added by adamsilverstein 9 years ago.
21221.4.diff (2.5 KB) - added by adamsilverstein 9 years ago.

Download all attachments as: .zip

Change History (23)

@stephdau
12 years ago

#1 follow-up: @toscho
12 years ago

  • Cc info@… added

Do not hard code the function, use a apply_filters() instead. See #19550.

#2 follow-up: @ericlewis
10 years ago

  • Focuses accessibility added
  • Keywords reporter-feedback dev-feedback added; has-patch removed

Why is esc_attr() not enough already? What's the benefit of wp_texturize()?

#3 in reply to: ↑ 1 @adamsilverstein
9 years ago

Replying to toscho:

Do not hard code the function, use a apply_filters() instead. See #19550.

Based on #19550 and r28715, wp_texturize already has a filter to allow you to turn it off entirely, that seems sufficient.

#4 in reply to: ↑ 2 @adamsilverstein
9 years ago

Replying to ericlewis:

Why is esc_attr() not enough already? What's the benefit of wp_texturize()?

these do different things entirely - esc_attr is security related, stripping scripts, etc. wptexturize transforms text - "quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol. "

I think would be nice to see this improved typography in alt and title tags, although I'm a bit wary of potential pitfalls or unexpected results.

@brianhogg is working on an updated patch here at #wcto. The current patch no longer applies cleanly.

@brianhogg
9 years ago

patch refresh

#5 @wonderboymusic
9 years ago

  • Keywords needs-unit-tests added; reporter-feedback dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

This should have tests to show what is not happening now and what should happen when the patch is applied.

@welcher
9 years ago

First pass unit test

#6 follow-up: @welcher
9 years ago

I've added some initial unit tests. They are my first core tests so any feedback is appreciated. I am re-using some of the data providers already in the class and if that approach makes sense, I'll go back and add the rest.

#7 in reply to: ↑ 6 @adamsilverstein
9 years ago

  • Keywords dev-feedback added; needs-unit-tests removed
  • Milestone changed from Future Release to 4.2

Looks good @welcher, I haven't seen that @dataProvider technique before, excellent.

I verified tests failed before patch and pass after...

In 21221.4.diff I refreshed @brianhogg's patch and combined with your tests, plus made some tiny code standards fixes (missing space near closing bracket of unit test functions).


Replying to welcher:

I've added some initial unit tests. They are my first core tests so any feedback is appreciated. I am re-using some of the data providers already in the class and if that approach makes sense, I'll go back and add the rest.

#8 @DrewAPicture
9 years ago

  • Keywords has-patch added

#9 @miqrogroove
9 years ago

21221.4.diff seems safe, and I have some big picture questions about it:

  • Why does an alt attribute need to be texturized?
  • Why use an HTML parser in an attribute context?
  • Is it okay to not texturize title attributes when they contain angle braces?

#10 @joedolson
9 years ago

I don't have answers for the second two questions; but for the first, the problem was for internationalization. Without texturizing, multibyte characters in attributes weren't expressed correctly.

#11 @miqrogroove
9 years ago

wptexturize is an ASCII only search and replace algorithm. What does this have to do with multibyte characters?

#12 @joedolson
9 years ago

Never mind then! I thought that was @stephdau's original intent from my prior review of this ticket, but if it's not a valid reason, then I'm not sure. I've never looked at this ticket in significant depth.

#13 @adamsilverstein
9 years ago

@stephdau: can you clarify this part: it provides i18n'd texturization, for EG

This ticket was mentioned in Slack in #core by drew. View the logs.


9 years ago

#15 @DrewAPicture
9 years ago

  • Milestone changed from 4.2 to Future Release

Looks like the feedback from @miqrogroove hasn't yet been fully addressed. Pushing to a future release.

This ticket was mentioned in Slack in #accessibility by rianrietveld. View the logs.


8 years ago

#17 @rianrietveld
8 years ago

  • Focuses accessibility removed

#18 @joedolson
8 years ago

Just did some testing with screen readers, and this doesn't have any bearing on accessibility. The characters are read correctly whether they're texturized or not. Removing accessibility focus.

Note: See TracTickets for help on using tickets.