Ticket #36084: 36084.6.diff
File 36084.6.diff, 6.2 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
2575 2575 } 2576 2576 } 2577 2577 2578 $rel = '';2578 $rel = ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url ); 2579 2579 $url = empty( $attachment['url'] ) ? '' : $attachment['url']; 2580 if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url ) {2581 $rel = 'attachment wp-att-' . $id;2582 }2583 2580 2584 2581 remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' ); 2585 2582 … … 2600 2597 $html = stripslashes_deep( $_POST['html'] ); 2601 2598 } else { 2602 2599 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; 2600 $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized 2601 2603 2602 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>'; 2605 2604 } 2606 2605 } 2607 2606 -
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|string $rel Optional. Value for rel attribute or whether to add a dafault value. 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 ) . '"'; 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 } 126 130 } else { 127 $rel = ' rel="' . esc_attr( $rel ) . '"';131 $rel = ''; 128 132 } 129 133 130 134 if ( $url ) 131 $html = '<a href="' . esc_attr( $url) . "\"$rel>$html</a>";135 $html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>'; 132 136 133 137 /** 134 138 * Filter the image HTML markup to send to the editor. … … 1166 1170 $align = !empty($attachment['align']) ? $attachment['align'] : 'none'; 1167 1171 $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium'; 1168 1172 $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 ) ); 1170 1174 1171 1175 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt); 1172 1176 } -
tests/phpunit/tests/media.php
1522 1522 1523 1523 $this->assertSame( $expected, $actual ); 1524 1524 } 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 } 1525 1592 }