PL Accordion Shortcode Fails with % inside
Submitted by Evan Mattson on 26 October 2012 - 07:00 PM
Evan Mattson
Issue Timeline
Ian mentioned he was getting an error using the pl_accordion shortcode on a site today. The error was a sprintf too few arguments error.
The problem is that the format string has the do_shortcode concatenated into it, not inserted with a %s, so any % sign in the accordion shortcode or any of it's content shortcodes will throw the same error.
To test this, I pulled the example off the .me tools demo:
[pl_accordion name="accordion"][pl_accordioncontent name="accordion" number="1" heading="Tile 1" open="yes"] Content 1 [/pl_accordioncontent] [pl_accordioncontent name="accordion" number="2" heading="Title 2"] <img class="pl-imageframe" src="http://placekitten.com/285/125" alt="" /> [/pl_accordioncontent] [/pl_accordion]
This will work, however, if you change "Content 1" to "Content 100%" or put a % anywhere else, you'll get one of these guys:
Warning: sprintf() [function.sprintf]: Too few arguments in C:\xampp\htdocs\pagelines\wp-content\themes\pagelines\includes\class.shortcodes.php on line 1084
Simple fix, but here's the code:
function pl_accordion_shortcode( $atts, $content = null ) {</p>
<p>$defaults = array(
'name' => '',
);
$atts = shortcode_atts( $defaults, $atts );</p>
<p> $out = sprintf( '<div id="%s" class="accordion">%s</div>',
$atts['name'],
do_shortcode( $content )
);
return $out;
}
Also, the docblock @examples in class.shortcodes.php for this shortcode references wrong shortcode tags.


