<?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>code-diesel &#187; wordpress</title>
	<atom:link href="http://www.codediesel.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Changing WordPress admin login error message</title>
		<link>http://www.codediesel.com/security/changing-wordpress-admin-login-error-message/</link>
		<comments>http://www.codediesel.com/security/changing-wordpress-admin-login-error-message/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 05:13:15 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2965</guid>
		<description><![CDATA[It can be surprising how easy it is to overlook security issues in software design. WordPress for example, after all the versions, still displays login error information that can be informative for a potential hacker. Rather than displaying a generic login error message, WordPress admin specifically displays whether a &#8216;username&#8217; was entered wrong or a [...]]]></description>
			<content:encoded><![CDATA[<p>It can be surprising how easy it is to overlook security issues in software design. WordPress for example, after all the versions, still displays login error information that can be informative for a potential hacker. Rather than displaying a generic login error message, WordPress admin specifically displays whether a &#8216;username&#8217; was entered wrong or a &#8216;password&#8217; as the following screenshot shows.<br />
<span id="more-2965"></span><br />
<a href="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login1.gif" alt="" title="wp-login1" width="330" height="293" class="aligncenter size-full wp-image-2966" /></a></p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login3.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login3.gif" alt="" title="wp-login3" width="333" height="307" class="aligncenter size-full wp-image-2969" /></a></p>
<p>This can be useful for a hacker to get  the username right. A good idea is to display a generic message as given below.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login2.gif" alt="" title="wp-login2" width="331" height="291" class="aligncenter size-full wp-image-2967" /></a></p>
<p>You can easily achieve that by adding the following line to your themes &#8216;functions.php&#8217; file.</p>

<div class="wp_codebox"><table><tr id="p29653"><td class="code" id="p2965code3"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login_errors'</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$no_login_error'</span><span style="color: #339933;">,</span> 
                            <span style="color: #0000ff;">&quot;return 'Oops! Wrong Credentials.';&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The second argument to the &#8216;add_filter&#8217; creates a anonymous callback function. This is equivalent to the following.</p>

<div class="wp_codebox"><table><tr id="p29654"><td class="code" id="p2965code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> no_login_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">'Oops! Wrong Credentials.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login_errors'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'no_login_error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/changing-wordpress-admin-login-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plugins to check for security threats</title>
		<link>http://www.codediesel.com/security/wordpress-plugins-to-check-for-security-threats/</link>
		<comments>http://www.codediesel.com/security/wordpress-plugins-to-check-for-security-threats/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 05:47:53 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2952</guid>
		<description><![CDATA[With WordPress installations on the rise, security threats are a common concern for users. Below is a small collection of WordPress plugins that I found adequate for use on most WordPress installations to keep security in check. As always security is not 100% achievable, but the following plugins will help you find any loopholes in [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress installations on the rise, security threats are a common concern for users. Below is a small collection of WordPress plugins that I found adequate for use on most WordPress installations to keep security in check. As always security is not 100% achievable, but the following plugins will help you find any loopholes in your site and help you monitor for any security breaches.<br />
<span id="more-2952"></span><br />
<strong>BulletProof Security</strong><br />
<a href="http://wordpress.org/extend/plugins/bulletproof-security/" rel="nofollow"  title="BulletProof Security" target="_blank">BulletProof Security</a> protects your website from XSS, RFI, CSRF, Base64, Code Injection and SQL Injection hacking attempts. The plugin also Protects wp-config.php, bb-config.php, php.ini, php5.ini, install.php and readme.html with .htaccess security protection. BPS has built-in Backup and Restore, a File Editor, a File Uploader and a File Downloader to make managing the BPS master .htaccess files and your website security fast and simple.</p>
<p><strong>WordPress File Monitor</strong><br />
<a href="http://wordpress.org/extend/plugins/wordpress-file-monitor/" rel="nofollow"  title="WordPress File Monitor" target="_blank">WFM</a> monitors your WordPress installation for any added, deleted or changed files. When a change is detected an email is sent to a specified address. Currently does not support multi-site installations.</p>
<p><strong>Ultimate Security Checker</strong><br />
<a href="http://wordpress.org/extend/plugins/ultimate-security-checker/" rel="nofollow"  title="Ultimate Security Checker" target="_blank">Ultimate Security Checker</a> helps you identify security problems with your WordPress installation. It scans your WordPress blog for hundreds of known threats, then gives you a security &#8220;grade&#8221; based on how well you have protected yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/wordpress-plugins-to-check-for-security-threats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backup your WordPress database to Amazon S3</title>
		<link>http://www.codediesel.com/wordpress/backup-your-wordpress-database-to-amazon-s3/</link>
		<comments>http://www.codediesel.com/wordpress/backup-your-wordpress-database-to-amazon-s3/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 03:12:23 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[amazons3]]></category>
		<category><![CDATA[cloud]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2948</guid>
		<description><![CDATA[My new article describes how to backup your WordPress database to the Amazon S3 cloud infrastructure using a custom plugin. Along with a small description of S3, the article proceeds to build a small plugin to upload your database to Amazon S3. Read the complete article at Smashing Magazine.]]></description>
			<content:encoded><![CDATA[<p>My new article describes how to backup your WordPress database to the Amazon S3 cloud infrastructure using a custom plugin. Along with a small description of S3, the article proceeds to build a small plugin to upload your database to Amazon S3. Read the complete article at <a href="http://wp.smashingmagazine.com/2011/12/01/integrating-amazon-s3-wordpress/" rel="nofollow"  title="Integrating Amazon S3 With WordPress">Smashing Magazine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/wordpress/backup-your-wordpress-database-to-amazon-s3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Country Filter WordPress plugin update</title>
		<link>http://www.codediesel.com/wordpress/country-filter-wordpress-plugin/</link>
		<comments>http://www.codediesel.com/wordpress/country-filter-wordpress-plugin/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 13:57:30 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[geolocation]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2911</guid>
		<description><![CDATA[I&#8217;ve recently updated the country filter plugin to use the MaxMind database along with the ip2nations database. Country Filter plugin allows you to control the visibility of WordPress elements depending on the users country of origin. You can hide or show certain elements of a page or some sections of a post from users browsing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently updated the country filter plugin to use the MaxMind database along with the ip2nations database. Country Filter plugin allows you to control the visibility of WordPress elements depending on the users country of origin. You can hide or show certain elements of a page or some sections of a post from users browsing from a particular country.</p>
<p>For example you could have a ‘donate’ button on a sidebar that displays only if the user is browsing from France. Or you could hide a particular paragraph in a post for users from a particular country. This can be used by marketing people to deliver targeted content to audiences.</p>
<p>Developers and designers could also use the plugin to load different stylesheets based on the users country. Services like hulu.com uses techniques such as this to constrain viewership to a particular country.</p>
<p>You can buy the plugin from <a href="http://www.codediesel.com/plugins/country-filter/" title="country filter plugin">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/wordpress/country-filter-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling WordPress plugins remotely</title>
		<link>http://www.codediesel.com/php/controlling-wordpress-plugins-remotely/</link>
		<comments>http://www.codediesel.com/php/controlling-wordpress-plugins-remotely/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 07:18:14 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2898</guid>
		<description><![CDATA[One of the important reasons for the popularity of WordPress is its plugin architecture, which has enabled thousands of programmers to write additional functionality for WordPress. But the plugins are constrained in silos, unable to be controlled by outside programs ( well this can be advantageous if you consider security). Take the popular WP-Super-Cache plugin. [...]]]></description>
			<content:encoded><![CDATA[<p>One of the important reasons for the popularity of WordPress is its plugin architecture, which has enabled thousands of programmers to write additional functionality for WordPress. But the plugins are constrained in silos, unable to be controlled by outside programs ( well this can be advantageous if you consider security).</p>
<p>Take the popular <a href="http://wordpress.org/extend/plugins/wp-super-cache/" rel="nofollow"  title="wp-super-cache" target="_blank">WP-Super-Cache</a> plugin. I frequently make changes to my blog from a FTP client, and every time I&#8217;ve to login to the WordPress admin and clear the cache so that I can see the latest changes reflected. At times this can be tiring. It would be nice if one could have a desktop app that interfaces with the remote WP-Super-Cache instance. This is exactly what we will do in the current post.<br />
<span id="more-2898"></span></p>
<h4>RPC interface plugin</h4>
<p>WordPress provides the XML_RPC interface to remotely post content to your blog. By default this interface is disabled for security reasons. But it can be a wonderful way to communicate with your WordPress plugins. WordPress has an extensive set of actions and filters which allow you add/change/remove low level features via plugins and themes. Using this technique plugins can expose new XML-RPC methods for your WordPress blog. A skeleton code to do the same is given below.</p>

<div class="wp_codebox"><table><tr id="p289810"><td class="code" id="p2898code10"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xmlrpc_methods'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_xmlrpc_methods'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_xmlrpc_methods<span style="color: #009900;">&#40;</span><span style="color: #000088;">$methods</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$methods</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'new_rpc_method'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my_method'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$methods</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_method<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #009933; font-style: italic;">// Do all your custom programming here</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The following is a short plugin that exposes a few of the WP-Super-Cache functions to the outside world as an RPC interface. This enables you to control a few WP-Super-Cache functions like disabling cache, enabling cache, clearing cache and checking cache status from another program. This program can be a desktop Adobe AIR application, a JavaScript plugin or another PHP application. The code for the complete plugin is shown below. </p>
<p>To make this all work you will first have to activate the XML-RPC interface for your WordPress blog. You can activate the same from the <em>admin > settings > writing > Remote Publishing</em> section. The XML_RPC interface is controlled by your &#8216;xmlrpc.php&#8217; file on your server.</p>

<div class="wp_codebox"><table><tr id="p289811"><td class="code" id="p2898code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/*
Plugin Name: Wp SuperCache API
Plugin URI: http://www.codediesel.com
Description: Expose a few Wp-SuperCache function for RPC
Version: 0.8
Author: Sameer Borate
Author URI: http://www.codediesel.com
*/</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Add your custom RPC method to the Wordpress RPC methods list */</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xmlrpc_methods'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_xmlrpc_methods'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_xmlrpc_methods<span style="color: #009900;">&#40;</span><span style="color: #000088;">$methods</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$methods</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wpSuperCacheRPC'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my_cacheStatus'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$methods</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_cacheStatus<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">// Parse the arguments, take note that they're in the correct order</span>
    <span style="color: #000088;">$username</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$password</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$action</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_xmlrpc_server</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">// Let's run a check to see if credentials are okay</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$wp_xmlrpc_server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_cache_is_enabled'</span><span style="color: #009900;">&#41;</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;">$cache_path</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;cache_status&quot;</span>  <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">return</span> wp_cache_is_enabled<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                                   <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;cache_enable&quot;</span>  <span style="color: #339933;">:</span> wp_cache_enable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                                   <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;cache_disable&quot;</span> <span style="color: #339933;">:</span> wp_cache_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                                   <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;cache_clear&quot;</span>   <span style="color: #339933;">:</span> prune_super_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_path</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: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Note that the functions I&#8217;ve used in the plugin: wp_cache_is_enabled(), wp_cache_enable(), wp_cache_disable(), prune_super_cache() are defined in the WP-Super-Cache plugin to accomplish their respective tasks.</p>
<h4>RPC interface client</h4>
<p>A sample PHP RPC client to work with the above code is shown below. Here we request the &#8216;cache_status&#8217; function from the remote server.</p>

<div class="wp_codebox"><table><tr id="p289812"><td class="code" id="p2898code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* XML_RPC Client to access the above plugin functions */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> wpSuperCacheRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rpc_url</span><span style="color: #339933;">,</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #990000;">xmlrpc_encode_request</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpSuperCacheRPC'</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$rpc_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$rpc_server</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://your-wordpress-site.com/xmlrpc.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Return '0' if cache is disabled or  '1' if enabled */</span>
<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'cache_status'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
  * Action can be any of the following :
  *
  * cache_status
  * cache_enable
  * cache_disable
  * cache_clear
  */</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* 'USER', 'PASSWORD' is your WordPress admin credentials */</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> wpSuperCacheRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rpc_server</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'USER'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$data</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you have never used a XML_RPC code on your machine you could get the following error after you run the above client program.</p>

<div class="wp_codebox"><table><tr id="p289813"><td class="code" id="p2898code13"><pre class="php" style="font-family:monospace;">Fatal error<span style="color: #339933;">:</span> Call to undefined <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">xmlrpc_encode_request</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>To rectify just enable the following line in your php.ini (on Windows).</p>

<div class="wp_codebox"><table><tr id="p289814"><td class="code" id="p2898code14"><pre class="php" style="font-family:monospace;">extension<span style="color: #339933;">=</span>php_xmlrpc<span style="color: #339933;">.</span>dll</pre></td></tr></table></div>

<h4>Testing the interface</h4>
<p>Now when you run the above client program, it will connect with the remote WordPress site with the help of the plugin and control the wp-super-cache functionality.</p>
<p>When you use the &#8216;cache_clear&#8217; function in the above client program and you want to check if the cache is actually cleared on the web server, make sure that you click on the <em>Regenerate cache stats</em> link in the wp-super-cache admin section to refresh the status. Not doing so will probably show you the old data and you may wonder why the code is not working.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/controlling-wordpress-plugins-remotely/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rethinking Pagination</title>
		<link>http://www.codediesel.com/wordpress/rethinking-pagination/</link>
		<comments>http://www.codediesel.com/wordpress/rethinking-pagination/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 06:27:50 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[interface]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2892</guid>
		<description><![CDATA[Pagination is one of the ubiquitous UI elements in website design. Designed in various formats and color combinations, this UI element has remained relatively static with respect to its usability functions. But in my opinion there is a lot more we can squeeze out of this little element. My pet peeve regarding pagination is its [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2011/08/pagination.jpg"><img src="http://www.codediesel.com/wp-content/uploads/2011/08/pagination.jpg" alt="" title="pagination" width="190" height="163" class="alignleft size-full wp-image-2897" /></a>Pagination is one of the ubiquitous UI elements in website design. Designed in various formats and color combinations, this UI element has remained relatively static with respect to its usability functions. But in my opinion there is a lot more we can squeeze out of this little element. My pet peeve regarding pagination is its inability to inform me about the content residing on a particular page in question, especially in Worpress like CMS.<br />
<span id="more-2892"></span><br />
For example if I’m browsing a site and am only interested in some particular type of posts, I’ve no way to quickly identify the posts on each page. And many sites do not make it easier as they do not even have any archive page. The only way forward is to visit each page and search for the relevant content. It would be wonderful if one could quickly glance at the post titles on each page from the pagination links itself as shown in the diagram below.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/08/pager-preview-raw1.png"><img src="http://www.codediesel.com/wp-content/uploads/2011/08/pager-preview-raw1.png" alt="" title="pager-preview-raw" width="262" height="272" class="aligncenter size-full wp-image-2894" /></a></p>
<p>But I’ve doubts whether this will be useful with pagination that just shows ‘next page’ and ‘previous page’ links. Still I think it is worth looking into. To see the concept in action you can check the pagination links on the current blogs home page. The present iteration just displays the post titles; adding click-able links to the displayed post titles will be another good idea (<em>currently <del datetime="2011-12-10T05:59:26+00:00">implemented</del> removed, but still in testing phase</em>).</p>
<h4>Creating the concept</h4>
<p>For building the preview I used the <a href="http://wordpress.org/extend/plugins/wp-paginate/" rel="nofollow" target="_blank"  title="wp-paginate">wp-paginate</a> WordPress plugin and modified a couple of functions to extract the post titles. The preview tool-tip uses the excellent jQuery <a href="http://craigsworks.com/projects/qtip2/" rel="nofollow" target="_blank"  title="qTip2 plugin">qTip2</a> plugin to display the post titles on hovering over the pagination links.</p>
<p>Although this looks like extra investment in time for a small return; in my opinion it somewhat increases the usability for the user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/wordpress/rethinking-pagination/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Create stunning mobile / iPad versions of your WordPress site</title>
		<link>http://www.codediesel.com/wordpress/create-stunning-mobile-ipad-versions-of-your-wordpress-site/</link>
		<comments>http://www.codediesel.com/wordpress/create-stunning-mobile-ipad-versions-of-your-wordpress-site/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 12:04:19 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2875</guid>
		<description><![CDATA[WPtouch Pro! is a WordPress plugin for self-hosted WordPress websites that shows a well-designed mobile theme version of your site when visitors are using popular touch mobile devices like the iPhone/iPod touch, Google Android phones, Palm Pre/Pixi, Samsung bada and Blackberry Storm &#038; Torch devices. WPtouch Pro works by automatically detecting these devices and serves [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2011/08/formatting.png"><img src="http://www.codediesel.com/wp-content/uploads/2011/08/formatting.png" alt="" title="mobile theming plugin for wordpress" width="178" height="179" class="alignleft size-full wp-image-2876" /></a>WPtouch Pro! is a WordPress plugin for self-hosted WordPress websites that shows a well-designed mobile theme version of your site when visitors are using popular touch mobile devices like the iPhone/iPod touch, Google Android phones, Palm Pre/Pixi, Samsung bada and Blackberry Storm &#038; Torch devices.<br />
<span id="more-2875"></span><br />
<a href="http://www.bravenewcode.com/store/plugins/wptouch-pro/?bnc_affiliate_id=22497&#038;utm_source=affiliate-22497&#038;utm_medium=affiliates&#038;utm_campaign=text1" rel="nofollow"  title="Get WPtouch Pro!" target="_blank">WPtouch Pro</a> works by automatically detecting these devices and serves its mobile/tablet-friendly themes. Desktop visitors still see your regular theme, and changes to it do not affect WPtouch Pro and vice-versa.</p>
<p>The plugin just doesn&#8217;t glue together RSS feeds, or use a proxy server to modify your site&#8217;s look— It creates a full-fledged theme, completely separate from your desktop theme that offers most of WordPress&#8217; native features, &#038; works with other plugins, too.</p>
<p>The plugin requires WordPress 3.1 or higher.</p>
<p><em>Disclaimer: The above link to WPtouch Pro is a affiliate sponsorship.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/wordpress/create-stunning-mobile-ipad-versions-of-your-wordpress-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmarking WordPress SQL using FirePHP</title>
		<link>http://www.codediesel.com/mysql/benchmarking-wordpress-sql-using-firephp/</link>
		<comments>http://www.codediesel.com/mysql/benchmarking-wordpress-sql-using-firephp/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 09:10:16 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/php/benchmarking-wordpress-sql-using-firephp/</guid>
		<description><![CDATA[Benchmarking your Wordpress SQL]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.codediesel.com/wp-content/uploads/2010/02/firephp_thumb.gif" alt="firephp_thumb" title="firephp_thumb" width="331" height="185" class="alignleft size-full wp-image-2478" />Building and running a WordPress site is a simple matter. WordPress is a considerably fast CMS system, until you start to add more and more plugins and one day you notice that Worpdress has started to slow down. It may be the case that SQL queries within some plugins are not optimized and are taking an increased amount of time executing them, this can considerably slow down your site. The first thing you can do to rectify the situation is to find out where exactly the bottleneck resides by analyzing the time each SQL query takes to executes. Some inquisitive people among you may also be interested in knowing in what sequence the WordPress SQL queries themselves are being run. Not that all bottlenecks occur due to unoptimized SQL, most are due to poor coding practices. Whatever the reason; the following post will show you how to look inside the SQL query execution of WordPress.<br />
<span id="more-2443"></span></p>
<h4>Logging WordPress SQL queries</h4>
<p>By default WordPress doesn&#8217;t log any queries. But you can instruct WordPress to do so  by adding the following configuration option to your WordPress &#8216;wpconfig.php&#8217; file.</p>

<div class="wp_codebox"><table><tr id="p244315"><td class="code" id="p2443code15"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/* wp-config.php */</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SAVEQUERIES'</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></pre></td></tr></table></div>

<p>Once that is done you can add the following lines at the end of your WordPress themes &#8216;footer.php&#8217; file.</p>

<div class="wp_codebox"><table><tr id="p244316"><td class="code" id="p2443code16"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/* footer.php */</span>
<span style="color: #339933;">..</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span></pre></td></tr></table></div>

<p>This will display the SQL statements executed by your WordPress installation in a raw format as shown below. It displays a total of three items &#8211; the executed query, the execution time of the query and the function that called the query.</p>

<div class="wp_codebox"><table><tr id="p244317"><td class="code" id="p2443code17"><pre class="text" style="font-family:monospace;">Array
(
    [0] =&gt; Array
        (
            [0] =&gt; SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'
            [1] =&gt; 0.004619836807251
            [2] =&gt; require, require_once, require_once, require_once, is_blog_installed, wp_load_alloptions
        )
&nbsp;
    [1] =&gt; Array
        (
            [0] =&gt; SELECT option_value FROM wp_options WHERE option_name = 'sidebars_widgets' LIMIT 1
            [1] =&gt; 0.0015749931335449
            [2] =&gt; require, require_once, require_once, require_once, do_action, call_user_func_array, wp_widgets_init, register_widget, WP_Widget_Factory-&gt;register, WP_Widget_Recent_Comments-&gt;WP_Widget_Recent_Comments, is_active_widget, wp_get_sidebars_widgets, get_option
        )
.
.</pre></td></tr></table></div>

<p>As you can see the raw information is not interesting to look at and it also clutters the actual site. A better way is to use FireBug and FirePHP to log the SQL queries without interfering with the WordPress output.</p>
<h4>Installing FirePHP</h4>
<p>Before starting you need to have <a href="https://addons.mozilla.org/en-US/firefox/addon/6149/" rel="nofollow" target="_blank" >FirePHP</a> and <a href="https://addons.mozilla.org/en-US/firefox/addon/1843" rel="nofollow" target="_blank" >FireBug</a> installed. FirePHP uses FireBugs console window to output the debug messages.  Once you have installed FirePHP and FireBug, you need to install the FirePHP <a href="http://www.firephp.org/HQ/Install.htm" rel="nofollow" target="_blank" >server libraries</a>. Copy the FirePHP server libraries to your WordPress themes directory. For e.g &#8216;wordpress\wp-content\themes\default\FirePHPCore&#8217;.</p>
<p>If you are unfamiliar with FirePHP a nice tutorial can be found at <a href="http://sixrevisions.com/web-development/how-to-debug-php-using-firefox-with-firephp/" rel="nofollow" target="_blank" >Six Revisions</a>.</p>
<h4>Displaying formatted information with FirePHP</h4>
<p>Once we are done with the above setup, you can add the following code at the end of your WordPress themes &#8216;footer.php&#8217; file, replacing the code we previously added.</p>

<div class="wp_codebox"><table><tr id="p244318"><td class="code" id="p2443code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* footer.php */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;FirePHPCore/FirePHP.class.PHP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$query_table</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SQL&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Execution Time&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Calling Function&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$expensive_query_time</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$expensive_query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$total_time</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queries</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$query_table</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009933; font-style: italic;">/* Get the most expensive query */</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$expensive_query_time</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$expensive_query_time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$expensive_query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$total_time</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$total_queries</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$firephp</span> <span style="color: #339933;">=</span> FirePHP<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* Display the queries in a formatted table */</span>
    <span style="color: #000088;">$firephp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">group</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Query'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Collapsed'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>  
                                    <span style="color: #0000ff;">'Color'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'#000'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$firephp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$total_queries</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; queries took &quot;</span> <span style="color: #339933;">.</span> 
                    <span style="color: #000088;">$total_time</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; seconds.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query_table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* Display the query summary */</span>
    <span style="color: #000088;">$firephp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">group</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Query Summary'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Collapsed'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>  
                                            <span style="color: #0000ff;">'Color'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'#000'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$firephp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$total_queries</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Total Queries'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$firephp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$expensive_query</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Expensive Query'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$firephp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$expensive_query_time</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Expensive Query Time'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Refresh your WordPress page and you should see the following output in the FireBug console. Click on the image below to view the complete debug screen. (Some queries have been removed for size.) As you can see FirePHP displays a nicely formatted output than the previous one.</p>
<p><a href="http://www.codediesel.com/data/images/firephp_large.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/02/firephp.gif" alt="firephp" title="firephp" width="563" height="247" class="aligncenter size-full wp-image-2455" /></a></p>
<h4>Modifying the query data returned by WordPress</h4>
<p>WordPress by default saves and returns the following three parameters for each SQL query:<br />
1. SQL query<br />
2. Query Execution time<br />
3. The method chain that called the query.</p>
<p>The code section where this happens is located in the query() method of the &#8216;wp-db.php&#8217; file in the WordPress &#8216;wp-includes&#8217; directory. The following snippet shows that section of code:</p>

<div class="wp_codebox"><table><tr id="p244319"><td class="code" id="p2443code19"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/* wp-db.php */</span>
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
<span style="color: #009933; font-style: italic;">// Log how the function was called</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">func_call</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\$</span>db-&gt;query(<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$query</span><span style="color: #000099; font-weight: bold;">\&quot;</span>)&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">// Keep track of the last query for debug..</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">// Perform the query via std mysql_query function..</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SAVEQUERIES'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> SAVEQUERIES <span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timer_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">++</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_queries</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SAVEQUERIES'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> SAVEQUERIES <span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queries</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timer_stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
                              <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_caller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span></pre></td></tr></table></div>

<p>You can modify the code to add some extra parameters as per your requirements, or modify the format in which it is returned. For example you could add code to save the data to a xml or csv file for latter retrieval and analysis.</p>
<p><strong>Note:</strong> Turning on the <em>define(&#8216;SAVEQUERIES&#8217;, true)</em> option can slow down your WordPress site, so make sure you disable it after your work is done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/mysql/benchmarking-wordpress-sql-using-firephp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.267 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-08 10:55:09 -->

