Created
February 16, 2012 20:22
-
-
Save stas/1847575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment