WordPress.org

Make WordPress Core

Changeset 22554


Ignore:
Timestamp:
11/13/2012 12:32:04 AM (7 years ago)
Author:
koopersmith
Message:

Media: Properly insert caption shortcodes for attachments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/mce-view.js

    r22537 r22554  
    456456
    457457    wp.media.string.image = function( attachment, props ) {
    458         var classes, img, options, size;
     458        var classes, img, options, size, shortcode, html;
    459459
    460460        props = _.defaults( props || {}, {
     
    482482        img.src    = size.url;
    483483
    484         // Update `img` classes.
    485         if ( props.align )
     484        // Only assign the align class to the image if we're not printing
     485        // a caption, since the alignment is sent to the shortcode.
     486        if ( props.align && ! attachment.caption )
    486487            classes.push( 'align' + props.align );
    487488
     
    515516        }
    516517
    517         return wp.html.string( options );
     518        html = wp.html.string( options );
     519
     520        // Generate the caption shortcode.
     521        if ( attachment.caption ) {
     522            shortcode = {
     523                id:    'attachment_' + attachment.id,
     524                width: img.width
     525            };
     526
     527            if ( props.align )
     528                shortcode.align = 'align' + props.align;
     529
     530            html = wp.shortcode.string({
     531                tag:     'caption',
     532                attrs:   shortcode,
     533                content: html + ' ' + attachment.caption
     534            });
     535        }
     536
     537        return html;
    518538    };
    519539
Note: See TracChangeset for help on using the changeset viewer.