<?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>Qu&#039;une petite étincelle brille au fond de vos yeux ! &#187; Wordpress</title>
	<atom:link href="http://www.vdigital.org/sharing/tag/blogroll/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vdigital.org/sharing</link>
	<description>Savoirs et partages</description>
	<lastBuildDate>Sat, 21 Aug 2010 20:36:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Utiliser Ajax avec WordPress</title>
		<link>http://www.vdigital.org/sharing/2010/08/utiliser-ajax-avec-wordpress/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/utiliser-ajax-avec-wordpress/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 21:20:17 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1094</guid>
		<description><![CDATA[<div class="img-shadow"><img width="200" height="150" title="ajaxwordpress" alt="Ajax and WordPress" class="attachment-thumbnail wp-post-image" src="http://bavotasan.com/wp-content/uploads/2010/08/ajaxwordpress.jpg"></img>]]></description>
			<content:encoded><![CDATA[<p><sub>Traduit et adapté de l&#8217;article <a href="http://bavotasan.com/tutorials/using-ajax-with-wordpress/">Using Ajax with WordPress</a> de C. Bavota (avec son aimable autorisation).</sub></p>
<p>Il y a quelques temps, C. Bavota a publié une révision du thème &laquo;&nbsp;<a href="http://wordpress.org/extend/themes/magazine-basic">Magazine Basic</a>&nbsp;&raquo; incluant une fonction d&#8217;enregistrement en Ajax. Dans l&#8217;attente de réactions suite à sa publication sur WordPress, il a obtenu des informations sur la façon d&#8217;intégrer Ajax en utilisant le module admin-ajax.php au lieu du code qu&#8217;il avait utilisé. Toutes les fonctions principales en Ajax de WordPress s&#8217;appuient sur admin-ajax.php, et sa mise en œuvre pour des scripts personnalisés est extrêmement simple.<br />
<span id="more-1094"></span><br />
Regardons les éléments dont vous aurez besoin pour que cela fonctionne. Dans l&#8217;exemple ci-dessous, nous allons coder une petite fonction de mailing-list qui notifiera l&#8217;administrateur par courriel lors d&#8217;une nouvelle inscription.</p>
<p><strong>Voyons le formulaire :</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglist&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglistemail&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglistemail&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglistsubmit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;S'abonner&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php admin_url(); ?&gt;</span></span>/wp-admin/images/wpspin_light.gif&quot; alt=&quot;&quot; class=&quot;ajaxsave&quot; style=&quot;display: none;&quot; /&gt;<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span></div></div>
<p><strong>Voici le jQuery :</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistemail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci d'indiquer votre adresse email.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mailinglistemail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci de saisir une adresse email valide.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'join_mailinglist'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; email<span style="color: #339933;">:</span> email<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Permettez-moi de vous expliquer chaque composant.</p>
<p>Quand un utilisateur clique sur &laquo;&nbsp;S&#8217;abonner&nbsp;&raquo; (Envoyer), nous devons vérifier que le champ e-mail n&#8217;est pas vide. S&#8217;il est vide, nous en informerons le visiteur en lui indiquant &laquo;&nbsp;Merci d&#8217;indiquer votre adresse email.&nbsp;&raquo; et nous arrêtons le processus en incluant l&#8217;instruction &laquo;&nbsp;return false;&nbsp;&raquo;.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistemail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci d'indiquer votre adresse email.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Ensuite, nous ferons une simple validation pour s&#8217;assurer que l&#8217;adresse e-mail contient au moins une arrobe (@) et un point. Si ce n&#8217;est pas le cas, nous renverrons un message d&#8217;erreur suivi de &laquo;&nbsp;return false;&nbsp;&raquo;.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mailinglistemail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci de saisir une adresse email valide.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Une fois ces contrôles élémentaires effectués et passés avec succès, nous pouvons traiter le formulaire. C&#8217;est maintenant qu&#8217;admin-ajax.php entre en jeu. Lors l&#8217;utilisation d&#8217;admin-ajax.php, vous devez ajouter une action WordPress (<a href="http://codex.wordpress.org/Function_Reference/add_action">add_action</a>) incluant une fonction de rappel (callback function) pour que ça fonctionne. Notre fonction de rappel sera join_mailinglist. Notre fonction PHP rendra l&#8217;ensemble fonctionnel en tâche de fond. Mais avant, nous allons créer une variable pour stocker l&#8217;action et l&#8217;adresse email du nouvel abonné.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'join_mailinglist'</span><span style="color: #339933;">,</span><br />
&nbsp; email<span style="color: #339933;">:</span> email<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>Maintenant, nous allons cacher le bouton d&#8217;envoi et présenter un graphique animé pour indiquer qu&#8217;une tâche de fond s&#8217;exécute. Puis nous utiliserons la fonction .post de jQuery pour envoyer ces informations au module admin-ajax.php. Une fois la fonction terminée et la réponse transmise, l&#8217;animation va disparaître, le bouton &laquo;&nbsp;S&#8217;abonner&nbsp;&raquo; sera de retour avec un message de succès, ou un message d&#8217;erreur.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span><br />
<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <br />
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></div></div>
<p>Avec le formulaire et le jQuery, vous aurez besoin encore d&#8217;un peu de PHP.<br />
Le module admin-ajax.php requiert deux ancrages d&#8217;action (<a href="http://codex.wordpress.org/Function_Reference/add_action">add_action</a>).</p>
<p>La première action ne fonctionnera que pour les utilisateurs connectés. La seconde le sera pour les autres. Les visiteurs n&#8217;ont pas à être connectés pour notre besoin, et dans notre cas l&#8217;action devrait ressembler à ceci :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_join_mailinglist'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'join_mailinglist_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_nopriv_join_mailinglist'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'join_mailinglist_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p><strong><br />
Voici la fonction join_mailinglist_callback, qui devra être ajoutée à votre functions.php :</strong></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> join_mailinglist_callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$yourEmail</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'vpiwigo@gmail.com'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Abonnez-vous à la lettre d\'information'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$success</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mail"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yourEmail</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$success</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Votre adresse email a été ajoutée à notre lettre d\'information.'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Un problème a été rencontré. Veuillez réessayer.'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Une fois tout en place, vous obtiendrez un formulaire fonctionnant comme ci-dessous. </p>
<p><script type='text/javascript' src='http://www.vdigital.org/sharing/wp-content/local/js/nl-subscription.js'></script></p>
<form method="post" id="mailinglist" action="">
<div id="message"></div>
<input type="text" name="mailinglistemail" id="mailinglistemail" />
<input type="submit" name="submit" id="mailinglistsubmit" value="S'abonner" /><img src="http://www.vdigital.org/sharing/wp-admin/images/wpspin_light.gif" alt="runing" class="ajaxsave" style="display: none;" /><br />
</form>
<p><sub>En réalité, aucune lettre d&#8217;information ne vous sera adressée suite à votre inscription sur ce formulaire de démonstration (les adresses fournies peuvent être fictives, elles ne seront pas enregistrées).</p>
<p><sub>Translated and adapted from &laquo;&nbsp;<a href="http://bavotasan.com/tutorials/using-ajax-with-wordpress/">Using Ajax with WordPress</a>&nbsp;&raquo; article by C. Bavota (with his kind authorization).</sub></p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1094';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/utiliser-ajax-avec-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PiwigoPress</title>
		<link>http://www.vdigital.org/sharing/2009/10/piwigopress/</link>
		<comments>http://www.vdigital.org/sharing/2009/10/piwigopress/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 19:46:08 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=557</guid>
		<description><![CDATA[Procédure d&#8217;installation. Coté Blog (WordPress) - Dans les extensions (WordPress) Ajoutez le plugin PiwigoPress et activez-le. - Apparence > Widgets Faites glisser le Widget dans le sidebar voulu&#8230; Paramétrez le Widget (Titre et nom du répertoire de votre galerie Piwigo). Coté galerie: - Avoir des images publiques non confidentielles assez récentes. En gros, c&#8217;est tout.]]></description>
			<content:encoded><![CDATA[<p>Procédure d&#8217;installation.</p>
<p>Coté Blog (WordPress)</p>
<p>- Dans les extensions (WordPress) Ajoutez le plugin PiwigoPress et activez-le.</p>
<p>- Apparence > Widgets<br />
Faites glisser le Widget dans le sidebar voulu&#8230;<br />
Paramétrez le Widget (Titre et nom du répertoire de votre galerie Piwigo).</p>
<p>Coté galerie:<br />
- Avoir des images publiques non confidentielles assez récentes.</p>
<p>En gros, c&#8217;est tout.</p>
<p><img title="VDigital" alt="VD-presb.gif" src="http://www.vdigital.org/images/VD-presb.gif"/></p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=557';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2009/10/piwigopress/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

