Opened 12 years ago
Last modified 6 years ago
#21221 new enhancement
Image title and alt attribute content should be texturized.
Reported by: | 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)
Change History (23)
#2
follow-up:
↓ 4
@
11 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()
?
#4
in reply to:
↑ 2
@
10 years ago
Replying to ericlewis:
Why is
esc_attr()
not enough already? What's the benefit ofwp_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.
#5
@
10 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.
#6
follow-up:
↓ 7
@
10 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
@
10 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.
#9
@
10 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
@
10 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
@
10 years ago
wptexturize is an ASCII only search and replace algorithm. What does this have to do with multibyte characters?
#12
@
10 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.
This ticket was mentioned in Slack in #core by drew. View the logs.
10 years ago
#15
@
10 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.
Do not hard code the function, use a
apply_filters()
instead. See #19550.