WordPress.org

Make WordPress Core

Changeset 38065


Ignore:
Timestamp:
07/15/2016 03:15:23 AM (4 years ago)
Author:
joemcgill
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-editor.js

    r34254 r38065  
    5656                // Generate alt fallbacks and strip tags.
    5757                if ( 'image' === props.type && ! props.alt ) {
    58                     props.alt = props.caption || props.title || '';
     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
    5966                    props.alt = props.alt.replace( /<\/?[^>]+>/g, '' );
    6067                    props.alt = props.alt.replace( /[\r\n]+/g, ' ' );
     
    234241                options, classes, shortcode, html;
    235242
     243            props.type = 'image';
    236244            props = wp.media.string.props( props, attachment );
    237245            classes = props.classes || [];
Note: See TracChangeset for help on using the changeset viewer.