From 9d0f2e27d06264c1ef25faad80bd7b28ad65cb54 Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Fri, 15 Jul 2016 03:15:23 +0000 Subject: [PATCH] Media: Always add `alt` attributes to images inserted from URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when inserting an image from a URL, leaving the `alt` field blank in the media modal would result in an image being inserted into the editor without an `alt` attribute, rather than an empty `alt`. This happened because the `props.type` would not get set in `wp.media.string.props()` — because `attachment` is undefined in this case — causing the image fallbacks to get skipped. This fixes the issue by explicitly setting `props.type` to 'image' in `wp.media.string.image()` before filling out the rest of the properties. Props ambrosey, dabnpits. Fixes #36735. git-svn-id: https://develop.svn.wordpress.org/trunk@38065 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-editor.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/js/media-editor.js b/src/wp-includes/js/media-editor.js index 5bf5bd3ffa..39997feed8 100644 --- a/src/wp-includes/js/media-editor.js +++ b/src/wp-includes/js/media-editor.js @@ -55,7 +55,14 @@ fallbacks = function( props ) { // Generate alt fallbacks and strip tags. if ( 'image' === props.type && ! props.alt ) { - props.alt = props.caption || props.title || ''; + 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, ' ' ); } @@ -233,6 +240,7 @@ var img = {}, options, classes, shortcode, html; + props.type = 'image'; props = wp.media.string.props( props, attachment ); classes = props.classes || [];