Make WordPress Core


Ignore:
Timestamp:
03/18/2016 08:04:19 PM (8 years ago)
Author:
azaozz
Message:

Media: fix erroneously inserting a rel attribute in get_image_send_to_editor(). Reverts most of [34259] and [34260] and adds a unit test.

Props joemcgill, azaozz.
Fixes #36084.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r36879 r37035  
    112112 * @param string       $align   Image CSS alignment property.
    113113 * @param string       $url     Optional. Image src URL. Default empty.
    114  * @param string       $rel     Optional. Image rel attribute. Default empty.
     114 * @param bool|string  $rel     Optional. Value for rel attribute or whether to add a dafault value. Default false.
    115115 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array of width
    116116 *                              and height values in pixels (in that order). Default 'medium'.
     
    118118 * @return string The HTML output to insert into the editor.
    119119 */
    120 function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = '', $size = 'medium', $alt = '' ) {
    121 
    122     $html = get_image_tag($id, $alt, '', $align, $size);
    123 
    124     if ( ! $rel ) {
    125         $rel = ' rel="attachment wp-att-' . esc_attr( $id ) . '"';
     120function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) {
     121
     122    $html = get_image_tag( $id, $alt, '', $align, $size );
     123
     124    if ( $rel ) {
     125        if ( is_string( $rel ) ) {
     126            $rel = ' rel="' . esc_attr( $rel ) . '"';
     127        } else {
     128            $rel = ' rel="attachment wp-att-' . intval( $id ) . '"';
     129        }
    126130    } else {
    127         $rel = ' rel="' . esc_attr( $rel ) . '"';
     131        $rel = '';
    128132    }
    129133
    130134    if ( $url )
    131         $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
     135        $html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>';
    132136
    133137    /**
     
    11671171        $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
    11681172        $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
    1169         $rel = ( $url == get_attachment_link($attachment_id) );
     1173        $rel = ( strpos( $url, 'attachment_id') || $url === get_attachment_link( $attachment_id ) );
    11701174
    11711175        return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
Note: See TracChangeset for help on using the changeset viewer.