Media: Always add `alt` attributes to images inserted from URLs
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. Built from https://develop.svn.wordpress.org/trunk@38065 git-svn-id: http://core.svn.wordpress.org/trunk@38006 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a8ccd1ce23
commit
c1e8f430f9
|
@ -55,7 +55,14 @@
|
||||||
fallbacks = function( props ) {
|
fallbacks = function( props ) {
|
||||||
// Generate alt fallbacks and strip tags.
|
// Generate alt fallbacks and strip tags.
|
||||||
if ( 'image' === props.type && ! props.alt ) {
|
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( /<\/?[^>]+>/g, '' );
|
||||||
props.alt = props.alt.replace( /[\r\n]+/g, ' ' );
|
props.alt = props.alt.replace( /[\r\n]+/g, ' ' );
|
||||||
}
|
}
|
||||||
|
@ -233,6 +240,7 @@
|
||||||
var img = {},
|
var img = {},
|
||||||
options, classes, shortcode, html;
|
options, classes, shortcode, html;
|
||||||
|
|
||||||
|
props.type = 'image';
|
||||||
props = wp.media.string.props( props, attachment );
|
props = wp.media.string.props( props, attachment );
|
||||||
classes = props.classes || [];
|
classes = props.classes || [];
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.6-beta3-38064';
|
$wp_version = '4.6-beta3-38065';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue