Jump to content


PL Accordion Shortcode Fails with % inside

Submitted by Evan Mattson on 26 October 2012 - 07:00 PM

#37shortcode accordion


Fixed   Add Issue 

Evan Mattson

Issue Timeline

  • Simon_P updated issue fixed in to 2.3.5

    29 October 2012 - 07:00 PM

  • Simon_P updated issue version to 2.3.4

    29 October 2012 - 07:00 PM

  • Simon_P updated issue severity to Fixed

    29 October 2012 - 06:59 PM

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(

  &#39;name&#39; => &#39;&#39;,

    );

    

    $atts = shortcode_atts( $defaults, $atts );</p>
<p>    $out = sprintf( &#39;<div id="%s" class="accordion">%s</div>&#39;,

     $atts[&#39;name&#39;],

     do_shortcode( $content )

);

       

    return $out;

}

 

Also, the docblock @examples in class.shortcodes.php for this shortcode references wrong shortcode tags.

Comments


TracDown © 2013 Michael Burton
Click to return to top of page in style!