diff --git a/src/wp-includes/js/media-editor.js b/src/wp-includes/js/media-editor.js
index e972f6b39c..3852543aa4 100644
--- a/src/wp-includes/js/media-editor.js
+++ b/src/wp-includes/js/media-editor.js
@@ -48,28 +48,9 @@
* @returns {Object} Joined props
*/
props: function( props, attachment ) {
- var link, linkUrl, size, sizes, fallbacks,
+ var link, linkUrl, size, sizes,
defaultProps = wp.media.view.settings.defaultProps;
- // Final fallbacks run after all processing has been completed.
- fallbacks = function( props ) {
- // Generate alt fallbacks and strip tags.
- if ( 'image' === props.type && ! props.alt ) {
- if ( props.caption ) {
- props.alt = props.caption;
- } else if ( props.title !== props.url ) {
- props.alt = props.title;
- } else {
- props.alt = '';
- }
-
- props.alt = props.alt.replace( /<\/?[^>]+>/g, '' );
- props.alt = props.alt.replace( /[\r\n]+/g, ' ' );
- }
-
- return props;
- };
-
props = props ? _.clone( props ) : {};
if ( attachment && attachment.type ) {
@@ -87,7 +68,7 @@
// All attachment-specific settings follow.
if ( ! attachment ) {
- return fallbacks( props );
+ return props;
}
props.title = props.title || attachment.title;
@@ -123,7 +104,7 @@
props.rel = props.rel || 'attachment wp-att-' + attachment.id;
}
- return fallbacks( props );
+ return props;
},
/**
* Create link markup that is suitable for passing to the editor
diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index 7a316d1ecf..f6c5f0f294 100644
--- a/src/wp-includes/media.php
+++ b/src/wp-includes/media.php
@@ -866,12 +866,8 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
$default_attr = array(
'src' => $src,
'class' => "attachment-$size_class size-$size_class",
- 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first
+ 'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
);
- if ( empty($default_attr['alt']) )
- $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption
- if ( empty($default_attr['alt']) )
- $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
$attr = wp_parse_args( $attr, $default_attr );
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
index b4787e6342..7209f5e69e 100644
--- a/tests/phpunit/tests/media.php
+++ b/tests/phpunit/tests/media.php
@@ -915,6 +915,34 @@ EOF;
remove_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
}
+ /**
+ * Tests the default output of `wp_get_attachment_image()`.
+ * @ticket 34635
+ */
+ function test_wp_get_attachment_image_defaults() {
+ $image = image_downsize( self::$large_id, 'thumbnail' );
+ $expected = sprintf( '
', $image[1], $image[2], $image[0] );
+
+ $this->assertEquals( $expected, wp_get_attachment_image( self::$large_id ) );
+ }
+
+ /**
+ * Test that `wp_get_attachment_image()` returns a proper alt value.
+ * @ticket 34635
+ */
+ function test_wp_get_attachment_image_with_alt() {
+ // Add test alt metadata.
+ update_post_meta( self::$large_id, '_wp_attachment_image_alt', 'Some very clever alt text', true );
+
+ $image = image_downsize( self::$large_id, 'thumbnail' );
+ $expected = sprintf( '
', $image[1], $image[2], $image[0] );
+
+ $this->assertEquals( $expected, wp_get_attachment_image( self::$large_id ) );
+
+ // Cleanup.
+ update_post_meta( self::$large_id, '_wp_attachment_image_alt', '', true );
+ }
+
/**
* @ticket 33878
*/
@@ -1808,7 +1836,7 @@ EOF;
$month = date( 'm' );
$expected = '
';