Make WordPress Core

Ticket #36084: 36084.4.diff

File 36084.4.diff, 5.8 KB (added by azaozz, 9 years ago)
  • src/wp-admin/includes/ajax-actions.php

     
    25782578        $rel = '';
    25792579        $url = empty( $attachment['url'] ) ? '' : $attachment['url'];
    25802580        if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url ) {
    2581                 $rel = 'attachment wp-att-' . $id;
     2581                $rel = ' rel="attachment wp-att-' . $id . '"'; // Hard-coded string, $id is already sanitized
    25822582        }
    25832583
    25842584        remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
     
    25952595                }
    25962596
    25972597                $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    2598                 $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt );
     2598                $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
    25992599        } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post )  ) {
    26002600                $html = stripslashes_deep( $_POST['html'] );
    26012601        } else {
    26022602                $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
    26032603                if ( ! empty( $url ) ) {
    2604                         $html = '<a href="' . esc_url( $url ) . '"' . 'rel="' . esc_attr( $rel ) . '">' . $html . '</a>';
     2604                        $html = '<a href="' . esc_url( $url ) . '"' . $rel . '">' . $html . '</a>';
    26052605                }
    26062606        }
    26072607
  • src/wp-admin/includes/media.php

     
    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         $rel     Optional. Whether to add rel attribute. 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 ) . '"';
    126         } else {
    127                 $rel = ' rel="' . esc_attr( $rel ) . '"';
    128         }
     124        $rel = $rel ? ' rel="attachment wp-att-' . intval( $id ) . '"' : '';
    129125
    130126        if ( $url )
    131                 $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
     127                $html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>';
    132128
    133129        /**
    134130         * Filter the image HTML markup to send to the editor.
  • tests/phpunit/tests/media.php

     
    14811481
    14821482                $this->assertSame( $expected, $actual );
    14831483        }
     1484
     1485        /**
     1486         * @ticket 36084
     1487         */
     1488        function test_get_image_send_to_editor_defaults() {
     1489                $id      = self::$large_id;
     1490                $caption = '';
     1491                $title   = 'A test title value.';
     1492                $align   = 'left';
     1493
     1494                // Calculate attachment data (default is medium).
     1495                $attachment = wp_get_attachment_image_src( $id, 'medium' );
     1496
     1497                $html = '<img src="%1$s" alt="" width="%2$d" height="%3$d" class="align%4$s size-medium wp-image-%5$d" />';
     1498                $expected = sprintf( $html, $attachment[0], $attachment[1], $attachment[2], $align, $id );
     1499
     1500                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1501
     1502                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1503        }
     1504
     1505        /**
     1506         * @ticket 36084
     1507         */
     1508        function test_get_image_send_to_editor_defaults_with_optional_params() {
     1509                $id      = self::$large_id;
     1510                $caption = 'A test caption.';
     1511                $title   = 'A test title value.';
     1512                $align   = 'left';
     1513                $url     = get_permalink( $id );
     1514                $rel     = true;
     1515                $size    = 'thumbnail';
     1516                $alt     = 'An example alt value.';
     1517
     1518                // Calculate attachment data.
     1519                $attachment = wp_get_attachment_image_src( $id, $size );
     1520
     1521                $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>';
     1522                $html = '[caption id="attachment_%9$d" align="align%7$s" width="%5$d"]' . $html . ' %10$s[/caption]';
     1523
     1524                $expected = sprintf( $html, $url, 'attachment wp-att-' . $id, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id, $caption );
     1525
     1526                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1527        }
     1528
     1529        /**
     1530         * @ticket 36084
     1531         */
     1532        function test_get_image_send_to_editor_defaults_no_caption_no_rel() {
     1533                $id      = self::$large_id;
     1534                $caption = '';
     1535                $title   = 'A test title value.';
     1536                $align   = 'left';
     1537                $url     = get_permalink( $id );
     1538                $rel     = '';
     1539                $size    = 'thumbnail';
     1540                $alt     = 'An example alt value.';
     1541
     1542                // Calculate attachment data.
     1543                $attachment = wp_get_attachment_image_src( $id, $size );
     1544
     1545                $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>';
     1546
     1547                $expected = sprintf( $html, $url, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id );
     1548
     1549                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1550        }
    14841551}