Ticket #34635: 34635.2.diff
File 34635.2.diff, 4.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/js/media-editor.js
diff --git src/wp-includes/js/media-editor.js src/wp-includes/js/media-editor.js index e972f6b..3852543 100644
48 48 * @returns {Object} Joined props 49 49 */ 50 50 props: function( props, attachment ) { 51 var link, linkUrl, size, sizes, fallbacks,51 var link, linkUrl, size, sizes, 52 52 defaultProps = wp.media.view.settings.defaultProps; 53 53 54 // Final fallbacks run after all processing has been completed.55 fallbacks = function( props ) {56 // Generate alt fallbacks and strip tags.57 if ( 'image' === props.type && ! props.alt ) {58 if ( props.caption ) {59 props.alt = props.caption;60 } else if ( props.title !== props.url ) {61 props.alt = props.title;62 } else {63 props.alt = '';64 }65 66 props.alt = props.alt.replace( /<\/?[^>]+>/g, '' );67 props.alt = props.alt.replace( /[\r\n]+/g, ' ' );68 }69 70 return props;71 };72 73 54 props = props ? _.clone( props ) : {}; 74 55 75 56 if ( attachment && attachment.type ) { … … 87 68 88 69 // All attachment-specific settings follow. 89 70 if ( ! attachment ) { 90 return fallbacks( props );71 return props; 91 72 } 92 73 93 74 props.title = props.title || attachment.title; … … 123 104 props.rel = props.rel || 'attachment wp-att-' + attachment.id; 124 105 } 125 106 126 return fallbacks( props );107 return props; 127 108 }, 128 109 /** 129 110 * Create link markup that is suitable for passing to the editor -
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index 7a316d1..f6c5f0f 100644
function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa 866 866 $default_attr = array( 867 867 'src' => $src, 868 868 'class' => "attachment-$size_class size-$size_class", 869 'alt' => trim( strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first869 'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ), 870 870 ); 871 if ( empty($default_attr['alt']) )872 $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption873 if ( empty($default_attr['alt']) )874 $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title875 871 876 872 $attr = wp_parse_args( $attr, $default_attr ); 877 873 -
tests/phpunit/tests/media.php
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php index b4787e6..7209f5e 100644
EOF; 916 916 } 917 917 918 918 /** 919 * Tests the default output of `wp_get_attachment_image()`. 920 * @ticket 34635 921 */ 922 function test_wp_get_attachment_image_defaults() { 923 $image = image_downsize( self::$large_id, 'thumbnail' ); 924 $expected = sprintf( '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="" />', $image[1], $image[2], $image[0] ); 925 926 $this->assertEquals( $expected, wp_get_attachment_image( self::$large_id ) ); 927 } 928 929 /** 930 * Test that `wp_get_attachment_image()` returns a proper alt value. 931 * @ticket 34635 932 */ 933 function test_wp_get_attachment_image_with_alt() { 934 // Add test alt metadata. 935 update_post_meta( self::$large_id, '_wp_attachment_image_alt', 'Some very clever alt text', true ); 936 937 $image = image_downsize( self::$large_id, 'thumbnail' ); 938 $expected = sprintf( '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="Some very clever alt text" />', $image[1], $image[2], $image[0] ); 939 940 $this->assertEquals( $expected, wp_get_attachment_image( self::$large_id ) ); 941 942 // Cleanup. 943 update_post_meta( self::$large_id, '_wp_attachment_image_alt', '', true ); 944 } 945 946 /** 919 947 * @ticket 33878 920 948 */ 921 949 function test_wp_get_attachment_image_url() { … … EOF; 1808 1836 $month = date( 'm' ); 1809 1837 1810 1838 $expected = '<img width="999" height="999" src="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-testsize-999x999.png"' . 1811 ' class="attachment-testsize size-testsize" alt=" test-image-large.png"' .1839 ' class="attachment-testsize size-testsize" alt=""' . 1812 1840 ' srcset="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-testsize-999x999.png 999w,' . 1813 1841 ' http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-large-150x150.png 150w"' . 1814 1842 ' sizes="(max-width: 999px) 100vw, 999px" />';