public
Created

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git wp-includes/media.php wp-includes/media.php
index e3b9008..5958d37 100644
--- wp-includes/media.php
+++ wp-includes/media.php
@@ -726,7 +726,7 @@ add_shortcode('caption', 'img_caption_shortcode');
function img_caption_shortcode($attr, $content = null) {
// Allow plugins/themes to override the default caption template.
- $output = apply_filters('img_caption_shortcode', '', $attr, $content);
+ $output = apply_filters( 'img_caption_shortcode', '', $attr, do_shortcode( $content) );
if ( $output != '' )
return $output;
@@ -734,16 +734,49 @@ function img_caption_shortcode($attr, $content = null) {
'id' => '',
'align' => 'alignnone',
'width' => '',
- 'caption' => ''
+ 'caption' => false
), $attr));
- if ( 1 > (int) $width || empty($caption) )
+ if ( 1 > (int) $width || ( $caption !== false && empty( $caption ) ) )
return $content;
- if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
+ return sprintf(
+ '<div %s class="wp-caption %s" style="width: %dpx">%s</div>',
+ $id ? 'id="' . esc_attr( $id ) . '"' : '',
+ esc_attr( $align ),
+ (10 + (int) $width ),
+ // Leave this for backcompat with <3.4.0 shortcode version
+ $caption ? do_shortcode( $content ) . img_caption_text_shortcode( array(), $caption ) : do_shortcode( $content )
+ );
+}
+
+add_shortcode( 'caption_text', 'img_caption_text_shortcode' );
+
+/**
+ * The Caption Text shortcode.
+ *
+ * Allows a plugin to replace the content that would otherwise be returned. The
+ * filter is 'img_caption_text_shortcode' and passes an empty string, the attr
+ * parameter and the content parameter values.
+ *
+ * The supported attributes for the shortcode are 'class'.
+ *
+ * @since 3.4.0
+ *
+ * @param array $attr Attributes attributed to the shortcode text.
+ * @param string $content Optional. Shortcode text.
+ * @return string
+ */
+function img_caption_text_shortcode( $attr, $content) {
+
+ // Allow plugins/themes to override the default caption text template.
+ $output = apply_filters( 'img_caption_text_shortcode', '', $attr, $content );
+ if ( $output != '' )
+ return $output;
+
+ extract( shortcode_atts( array( 'class' => 'wp-caption-text' ), $attr ) );
- return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
- . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
+ return '<p class="' . $class . '">' . $content . '</p>';
}
add_shortcode('gallery', 'gallery_shortcode');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.