[wp-trac] [WordPress Trac] #32072: Move link code for clarity in wp_ajax_send_attachment_to_editor() in ajax-actions.php

WordPress Trac noreply at wordpress.org
Wed Apr 22 21:53:26 UTC 2015


#32072: Move link code for clarity in wp_ajax_send_attachment_to_editor() in ajax-
actions.php
-------------------------+-----------------------------
 Reporter:  tychay       |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Media        |    Version:  4.1.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 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>';
                 }
         }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32072>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list