<?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>bavotasan.com &#187; Scripts</title>
	<atom:link href="http://bavotasan.com/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://bavotasan.com</link>
	<description>by c.bavota</description>
	<lastBuildDate>Tue, 07 Feb 2012 15:42:10 +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>8 jQuery Plugins to Improve the Way your Forms Look</title>
		<link>http://bavotasan.com/2010/8-jquery-plugins-improve-forms-look/</link>
		<comments>http://bavotasan.com/2010/8-jquery-plugins-improve-forms-look/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 19:55:38 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[bit]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[Default Theme]]></category>
		<category><![CDATA[dfc]]></category>
		<category><![CDATA[drop]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[Job]]></category>
		<category><![CDATA[jqTransform]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Little Bit]]></category>
		<category><![CDATA[Luckily]]></category>
		<category><![CDATA[Mouse Click]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Style]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1887</guid>
		<description><![CDATA[When it comes to forms, every browser displays inputs, select drop downs and buttons differently. You can style certain elements using CSS but things like radio buttons and checkboxes are determined by the browser. Luckily, there are some cool jQuery plugins available that help you add a little bit more style to your forms. Here [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to forms, every browser displays inputs, select drop downs and buttons differently. You can style certain elements using CSS but things like radio buttons and checkboxes are determined by the browser. Luckily, there are some cool jQuery plugins available that help you add a little bit more style to your forms.<br />
<span id="more-1887"></span><br />
Here are a list of jQuery plugins that can help get your forms looking a bit more impressive:</p>
<div class="lists">
<div class="sections">
<h2>jqTransform</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/jqtransform.jpg" alt="" title="jqtransform" width="560" height="163" class="alignleft size-full wp-image-1888" /><br />
jqTransform allows you to skin form elements with color changes on both mouse rollover and mouse click event.<br />
<a href="http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/">http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/jqtransform_example.jpg" alt="" title="jqtransform_example" width="520" height="580" class="aligncenter size-full wp-image-1889" />
</div>
<div class="sections">
<h2>Niceforms</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/niceform.jpg" alt="" title="niceform" width="560" height="163" class="alignleft size-full wp-image-1895" /><br />
Niceforms is a script that will replace the most commonly used form elements with custom designed ones. You can either use the default theme that is provided or you can even develop your own look with minimal effort.<br />
<a href="http://www.emblematiq.com/lab/niceforms/">http://www.emblematiq.com/lab/niceforms/</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/niceforms_examples.jpg" alt="" title="niceforms_examples" width="560" height="651" class="alignleft size-full wp-image-1896" />
</div>
<div class="sections">
<h2>Uniform</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/uniform.jpg" alt="" title="uniform" width="560" height="163" class="alignleft size-full wp-image-1919" /><br />
Uniform masks your standard form controls with custom themed controls. It works in sync with your real form elements to ensure accessibility and compatibility.<br />
<a href="http://pixelmatrixdesign.com/uniform/">http://pixelmatrixdesign.com/uniform/</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/uniform_example.jpg" alt="" title="uniform_example" width="453" height="179" class="alignleft size-full wp-image-1920" />
</div>
<div class="sections">
<h2>jNice</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/jnice.jpg" alt="" title="jnice" width="560" height="163" class="alignleft size-full wp-image-1900" /><br />
jNice helps you create custom looking form elements that function like normal form elements using jQuery and CSS.<br />
<a href="http://plugins.jquery.com/project/jNice">http://plugins.jquery.com/project/jNice</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/jnice_example.jpg" alt="" title="jnice_example" width="392" height="270" class="alignleft size-full wp-image-1901" />
</div>
<div class="sections">
<h2>jQuery FormOne</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/formone.jpg" alt="" title="formone" width="560" height="163" class="alignleft size-full wp-image-1934" /><br />
jQuery FormOne (aka JQF1) claims to be the most complete form styling plugin and it does seem to cover all the bases.<br />
<a href="http://www.azurem.com/jqf1/">http://www.azurem.com/jqf1/</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/formone_example.jpg" alt="" title="formone_example" width="560" height="978" class="alignleft size-full wp-image-1936" />
</div>
<div class="sections">
<h2>CRIR</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/crir.jpg" alt="" title="crir" width="560" height="163" class="alignleft size-full wp-image-1908" /><br />
CRIR styles only radio buttons and checkboxes. It does a cool job of it but you will still need to use CSS to style other elements of your form.<br />
<a href="http://www.chriserwin.com/scripts/crir/index.php">http://www.chriserwin.com/scripts/crir/index.php</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/crir_example.jpg" alt="" title="crir_example" width="404" height="363" class="alignleft size-full wp-image-1905" />
</div>
<div class="sections">
<h2>jQuery Checkbox</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/checkbox.jpg" alt="" title="checkbox" width="560" height="163" class="alignleft size-full wp-image-1911" /><br />
jQuery Checkbox was designed to replace the default checkboxes with super awesome switches. It also works with radio buttons.<br />
<a href="http://widowmaker.kiev.ua/checkbox/">http://widowmaker.kiev.ua/checkbox/</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/checkbox_example.jpg" alt="" title="checkbox_example" width="349" height="98" class="alignleft size-full wp-image-1912" />
</div>
<div class="sections">
<h2>File Style</h2>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/04/filestyle.jpg" alt="" title="filestyle" width="560" height="163" class="alignleft size-full wp-image-1938" /><br />
File Style allows you to choose an image to replace the default browse button when using a file input field.<br />
<a href="http://www.appelsiini.net/projects/filestyle">http://www.appelsiini.net/projects/filestyle</a></p>
<p><strong>Example</strong>:<br />
<img src="http://bavotasan.com/wp-content/uploads/2010/04/filestyle_example.jpg" alt="" title="filestyle_example" width="560" height="138" class="alignleft size-full wp-image-1939" />
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/8-jquery-plugins-improve-forms-look/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Force WordPress to use the Latest Version of jQuery</title>
		<link>http://bavotasan.com/2010/force-wordpress-use-latest-version-jquery/</link>
		<comments>http://bavotasan.com/2010/force-wordpress-use-latest-version-jquery/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 15:20:43 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[Change]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[New Features]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[piece]]></category>
		<category><![CDATA[Place]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1875</guid>
		<description><![CDATA[If you&#8217;re using WordPress 2.9.x, then the latest version of jQuery included is 1.3.2. What if you want to take advantage of new features in version 1.4, like delaying an animation queue or binding multiple event handlers? You can easily add a link in your header to the latest version, but that might end up [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using WordPress 2.9.x, then the latest version of <a href="http://jquery.com/">jQuery</a> included is 1.3.2. What if you want to take advantage of new features in version 1.4, like delaying an animation queue or binding multiple event handlers? You can easily add a link in your header to the latest version, but that might end up conflicting with some plugins or themes.<br />
<span id="more-1875"></span><br />
The best approach would be to use the following piece of code to let WordPress know that you want to load the current version instead.</p>
<p>Place this into your theme&#8217;s <code>functions.php</code> file:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> current_jquery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_scripts</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">version_compare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$version</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_scripts</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">registered</span><span style="color: #009900;">&#91;</span>jquery<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">ver</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>is_admin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                wp_deregister_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
                wp_register_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jquery/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$version</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/jquery.min.js'</span><span style="color: #339933;">,</span>
                        <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> current_jquery<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'1.4.2'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// change number to latest version</span></pre></div></td></tr></table></div>

<p>If jQuery is updated, all you have to do is change the version number when calling the function.</p>
<p><strong>Reference</strong>: <a href="http://binarybonsai.com/2010/02/14/how-to-load-the-latest-jquery-in-wordpress/">Binary Bonsai</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/force-wordpress-use-latest-version-jquery/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Simple Voting for WordPress with PHP and jQuery</title>
		<link>http://bavotasan.com/2009/simple-voting-for-wordpress-with-php-and-jquery/</link>
		<comments>http://bavotasan.com/2009/simple-voting-for-wordpress-with-php-and-jquery/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 17:58:03 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[span]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Wp]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1567</guid>
		<description><![CDATA[This tutorial is no longer up-to-date. Please check out A Better Voting System for WordPress for a more secure and efficient approach. I needed to create a simple way for site members to vote on a post and the few scripts I found didn&#8217;t really work how I needed them to. So I decided to [...]]]></description>
			<content:encoded><![CDATA[<div class="imgprov">
This tutorial is no longer up-to-date. Please check out <a href="http://bit.ly/rrp67O">A Better Voting System for WordPress</a> for a more secure and efficient approach.
</div>
<p>I needed to create a simple way for site members to vote on a post and the few scripts I found didn&#8217;t really work how I needed them to. So I decided to whip something together myself. I developed a pretty basic script using PHP and jQuery to allow members who are signed in to click on a simple link to add their vote to a post.<br />
<span id="more-1567"></span><br />
First you need to add this to your <code>header.php</code> file between the &lt;head&gt; tags. If you notice that you already have the <code>&lt;?php wp_head(); ?&gt;</code> call somewhere else in your <code>header.php</code> file, just delete it.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;?php wp_enqueue_script( 'jquery' ) ?&gt;
&lt;?php wp_head(); ?&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
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>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.vote a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>
<span style="color: #003366; font-weight: bold;">var</span> some <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> thepost <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;post&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> theuser <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php bloginfo('template_url'); ?&gt;/vote.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>user<span style="color: #339933;">:</span> theuser<span style="color: #339933;">,</span> post<span style="color: #339933;">:</span> thepost<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> votebox <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;.vote&quot;</span><span style="color: #339933;">+</span>thepost<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot; span&quot;</span><span style="color: #339933;">;</span>
jQuery<span style="color: #009900;">&#40;</span>votebox<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery<span style="color: #009900;">&#40;</span>some<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span class=&quot;voted&quot;&gt;Voted&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>When a member clicks on the vote link, the above code will get the post ID and the member&#8217;s user ID and send it to a file called <code>vote.php</code> using a post method. The vote.php file will perform everything we need to add the vote.</p>
<p>So let&#8217;s create a file called <code>vote.php</code> and add it to your theme&#8217;s directory.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">stripos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;wp-content&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/wp-load.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$currentvotes</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'votes'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$currentvotes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$currentvotes</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$voters</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thevoters'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$voters</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$voters</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$voters</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$voters</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'votes'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currentvotes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thevoters'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$voters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$currentvotes</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>Once the information is posted to <code>vote.php</code> two custom fields are created. One to count the vote and one to add the voter to a list so that they can&#8217;t vote again.</p>
<p>Add the code below to your <code>functions.php</code> file, or create a <code>functions.php</code> file if your theme does not have one.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// voting function</span>
<span style="color: #000000; font-weight: bold;">function</span> voting<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$user_ID</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$currentvotes</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'votes'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$voters</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thevoters'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$voters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$voters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$voters</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$voter</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$voter</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$user_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$alreadyVoted</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$currentvotes</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$currentvotes</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;vote vote'</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;&lt;span&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$currentvotes</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_ID</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$alreadyVoted</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;&lt;a post=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; user=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user_ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Vote&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_ID</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$alreadyVoted</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;&lt;span class=&quot;voted&quot;&gt;'</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Voted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$user_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;signup&quot;&gt;&lt;p&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/wp-login.php?action=register&quot;&gt;'</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Register'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'to vote'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.&lt;/p&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Let&#8217;s add some CSS to style our voting box.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.vote</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span> <span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.vote</span> a<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.vote</span> span<span style="color: #6666ff;">.voted</span> <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.vote</span> span<span style="color: #6666ff;">.voted</span> <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">default</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>Now all you need to do is add the following within the WordPress loop to have the voting box appear.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> voting<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>Test it out below:</p>
<p><script type="text/javascript">
jQuery(document).ready(function(){
	jQuery(".vote a").click(
		function() {
		var some = jQuery(this);
		var votebox = ".vote span";
		jQuery(votebox).text(1);
		jQuery(some).replaceWith('<span class="voted">Voted</span>');
	});
});	
</script></p>
<div class="vote"><span>0</span><br />
<a>Vote</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/simple-voting-for-wordpress-with-php-and-jquery/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Backup, Backup, Backup!</title>
		<link>http://bavotasan.com/2009/backup-backup-backup/</link>
		<comments>http://bavotasan.com/2009/backup-backup-backup/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 17:04:38 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Backup Backup Backup]]></category>
		<category><![CDATA[Click]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[couple]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Backup]]></category>
		<category><![CDATA[Hackers]]></category>
		<category><![CDATA[Important Things]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[thing]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=665</guid>
		<description><![CDATA[Over the past couple of weeks I have helped out many people who have been hacked. There are many ways in which you can protect your site, but the most important thing is having a recent backup from before you were hacked. There are many plugins available for WordPress that will help you make a [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past couple of weeks I have helped out many people who have been hacked. There are many ways in which you can protect your site, but the most important thing is having a recent backup from before you were hacked.<span id="more-665"></span></p>
<p>There are many plugins available for WordPress that will help you make a backup of your database. <a href="http://wordpress.org/extend/plugins/search.php?q=backup">Click here to see them all</a>. I use WP-DB-Backup on many of my client&#8217;s sites. It has the option to backup to your server or your desktop. I suggest doing both. You can never have too many backups. I always save my backups in multiple places, and I also keep two or three previous backups, just in case.</p>
<p>If you are not using WordPress, there are many scripts out there that can help you with making a database backup. If your server has PHPMyAdmin installed, you can make manual backups very easily. But whatever you do, be certain to backup your database often.</p>
<p>Backing up your database is extremely important but so is backing up your site. Doing both regularly will not stop hackers from attacking you, but it will make it easier for you to repair the damage they make. </p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/backup-backup-backup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

