#32072 closed enhancement (fixed)
Move link code for clarity in wp_ajax_send_attachment_to_editor() in ajax-actions.php
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.4 | Priority: | normal |
| Severity: | normal | Version: | 3.5 |
| Component: | Media | Keywords: | |
| Focuses: | Cc: |
Description
Code is called from the media library insert.
Lines 2411-2418 do nothing most of the time since $html is often overwritten:
$rel = $url = '';
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
if ( ! empty( $attachment['url'] ) ) {
$url = $attachment['url'];
if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url )
$rel = ' rel="attachment wp-att-' . $id . '"';
$html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>';
}
The code is only needed when an attachment is not an image or video. It'd be better to move it to there for more clarity (e.g. lines 24411-2431 should be replaced like so)
$url = ( empty ($attachment['url'] ) ) ? '' : $attachment['url'];
remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
$align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
$size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
$alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
$caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
$title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
$html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
} elseif ( 'video' === substr( $post->post_mime_type, 0, 5 ) || 'audio' === substr( $post->post_mime_type, 0, 5 ) ) {
$html = stripslashes_deep( $_POST['html'] );
} else {
$rel ='';
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
if ( $url ) {
if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url )
$rel = ' rel="attachment wp-att-' . $id . '"';
$html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>';
}
}
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
The above code has an error,
$relneeds to be assigned below$url:Else it will trigger a warning in the
'image'code.e.g.