<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[20679] trunk: Change the image caption shortcode format to [caption ...]&lt;a&gt;&lt;img /&gt;&lt;/a&gt; caption text + html[/caption].</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/20679">20679</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2012-05-02 01:14:52 +0000 (Wed, 02 May 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Change the image caption shortcode format to [caption ...]&lt;a&gt;&lt;img /&gt;&lt;/a&gt; caption text + html[/caption]. That way HTML tags in captions are better supported and the shortcode wouldn't break when using the wrong quotes. Props  sushkov, nacin, fixes <a href="http://core.trac.wordpress.org/ticket/18311">#18311</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpadminjseditordevjs">trunk/wp-admin/js/editor.dev.js</a></li>
<li><a href="#trunkwpincludesjstinymcepluginswpeditimageeditor_plugin_srcjs">trunk/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js</a></li>
<li><a href="#trunkwpincludesjstinymcepluginswpeditimagejseditimagedevjs">trunk/wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.dev.js</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (20678 => 20679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2012-05-01 22:58:23 UTC (rev 20678)
+++ trunk/wp-admin/includes/media.php        2012-05-02 01:14:52 UTC (rev 20679)
</span><span class="lines">@@ -145,14 +145,14 @@
</span><span class="cx"> 
</span><span class="cx">         $caption = str_replace( array(&quot;\r\n&quot;, &quot;\r&quot;), &quot;\n&quot;, $caption);
</span><span class="cx">         $caption = preg_replace_callback( '/&lt;[a-zA-Z0-9]+(?: [^&lt;&gt;]+&gt;)*/', '_cleanup_image_add_caption', $caption );
</span><del>-        $caption = preg_replace( '/\n+/', '&lt;br /&gt;', str_replace('&quot;', '&amp;quot;', $caption) );
</del><ins>+        // convert any remaining line breaks to &lt;br&gt;
+        $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '&lt;br /&gt;', $caption );
</ins><span class="cx"> 
</span><span class="cx">         $html = preg_replace( '/(class=[&quot;\'][^\'&quot;]*)align(none|left|right|center)\s?/', '$1', $html );
</span><span class="cx">         if ( empty($align) )
</span><span class="cx">                 $align = 'none';
</span><span class="cx"> 
</span><del>-        $shcode = '[caption id=&quot;' . $id . '&quot; align=&quot;align' . $align
-        . '&quot; width=&quot;' . $width . '&quot; caption=&quot;' . $caption . '&quot;]' . $html . '[/caption]';
</del><ins>+        $shcode = '[caption id=&quot;' . $id . '&quot; align=&quot;align' . $align        . '&quot; width=&quot;' . $width . '&quot;]' . $html . ' ' . $caption . '[/caption]';
</ins><span class="cx"> 
</span><span class="cx">         return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
</span><span class="cx"> }
</span><span class="lines">@@ -166,23 +166,10 @@
</span><span class="cx">  */
</span><span class="cx"> function _cleanup_image_add_caption( $matches ) {
</span><span class="cx">         // remove any line breaks from inside the tags
</span><del>-        $s = preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
-        // look for single quotes inside html attributes (for example in title)
-        $s = preg_replace_callback( '/=&quot;[^&quot;]+&quot;/', '_cleanup_image_add_caption_callback', $s );
-        return str_replace( '&quot;', &quot;'&quot;, $s );
</del><ins>+        return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Private preg_replace callback used in _cleanup_image_add_caption()
- *
- * @access private
- * @since 3.4.0
- */
-function _cleanup_image_add_caption_callback( $matches ) {
-        return str_replace( &quot;'&quot;, '&amp;#39;', $matches[0] );
-}
-
-/**
</del><span class="cx">  * {@internal Missing Short Description}}
</span><span class="cx">  *
</span><span class="cx">  * @since 2.5.0
</span><span class="lines">@@ -1541,13 +1528,10 @@
</span><span class="cx">                 if ( f.caption.value ) {
</span><span class="cx">                         caption = f.caption.value.replace(/\r\n|\r/g, '\n');
</span><span class="cx">                         caption = caption.replace(/&lt;[a-zA-Z0-9]+( [^&lt;&gt;]+)?&gt;/g, function(a){
</span><del>-                                a = a.replace(/[\r\n\t]+/, ' ').replace(/=&quot;[^&quot;]+&quot;/, function(b){
-                                        return b.replace(/'/g, '&amp;#39;');
-                                });
-                                return a.replace(/&quot;/g, &quot;'&quot;);
</del><ins>+                                return a.replace(/[\r\n\t]+/, ' ');
</ins><span class="cx">                         });
</span><span class="cx"> 
</span><del>-                        caption = caption.replace(/\n+/g, '&lt;br /&gt;').replace(/&quot;/g, '&amp;quot;');
</del><ins>+                        caption = caption.replace(/\s*\n\s*/g, '&lt;br /&gt;');
</ins><span class="cx">                 }
</span><span class="cx"> &lt;?php } ?&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -1561,7 +1545,7 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( caption )
</span><del>-                        html = '[caption id=&quot;&quot; align=&quot;'+t.align+'&quot; width=&quot;'+t.width+'&quot; caption=&quot;'+caption+'&quot;]'+html+'[/caption]';
</del><ins>+                        html = '[caption id=&quot;&quot; align=&quot;'+t.align+'&quot; width=&quot;'+t.width+'&quot;]'+html+caption+'[/caption]';
</ins><span class="cx"> 
</span><span class="cx">                 var win = window.dialogArguments || opener || parent || top;
</span><span class="cx">                 win.send_to_editor(html);
</span></span></pre></div>
<a id="trunkwpadminjseditordevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/editor.dev.js (20678 => 20679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/editor.dev.js        2012-05-01 22:58:23 UTC (rev 20678)
+++ trunk/wp-admin/js/editor.dev.js        2012-05-02 01:14:52 UTC (rev 20679)
</span><span class="lines">@@ -73,11 +73,11 @@
</span><span class="cx">                         });
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                // keep &lt;br&gt; tags inside captions
</del><ins>+                // keep &lt;br&gt; tags inside captions and remove line breaks
</ins><span class="cx">                 if ( content.indexOf('[caption') != -1 ) {
</span><span class="cx">                         preserve_br = true;
</span><del>-                        content = content.replace(/\[caption[^\]]+\]/g, function(a) {
-                                return a.replace(/&lt;br([^&gt;]*)&gt;[\r\n]*/g, '&lt;wp-temp-br$1&gt;');
</del><ins>+                        content = content.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) {
+                                return a.replace(/&lt;br([^&gt;]*)&gt;/g, '&lt;wp-temp-br$1&gt;').replace(/[\r\n\t]+/, '');
</ins><span class="cx">                         });
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -139,7 +139,8 @@
</span><span class="cx">         },
</span><span class="cx"> 
</span><span class="cx">         _wp_Autop : function(pee) {
</span><del>-                var blocklist = 'table|thead|tfoot|tbody|tr|td|th|caption|col|colgroup|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]|fieldset|legend|hr|noscript|menu|samp|header|footer|article|section|hgroup|nav|aside|details|summary';
</del><ins>+                var preserve_linebreaks = false, preserve_br = false,
+                        blocklist = 'table|thead|tfoot|tbody|tr|td|th|caption|col|colgroup|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]|fieldset|legend|hr|noscript|menu|samp|header|footer|article|section|hgroup|nav|aside|details|summary';
</ins><span class="cx"> 
</span><span class="cx">                 if ( pee.indexOf('&lt;object') != -1 ) {
</span><span class="cx">                         pee = pee.replace(/&lt;object[\s\S]+?&lt;\/object&gt;/g, function(a){
</span><span class="lines">@@ -153,11 +154,27 @@
</span><span class="cx"> 
</span><span class="cx">                 // Protect pre|script tags
</span><span class="cx">                 if ( pee.indexOf('&lt;pre') != -1 || pee.indexOf('&lt;script') != -1 ) {
</span><ins>+                        preserve_linebreaks = true;
</ins><span class="cx">                         pee = pee.replace(/&lt;(pre|script)[^&gt;]*&gt;[\s\S]+?&lt;\/\1&gt;/g, function(a) {
</span><del>-                                return a.replace(/(\r\n|\n)/g, '&lt;wp_temp_br&gt;');
</del><ins>+                                return a.replace(/(\r\n|\n)/g, '&lt;wp-temp-lb&gt;');
</ins><span class="cx">                         });
</span><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+                // keep &lt;br&gt; tags inside captions and convert line breaks
+                if ( pee.indexOf('[caption') != -1 ) {
+                        preserve_br = true;
+                        pee = pee.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) {
+                                // keep existing &lt;br&gt;
+                                a = a.replace(/&lt;br([^&gt;]*)&gt;/g, '&lt;wp-temp-br$1&gt;');
+                                // no line breaks inside HTML tags
+                                a = a.replace(/&lt;[a-zA-Z0-9]+( [^&lt;&gt;]+)?&gt;/g, function(b){
+                                        return b.replace(/[\r\n\t]+/, ' ');
+                                });
+                                // convert remaining line breaks to &lt;br&gt;
+                                return a.replace(/\s*\n\s*/g, '&lt;wp-temp-br /&gt;');
+                        });
+                }
+
</ins><span class="cx">                 pee = pee + '\n\n';
</span><span class="cx">                 pee = pee.replace(/&lt;br \/&gt;\s*&lt;br \/&gt;/gi, '\n\n');
</span><span class="cx">                 pee = pee.replace(new RegExp('(&lt;(?:'+blocklist+')(?: [^&gt;]*)?&gt;)', 'gi'), '\n$1');
</span><span class="lines">@@ -186,8 +203,12 @@
</span><span class="cx">                 });
</span><span class="cx"> 
</span><span class="cx">                 // put back the line breaks in pre|script
</span><del>-                pee = pee.replace(/&lt;wp_temp_br&gt;/g, '\n');
</del><ins>+                if ( preserve_linebreaks )
+                        pee = pee.replace(/&lt;wp-temp-lb&gt;/g, '\n');
</ins><span class="cx"> 
</span><ins>+                if ( preserve_br )
+                        pee = pee.replace(/&lt;wp-temp-br([^&gt;]*)&gt;/g, '&lt;br$1&gt;');
+
</ins><span class="cx">                 return pee;
</span><span class="cx">         },
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesjstinymcepluginswpeditimageeditor_plugin_srcjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js (20678 => 20679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js        2012-05-01 22:58:23 UTC (rev 20678)
+++ trunk/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js        2012-05-02 01:14:52 UTC (rev 20679)
</span><span class="lines">@@ -139,7 +139,7 @@
</span><span class="cx"> 
</span><span class="cx">                 _do_shcode : function(content) {
</span><span class="cx">                         return content.replace(/(?:&lt;p&gt;)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:&lt;\/p&gt;)?/g, function(a,b,c){
</span><del>-                                var id, cls, w, cap, div_cls;
</del><ins>+                                var id, cls, w, cap, div_cls, img, trim = tinymce.trim;
</ins><span class="cx"> 
</span><span class="cx">                                 id = b.match(/id=['&quot;]([^'&quot;]*)['&quot;] ?/);
</span><span class="cx">                                 b = b.replace(id[0], '');
</span><span class="lines">@@ -150,8 +150,18 @@
</span><span class="cx">                                 w = b.match(/width=['&quot;]([0-9]*)['&quot;] ?/);
</span><span class="cx">                                 b = b.replace(w[0], '');
</span><span class="cx"> 
</span><del>-                                cap = tinymce.trim(b).replace(/caption=['&quot;]/, '').replace(/['&quot;]$/, '');
</del><ins>+                                c = trim(c);
+                                img = c.match(/((?:&lt;a [^&gt;]+&gt;)?&lt;img [^&gt;]+&gt;(?:&lt;\/a&gt;)?)([\s\S]*)/i);
</ins><span class="cx"> 
</span><ins>+                                if ( img &amp;&amp; img[2] ) {
+                                        cap = trim( img[2] );
+                                        img = trim( img[1] );
+                                } else {
+                                        // old captions shortcode style
+                                        cap = trim(b).replace(/caption=['&quot;]/, '').replace(/['&quot;]$/, '');
+                                        img = c;
+                                }
+
</ins><span class="cx">                                 id = ( id &amp;&amp; id[1] ) ? id[1] : '';
</span><span class="cx">                                 cls = ( cls &amp;&amp; cls[1] ) ? cls[1] : 'alignnone';
</span><span class="cx">                                 w = ( w &amp;&amp; w[1] ) ? w[1] : '';
</span><span class="lines">@@ -164,7 +174,7 @@
</span><span class="cx">                                         div_cls += ' mceIEcenter';
</span><span class="cx"> 
</span><span class="cx">                                 return '&lt;div class=&quot;'+div_cls+'&quot;&gt;&lt;dl id=&quot;'+id+'&quot; class=&quot;wp-caption '+cls+'&quot; style=&quot;width: '+( 10 + parseInt(w) )+
</span><del>-                                'px&quot;&gt;&lt;dt class=&quot;wp-caption-dt&quot;&gt;'+c+'&lt;/dt&gt;&lt;dd class=&quot;wp-caption-dd&quot;&gt;'+cap+'&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;';
</del><ins>+                                'px&quot;&gt;&lt;dt class=&quot;wp-caption-dt&quot;&gt;'+img+'&lt;/dt&gt;&lt;dd class=&quot;wp-caption-dd&quot;&gt;'+cap+'&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;';
</ins><span class="cx">                         });
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="lines">@@ -187,15 +197,14 @@
</span><span class="cx">                                         cls = cls.match(/align[a-z]+/) || 'alignnone';
</span><span class="cx"> 
</span><span class="cx">                                         cap = cap.replace(/\r\n|\r/g, '\n').replace(/&lt;[a-zA-Z0-9]+( [^&lt;&gt;]+)?&gt;/g, function(a){
</span><del>-                                                a = a.replace(/[\r\n\t]+/, ' ').replace(/=&quot;[^&quot;]+&quot;/, function(b){
-                                                        return b.replace(/'/g, '&amp;#39;');
-                                                });
-                                                return a.replace(/&quot;/g, &quot;'&quot;);
</del><ins>+                                                // no line breaks inside HTML tags
+                                                return a.replace(/[\r\n\t]+/, ' ');
</ins><span class="cx">                                         });
</span><span class="cx"> 
</span><del>-                                        cap = cap.replace(/\n+/g, '&lt;br /&gt;').replace(/&quot;/g, '&amp;quot;');
</del><ins>+                                        // convert remaining line breaks to &lt;br&gt;
+                                        cap = cap.replace(/\s*\n\s*/g, '&lt;br /&gt;');
</ins><span class="cx"> 
</span><del>-                                        return '[caption id=&quot;'+id+'&quot; align=&quot;'+cls+'&quot; width=&quot;'+w+'&quot; caption=&quot;'+cap+'&quot;]'+c+'[/caption]';
</del><ins>+                                        return '[caption id=&quot;'+id+'&quot; align=&quot;'+cls+'&quot; width=&quot;'+w+'&quot;]'+c+' '+cap+'[/caption]';
</ins><span class="cx">                                 });
</span><span class="cx"> 
</span><span class="cx">                                 if ( ret.indexOf('[caption') !== 0 ) {
</span></span></pre></div>
<a id="trunkwpincludesjstinymcepluginswpeditimagejseditimagedevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.dev.js (20678 => 20679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.dev.js        2012-05-01 22:58:23 UTC (rev 20678)
+++ trunk/wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.dev.js        2012-05-02 01:14:52 UTC (rev 20679)
</span><span class="lines">@@ -419,13 +419,10 @@
</span><span class="cx">                         caption = f.img_cap_text.value;
</span><span class="cx"> 
</span><span class="cx">                         caption = caption.replace(/\r\n|\r/g, '\n').replace(/&lt;[a-zA-Z0-9]+( [^&lt;&gt;]+)?&gt;/g, function(a){
</span><del>-                                a = a.replace(/[\r\n\t]+/, ' ').replace(/=&quot;[^&quot;]+&quot;/, function(b){
-                                        return b.replace(/'/g, '&amp;#39;');
-                                });
-                                return a.replace(/&quot;/g, &quot;'&quot;);
</del><ins>+                                return a.replace(/[\r\n\t]+/, ' ');
</ins><span class="cx">                         });
</span><span class="cx"> 
</span><del>-                        caption = caption.replace(/\n+/g, '&lt;br /&gt;').replace(/&quot;/g, '&amp;quot;');
</del><ins>+                        caption = caption.replace(/\s*\n\s*/g, '&lt;br /&gt;');
</ins><span class="cx"> 
</span><span class="cx">                         if ( DL ) {
</span><span class="cx">                                 ed.dom.setAttribs(DL, {
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (20678 => 20679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-05-01 22:58:23 UTC (rev 20678)
+++ trunk/wp-includes/media.php        2012-05-02 01:14:52 UTC (rev 20679)
</span><span class="lines">@@ -724,6 +724,13 @@
</span><span class="cx">  * @return string
</span><span class="cx">  */
</span><span class="cx"> function img_caption_shortcode($attr, $content = null) {
</span><ins>+        // New-style shortcode with the caption inside the shortcode with the link and image tags.
+        if ( ! isset( $attr['caption'] ) ) {
+                if ( preg_match( '#((?:&lt;a [^&gt;]+&gt;\s*)?&lt;img [^&gt;]+&gt;(?:\s*&lt;/a&gt;)?)(.*)#is', $content, $matches ) ) {
+                        $content = $matches[1];
+                        $attr['caption'] = trim( $matches[2] );
+                }
+        }
</ins><span class="cx"> 
</span><span class="cx">         // Allow plugins/themes to override the default caption template.
</span><span class="cx">         $output = apply_filters('img_caption_shortcode', '', $attr, $content);
</span></span></pre>
</div>
</div>

</body>
</html>