Make WordPress Core

Ticket #36084: 36084.7.diff

File 36084.7.diff, 6.3 KB (added by joemcgill, 9 years ago)
  • src/wp-admin/includes/ajax-actions.php

    diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php
    index 34d179c..7df5b80 100644
    function wp_ajax_send_attachment_to_editor() { 
    25752575                }
    25762576        }
    25772577
    2578         $rel = '';
    25792578        $url = empty( $attachment['url'] ) ? '' : $attachment['url'];
    2580         if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url ) {
    2581                 $rel = 'attachment wp-att-' . $id;
    2582         }
     2579        $rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $id ) == $url );
    25832580
    25842581        remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
    25852582
    function wp_ajax_send_attachment_to_editor() { 
    26002597                $html = stripslashes_deep( $_POST['html'] );
    26012598        } else {
    26022599                $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
     2600                $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized
     2601
    26032602                if ( ! empty( $url ) ) {
    2604                         $html = '<a href="' . esc_url( $url ) . '"' . 'rel="' . esc_attr( $rel ) . '">' . $html . '</a>';
     2603                        $html = '<a href="' . esc_url( $url ) . '"' . $rel . '">' . $html . '</a>';
    26052604                }
    26062605        }
    26072606
  • src/wp-admin/includes/media.php

    diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php
    index 2f7e585..194e827 100644
    function the_media_upload_tabs() { 
    111111 * @param string       $title   Image title attribute.
    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'.
    117117 * @param string       $alt     Optional. Image alt attribute. Default empty.
    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 = '' ) {
     120function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) {
    121121
    122         $html = get_image_tag($id, $alt, '', $align, $size);
     122        $html = get_image_tag( $id, $alt, '', $align, $size );
    123123
    124         if ( ! $rel ) {
    125                 $rel = ' rel="attachment wp-att-' . esc_attr( $id ) . '"';
     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        /**
    134138         * Filter the image HTML markup to send to the editor.
    function image_media_send_to_editor($html, $attachment_id, $attachment) { 
    11661170                $align = !empty($attachment['align']) ? $attachment['align'] : 'none';
    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);
    11721176        }
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index a58360a..5d72984 100644
    EOF; 
    15221522
    15231523                $this->assertSame( $expected, $actual );
    15241524        }
     1525
     1526        /**
     1527         * @ticket 36084
     1528         */
     1529        function test_get_image_send_to_editor_defaults() {
     1530                $id      = self::$large_id;
     1531                $caption = '';
     1532                $title   = 'A test title value.';
     1533                $align   = 'left';
     1534
     1535                // Calculate attachment data (default is medium).
     1536                $attachment = wp_get_attachment_image_src( $id, 'medium' );
     1537
     1538                $html = '<img src="%1$s" alt="" width="%2$d" height="%3$d" class="align%4$s size-medium wp-image-%5$d" />';
     1539                $expected = sprintf( $html, $attachment[0], $attachment[1], $attachment[2], $align, $id );
     1540
     1541                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1542
     1543                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1544        }
     1545
     1546        /**
     1547         * @ticket 36084
     1548         */
     1549        function test_get_image_send_to_editor_defaults_with_optional_params() {
     1550                $id      = self::$large_id;
     1551                $caption = 'A test caption.';
     1552                $title   = 'A test title value.';
     1553                $align   = 'left';
     1554                $url     = get_permalink( $id );
     1555                $rel     = true;
     1556                $size    = 'thumbnail';
     1557                $alt     = 'An example alt value.';
     1558
     1559                // Calculate attachment data.
     1560                $attachment = wp_get_attachment_image_src( $id, $size );
     1561
     1562                $html = '<a href="%1$s" rel="%2$s"><img src="%3$s" alt="%4$s" width="%5$d" height="%6$d" class="size-%8$s wp-image-%9$d" /></a>';
     1563                $html = '[caption id="attachment_%9$d" align="align%7$s" width="%5$d"]' . $html . ' %10$s[/caption]';
     1564
     1565                $expected = sprintf( $html, $url, 'attachment wp-att-' . $id, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id, $caption );
     1566
     1567                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1568        }
     1569
     1570        /**
     1571         * @ticket 36084
     1572         */
     1573        function test_get_image_send_to_editor_defaults_no_caption_no_rel() {
     1574                $id      = self::$large_id;
     1575                $caption = '';
     1576                $title   = 'A test title value.';
     1577                $align   = 'left';
     1578                $url     = get_permalink( $id );
     1579                $rel     = '';
     1580                $size    = 'thumbnail';
     1581                $alt     = 'An example alt value.';
     1582
     1583                // Calculate attachment data.
     1584                $attachment = wp_get_attachment_image_src( $id, $size );
     1585
     1586                $html = '<a href="%1$s"><img src="%2$s" alt="%3$s" width="%4$d" height="%5$d" class="align%6$s size-%7$s wp-image-%8$d" /></a>';
     1587
     1588                $expected = sprintf( $html, $url, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id );
     1589
     1590                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1591        }
    15251592}