Opened 9 years ago
Closed 9 years ago
#34826 closed defect (bug) (fixed)
Links in images that link to attachment page are outputting with double rel attribute, wp_ajax_send_attachment_to_editor()
Reported by: | lucymtc | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Media | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
To reproduce bug:
- In the visual editor click on Add Media.
- Select an image from the library and from the right column select Link To: Attachment Page.
The image is sent to the editor but in the outputted code the rel attribute of the link looks like this:
rel=" rel="attachment wp-att-571835""
When the expected is:
rel="attachment wp-att-571835"
In /wp-admin/includes/media.php see the function get_image_send_to_editor(), starting on line 124:
<?php if ( ! $rel ) { $rel = ' rel="attachment wp-att-' . esc_attr( $id ) . '"'; } else { $rel = ' rel="' . esc_attr( $rel ) . '"'; }
$rel is including rel="" attribute. The problem seems to be that from the function wp_ajax_send_attachment_to_editor() in the file /wp-admin/includes/ajax-actions.php, line 2573, is also including rel="" in $rel variable.
<?php if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url ) { $rel = ' rel="attachment wp-att-' . $id . '"'; }
This is the variable passed as a parameter when calling get_image_send_to_editor()
So the solution would be to change:
$rel = ' rel="attachment wp-att-' . $id . '"';
To:
$rel = 'attachment wp-att-' . $id;
in wp_ajax_send_attachment_to_editor()
Attachments (2)
Change History (8)
Note: See
TracTickets for help on using
tickets.
Hey there,
Thanks for your report and the patch!
Looks like that was introduced in [34259] and [34260].
As you can see from that commit, the
$rel
variable is used further down like this for other attachments that aren't images, audio or video:$html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>';
So that needs to be changed as well. See my updated patch.