Make WordPress Core

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's profile lucymtc Owned by: wonderboymusic's profile 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)

ajax-actions.diff (578 bytes) - added by lucymtc 9 years ago.
34826.diff (978 bytes) - added by swissspidy 9 years ago.

Download all attachments as: .zip

Change History (8)

@lucymtc
9 years ago

#1 @lucymtc
9 years ago

  • Keywords has-patch added

@swissspidy
9 years ago

#2 @swissspidy
9 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to wonderboymusic
  • Status changed from new to assigned

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.

#3 @wonderboymusic
9 years ago

  • Keywords commit added

Looks good to me.

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


9 years ago

#5 @helen
9 years ago

Don't see any side effects since this is all from trunk. Going in.

#6 @helen
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 35760:

Media: Avoid rel="rel=" situations.

props lucymtc, swissspidy.
fixes #34826. see #32074.

Note: See TracTickets for help on using tickets.