Ticket #36084: 36084.4.diff
File 36084.4.diff, 5.8 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
2578 2578 $rel = ''; 2579 2579 $url = empty( $attachment['url'] ) ? '' : $attachment['url']; 2580 2580 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 2582 2582 } 2583 2583 2584 2584 remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' ); … … 2595 2595 } 2596 2596 2597 2597 $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 ); 2599 2599 } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) { 2600 2600 $html = stripslashes_deep( $_POST['html'] ); 2601 2601 } else { 2602 2602 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; 2603 2603 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>'; 2605 2605 } 2606 2606 } 2607 2607 -
src/wp-admin/includes/media.php
111 111 * @param string $title Image title attribute. 112 112 * @param string $align Image CSS alignment property. 113 113 * @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. 115 115 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width 116 116 * and height values in pixels (in that order). Default 'medium'. 117 117 * @param string $alt Optional. Image alt attribute. Default empty. 118 118 * @return string The HTML output to insert into the editor. 119 119 */ 120 function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = '', $size = 'medium', $alt = '' ) {120 function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) { 121 121 122 $html = get_image_tag( $id, $alt, '', $align, $size);122 $html = get_image_tag( $id, $alt, '', $align, $size ); 123 123 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 ) . '"' : ''; 129 125 130 126 if ( $url ) 131 $html = '<a href="' . esc_attr( $url) . "\"$rel>$html</a>";127 $html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>'; 132 128 133 129 /** 134 130 * Filter the image HTML markup to send to the editor. -
tests/phpunit/tests/media.php
1481 1481 1482 1482 $this->assertSame( $expected, $actual ); 1483 1483 } 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 } 1484 1551 }