<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>piouPiouM&#039;s dev&#187; Archives pour le tag shortcode – piouPiouM&#039;s dev</title>
	<atom:link href="http://pioupioum.fr/tag/shortcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://pioupioum.fr</link>
	<description>Bloc-note d&#039;un développeur web</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:47:44 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress et SmartyPants&#160;: des légendes qui disparaissent</title>
		<link>http://pioupioum.fr/outils-astuces/wordpress-smartypants-shortcode-caption.html</link>
		<comments>http://pioupioum.fr/outils-astuces/wordpress-smartypants-shortcode-caption.html#comments</comments>
		<pubDate>Fri, 07 Aug 2009 13:10:57 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=186</guid>
		<description><![CDATA[Si comme moi vous utilisez Typographer, extension de SmartyPants1, en tant que plugin WordPress vous l&#8217;aurez certainement relevé&#160;: son activation entraîne la disparition des légendes pour les images.

Pour corriger cet effet de bord, éditez le fichier smartypants.php2 pour y remplacer la priorité d&#8217;application des filtres the_content et the_excerpt (originellement à 10)&#160;:


137
138
add_filter&#40;'the_content', 'SmartyPants', 11&#41;;
add_filter&#40;'the_excerpt', 'SmartyPants', 11&#41;;


Le [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Si comme moi vous utilisez <em><a href="http://michelf.com/projets/php-smartypants/typographer/" title="PHP SmartyPants Typographer">Typographer</a></em>, extension de <strong><a href="http://michelf.com/projets/php-smartypants/" title="PHP SmartyPants">SmartyPants</a></strong><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>, en tant que plugin <a href="http://fr.wordpress.org/" title="WordPress | France">WordPress</a> vous l&#8217;aurez certainement relevé&#160;: son activation entraîne la disparition des <strong>légendes</strong> pour les images.</p>

<p>Pour corriger cet effet de bord, éditez le fichier <code>smartypants.php</code><sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> pour y remplacer la priorité d&#8217;application des filtres <code>the_content</code> et <code>the_excerpt</code> (originellement à 10)&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>137
138
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'SmartyPants'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_excerpt'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'SmartyPants'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Le plugin SmartyPants Typographer<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup> entre ainsi en action après le traitement du shortcode <strong>caption</strong>.</p>

<p>Le bug et son correctif ont été reportés auprès de <a href="http://michelf.com/" title="ici Michel Fortin">Michel Fortin</a>.</p>

<p><strong>Mise à jour du 09/08/2009</strong><br />
Le correctif sera appliqué dans la prochaine version de SmartyPants (et son extension Typographer).</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html' title='Shortcode WordPress : intégrer un flux RSS'>Shortcode WordPress&#160;: intégrer un flux RSS</a></li><li><a href='http://pioupioum.fr/outils-astuces/faille-wordpress-mot-passe-correctif.html' title='Correctif pour la faille WordPress de réinitialisation de mot de passe'>Correctif pour la faille WordPress de réinitialisation de mot de passe</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-autoriser-upload-media-format-inconnu.html' title='WordPress : autoriser l&#8217;upload de fichiers au format non-supporté'>WordPress&#160;: autoriser l&#8217;upload de fichiers au format non-supporté</a></li><li><a href='http://pioupioum.fr/plugins-wordpress/wordpress-jquery-ui-effects.html' title='WordPress jQuery UI Effects'>WordPress jQuery UI Effects</a></li><li><a href='http://pioupioum.fr/outils-astuces/wordpress-recuperation-avancee-images-article.html' title='WordPress : récupération avancée des images d&#8217;un article'>WordPress&#160;: récupération avancée des images d&#8217;un article</a></li></ul>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>ici, SmartyPants version 1.5.1oo2.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>dans le cas de l&#8217;extension <abbr title="WordPress">WP</abbr> SmartyPants, le correctif est à appliquer aux lignes 61 et 62.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>SmartyPants Typographer version 1.0.&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/wordpress-smartypants-shortcode-caption.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Shortcode WordPress&#160;: intégrer un flux RSS</title>
		<link>http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html</link>
		<comments>http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html#comments</comments>
		<pubDate>Fri, 17 Jul 2009 01:02:36 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=70</guid>
		<description><![CDATA[Dans son article Mastering WordPress Shortcodes, Smashing Magazine nous invite dans son 4ème exemple à intégrer le contenu d&#8217;un flux RSS dans vos billets WordPress à l&#8217;aide d&#8217;un shortcode.

Houston, on a un problème

Reprenons le code donné dans l&#8217;article&#160;:


1
2
3
4
5
6
7
8
9
10
11
12
13
//This file is needed to be able to use the wp_rss() function.
include_once&#40;ABSPATH.WPINC.'/rss.php'&#41;;
&#160;
function readRss&#40;$atts&#41; &#123;
    extract&#40;shortcode_atts&#40;array&#40;
 [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Dans son article <a href="http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/" title="Mastering WordPress Shortcodes | Developer&#039;s Toolbox | Smashing Magazine">Mastering WordPress Shortcodes</a>, <a href="http://www.smashingmagazine.com/" title="Smashing Magazine">Smashing Magazine</a> nous invite dans son 4<sup>ème</sup> exemple à intégrer le contenu d&#8217;un flux <abbr title="Really Simple Syndication">RSS</abbr> dans vos billets <a href="http://www.wordpress-fr.net/" title="WordPress Francophone – La communauté du CMS Opensource">WordPress</a> à l&#8217;aide d&#8217;un <a href="http://codex.wordpress.org/Shortcode_API" title="Shortcode API » WordPress Codex">shortcode</a>.</p>

<h2>Houston, on a un problème</h2>

<p>Reprenons le code donné dans l&#8217;article&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//This file is needed to be able to use the wp_rss() function.</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>ABSPATH<span style="color: #339933;">.</span>WPINC<span style="color: #339933;">.</span><span style="color: #0000ff;">'/rss.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> readRss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;feed&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">&quot;num&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> wp_rss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rss'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'readRss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Si vous le testez, comme <a href="http://twitter.com/Fran6/status/2671399288" title="sur twitter">@Fran6</a> par exemple, vous constaterez que le résultat n&#8217;est pas celui escompté&#160;: le flux de syndication précède le contenu de votre article au lieu d&#8217;être inséré là où vous l&#8217;attendiez.<span id="more-70"></span></p>

<p>La raison&#160;? À la <code>ligne 10</code>, le résultat de la fonction <code>wp_rss()</code> est retourné au moteur de WordPress pour remplacer le shortcode dans le contenu du billet. Or, la fonction <code>wp_rss()</code> <strong>ne retourne rien</strong> mais <strong>affiche directement</strong> le résultat. Ainsi, tout appel du shortcode entraîne l&#8217;envoi au client du flux <abbr title="Really Simple Syndication">RSS</abbr> (sous la forme d&#8217;une liste non-ordonnée) suivi du contenu du billet.</p>

<h2>Solution</h2>

<p>On corrige le <a href="http://codex.wordpress.org/Shortcode_API" title="Shortcode API » WordPress Codex">shortcode</a> en capturant la sortie de la fonction <code>wp_rss()</code> à l&#8217;aide d&#8217;une <a href="http://fr.php.net/manual/fr/intro.outcontrol.php" title="PHP: Contrôle de l'affichage - Introduction - Manual">tamporisation de sortie</a>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//This file is needed to be able to use the wp_rss() function.</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>ABSPATH<span style="color: #339933;">.</span>WPINC<span style="color: #339933;">.</span><span style="color: #0000ff;">'/rss.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> readRss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">&quot;feed&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;num&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    wp_rss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rss'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'readRss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/outils-astuces/wordpress-smartypants-shortcode-caption.html' title='WordPress et SmartyPants : des légendes qui disparaissent'>WordPress et SmartyPants&#160;: des légendes qui disparaissent</a></li><li><a href='http://pioupioum.fr/outils-astuces/faille-wordpress-mot-passe-correctif.html' title='Correctif pour la faille WordPress de réinitialisation de mot de passe'>Correctif pour la faille WordPress de réinitialisation de mot de passe</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-autoriser-upload-media-format-inconnu.html' title='WordPress : autoriser l&#8217;upload de fichiers au format non-supporté'>WordPress&#160;: autoriser l&#8217;upload de fichiers au format non-supporté</a></li><li><a href='http://pioupioum.fr/plugins-wordpress/wordpress-jquery-ui-effects.html' title='WordPress jQuery UI Effects'>WordPress jQuery UI Effects</a></li><li><a href='http://pioupioum.fr/outils-astuces/wordpress-recuperation-avancee-images-article.html' title='WordPress : récupération avancée des images d&#8217;un article'>WordPress&#160;: récupération avancée des images d&#8217;un article</a></li></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
