From c3a174becd835bb2c52bebb61f220738d6c88738 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 6 Mar 2013 20:07:40 +0000 Subject: [PATCH] Add shortcode_atts_$shortcode filter for when the name of the shortcode is passed to shortcode_atts(). props coffee2code. fixes #15155. git-svn-id: http://core.svn.wordpress.org/trunk@23626 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 4 ++-- wp-includes/shortcodes.php | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index f1f373735e..c543389a97 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -644,7 +644,7 @@ function img_caption_shortcode($attr, $content = null) { 'align' => 'alignnone', 'width' => '', 'caption' => '' - ), $attr)); + ), $attr, 'caption')); if ( 1 > (int) $width || empty($caption) ) return $content; @@ -704,7 +704,7 @@ function gallery_shortcode($attr) { 'size' => 'thumbnail', 'include' => '', 'exclude' => '' - ), $attr)); + ), $attr, 'gallery')); $id = intval($id); if ( 'RAND' == $order ) diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php index 2dfc277450..bdc3f9bd56 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -289,9 +289,10 @@ function shortcode_parse_atts($text) { * * @param array $pairs Entire list of supported attributes and their defaults. * @param array $atts User defined attributes in shortcode tag. + * @param string $shortcode Optional. The name of the shortcode, provided for context to enable filtering * @return array Combined and filtered attribute list. */ -function shortcode_atts($pairs, $atts) { +function shortcode_atts( $pairs, $atts, $shortcode = '' ) { $atts = (array)$atts; $out = array(); foreach($pairs as $name => $default) { @@ -300,6 +301,10 @@ function shortcode_atts($pairs, $atts) { else $out[$name] = $default; } + + if ( $shortcode ) + $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts ); + return $out; }