-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix: ensure that figure and figcaption elements have unique IDs #11940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
a556ae1
be000e7
fb96413
6fb659a
b5ebd2b
51e0a39
6cd23cb
895f84c
2181865
184e429
1738223
17a9976
270c11b
4fe064b
67f82c8
75e2121
1db8cca
cb0ac08
d6615f4
3d502ad
16708f9
1d992f0
e83167f
2ec8377
948f6d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2599,19 +2599,24 @@ function img_caption_shortcode( $attr, $content = '' ) { | |||||||||
| $describedby = ''; | ||||||||||
|
|
||||||||||
| if ( $atts['id'] ) { | ||||||||||
| $atts['id'] = sanitize_html_class( $atts['id'] ); | ||||||||||
| $id = 'id="' . esc_attr( $atts['id'] ) . '" '; | ||||||||||
| $unique_id_value = wp_unique_id( sanitize_html_class( $atts['id'] ) ); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the prefix should have
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this won't work. The counter is global. So we'd need to basically need to implement our own
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, and that's a thing!
Suggested change
|
||||||||||
| $id = 'id="' . esc_attr( $unique_id_value ) . '" '; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if ( $atts['caption_id'] ) { | ||||||||||
| // User explicitly provided a caption_id - make it unique. | ||||||||||
| $atts['caption_id'] = sanitize_html_class( $atts['caption_id'] ); | ||||||||||
| $caption_id_value = wp_unique_id( $atts['caption_id'] ); | ||||||||||
|
SteelWagstaff marked this conversation as resolved.
Outdated
|
||||||||||
| } elseif ( $atts['id'] ) { | ||||||||||
| $atts['caption_id'] = 'caption-' . str_replace( '_', '-', $atts['id'] ); | ||||||||||
| // Derive from the already-unique figure ID - guaranteed unique, no need for second call. | ||||||||||
| $caption_id_value = 'caption-' . str_replace( '_', '-', $unique_id_value ); | ||||||||||
| } else { | ||||||||||
| $caption_id_value = ''; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if ( $atts['caption_id'] ) { | ||||||||||
| $caption_id = 'id="' . esc_attr( $atts['caption_id'] ) . '" '; | ||||||||||
| $describedby = 'aria-describedby="' . esc_attr( $atts['caption_id'] ) . '" '; | ||||||||||
| if ( $caption_id_value ) { | ||||||||||
| $caption_id = 'id="' . esc_attr( $caption_id_value ) . '" '; | ||||||||||
| $describedby = 'aria-describedby="' . esc_attr( $caption_id_value ) . '" '; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.