From 630484f45321c876a295d9f4c593302fad8107dc Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Tue, 13 Nov 2012 00:32:04 +0000 Subject: [PATCH] Media: Properly insert caption shortcodes for attachments. git-svn-id: https://develop.svn.wordpress.org/trunk@22554 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/js/mce-view.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index de23ebd878..e23bfd393d 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -455,7 +455,7 @@ window.wp = window.wp || {}; }; wp.media.string.image = function( attachment, props ) { - var classes, img, options, size; + var classes, img, options, size, shortcode, html; props = _.defaults( props || {}, { img: {}, @@ -481,8 +481,9 @@ window.wp = window.wp || {}; img.height = size.height; img.src = size.url; - // Update `img` classes. - if ( props.align ) + // Only assign the align class to the image if we're not printing + // a caption, since the alignment is sent to the shortcode. + if ( props.align && ! attachment.caption ) classes.push( 'align' + props.align ); if ( props.size ) @@ -514,7 +515,26 @@ window.wp = window.wp || {}; }; } - return wp.html.string( options ); + html = wp.html.string( options ); + + // Generate the caption shortcode. + if ( attachment.caption ) { + shortcode = { + id: 'attachment_' + attachment.id, + width: img.width + }; + + if ( props.align ) + shortcode.align = 'align' + props.align; + + html = wp.shortcode.string({ + tag: 'caption', + attrs: shortcode, + content: html + ' ' + attachment.caption + }); + } + + return html; }; mceview.add( 'attachment', {