<?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>Index of /andrejciho &#187; WordPress</title>
	<atom:link href="http://www.andrejciho.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andrejciho.com</link>
	<description>Personal blog of a webdeveloper</description>
	<lastBuildDate>Sat, 04 Feb 2012 01:52:18 +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>Extension of the WPDB class that throws exceptions on SQL error</title>
		<link>http://www.andrejciho.com/wordpress/extension-of-the-wpdb-class-that-throws-exceptions-on-sql-error/</link>
		<comments>http://www.andrejciho.com/wordpress/extension-of-the-wpdb-class-that-throws-exceptions-on-sql-error/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 01:52:18 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/?p=159</guid>
		<description><![CDATA[NOW you can tell a SQL error apart from empty result set]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://codex.wordpress.org/Class_Reference/wpdb">WPDB</a> (WordPress&#8217; database class) gives you two options how to handle SQL errors. You either show them in the browser to everybody:</p>
<pre><code>$wpdb-&gt;show_errors();</code></pre>
<p>or any potential the failure happens silently</p>
<pre><code>$wpdb-&gt;hide_errors();</code></pre>
<p>with results of the SQL query coming back as blank and you can&#8217;t tell &#8220;nothing found&#8221; apart from &#8220;SQL error&#8221;.</p>
<p>I needed a better way to deal with SQL errors. PHP allows for throwing and catching exceptions (read more about it <a href="http://php.net/manual/en/language.exceptions.php">here</a>) which I highly encourage all of us WordPress developers to get very familiar with if you aren&#8217;t already. I cooked up a simple plugin that basically extends the WPDB class redefining some select methods and allows me to capture the SQL errors for further processing.</p>
<p>Here&#8217;s how I can interact with this extended class in my plugins or theme files:</p>
<pre><code>try {
    $transactions = $wpdb_e-&gt;get_results($query);
} catch (Exception $e) {
    // You can decide what to do with a SQL failure at this point, here are some ideas:
    if (WP_DEBUG) die($e-&gt;getMessage());
    echo 'We apologize but we were not able to retrieve your transactions';
    wp_mail('myname@mydomain.com', bloginfo('name') . ' has a SQL error', $e-&gt;getMessage());
}

if (empty($transactions))  echo 'You have no transactions as of yet';</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/extension-of-the-wpdb-class-that-throws-exceptions-on-sql-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging a live WordPress site using WP_DEBUG</title>
		<link>http://www.andrejciho.com/wordpress/debugging-a-live-wordpress-site-using-wp_debug/</link>
		<comments>http://www.andrejciho.com/wordpress/debugging-a-live-wordpress-site-using-wp_debug/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 01:39:32 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/?p=166</guid>
		<description><![CDATA[Enable WP_DEBUG messages just for YOU, but nobody else]]></description>
			<content:encoded><![CDATA[<p>WP_DEBUG is a boolean constant found in wp-config.php. When set to <em>true</em>, all php errors (and warnings and notifications) are printed in the browser. This is very useful during development but can be dangerous because text of php errors often reveals unnecessary details about your programming code, paths, etc to visitors in case they run into an issue with your site. For production sites this is always set to <em>false</em>.</p>
<p>But what do you do when you get a frantic client phone call reporting an issue on the live site? You can&#8217;t just enable WP_DEBUG for everybody and very likely break the site&#8217;s design as various error messages of sloppy plugin or WordPress&#8217; core code might render.</p>
<p>Solution is simple: Enable WP_DEBUG just for <em>you</em>.</p>
<p>First, you&#8217;ll need to know your outgoing IP address. When I&#8217;m lazy I go to my friend <a href="http://derosia.com">Topher&#8217;s beautiful website</a> which tells me my IP address.</p>
<p>Then edit your wp-config.php (CAREFUL) by replacing:</p>
<pre><code>define('WP_DEBUG', false);</code></pre>
<p>with</p>
<pre><code>if ($_SERVER['REMOTE_ADDR'] == '123.123.123.123') {
	define('WP_DEBUG', true);	
} else {
	define('WP_DEBUG', false);
}</code></pre>
<p>(don&#8217;t forget to replace 123.123.123.123 with your outgoing IP address)</p>
<p>By the way this is a great solution if you&#8217;re working from home or are tethering using your phone so that you are the only one coming from this IP address. If you&#8217;re in the same building with your client and try to debug the site without freaking out the CEO this might not be the best because odds are you and her are coming from the same IP address and she&#8217;ll see the same debug junk you do.</p>
<p>Please let me know if this was any helpful to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/debugging-a-live-wordpress-site-using-wp_debug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Patch for Pods CMS 1.8.1 &#8211; mysql_real_escape_string</title>
		<link>http://www.andrejciho.com/wordpress/patch-for-pods-cms-1-8-1-mysql_real_escape_string/</link>
		<comments>http://www.andrejciho.com/wordpress/patch-for-pods-cms-1-8-1-mysql_real_escape_string/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 15:41:42 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/?p=154</guid>
		<description><![CDATA[A patch to Pods CMS 1.8.1 to add a link_identifier as a second parameter to mysql_real_escape_string to avoid "access denied" errors]]></description>
			<content:encoded><![CDATA[<p>At <a href="http://atlantawordcamp.com/" target="_blank">Wordcamp Atlanta</a> I learned about <a href="http://pods.uproot.us/" target="_blank">Pods CMS</a> &#8211; a powerful WordPress plugin allowing you to build your content types, giving you an admin to add/edit/delete (kinda like RoR&#8217;s scaffolding) and an easy way to pull it out of database in your template. Very powerful plugin. Needless to say another world of possibilities opened up for me.</p>
<p>After spending some time on setting things up on my local box I uploaded it to a staging environment on our server and noticed a &#8220;mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user: &#8216;nobody@localhost&#8217;&#8221; error.</p>
<p>If you look up <a href="http://php.net/manual/en/function.mysql-real-escape-string.php" target="_blank">mysql-real-escape-string</a> in the php manual you&#8217;ll notice that the second and optional parameter is <em>link_identifier</em> (the db resource). The manual describes it as:</p>
<blockquote><p>The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an E_WARNING level error is generated.</p></blockquote>
<p>There might be another solution to the problem, for example changing a setting on the server, but if you don&#8217;t know how to change it or don&#8217;t have permissions to do so, you can modify code of Pods CMS so that anytime it calls mysql_real_escape_string it passes the link_identifier. Here is a <a href="http://www.andrejciho.com/wp-content/uploads/2010/01/mysql_real_escape_string_1.8.1.txt">patch</a> I created.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/patch-for-pods-cms-1-8-1-mysql_real_escape_string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Relative Bookmarks for WordPress Admin Pages</title>
		<link>http://www.andrejciho.com/wordpress/relative-bookmarks-for-wordpress-admin-pages/</link>
		<comments>http://www.andrejciho.com/wordpress/relative-bookmarks-for-wordpress-admin-pages/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 14:22:18 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/?p=147</guid>
		<description><![CDATA[Get around wordpress admin menus quickly - on any wordpress blog]]></description>
			<content:encoded><![CDATA[<p>A recent <a href="http://twitter.com/andrea_r/status/3405028496">tweet</a> by @andrea_r inspired me to post my relative bookmarks (bookmarklets rather) solution. If you manage a lot of websites in WordPress, you probably find yourself jumping around the administrative area a good bit and while the 2.8 admin redesign helped a lot in saving time, using these universal bookmarks takes it a step further.</p>
<p>It is quite simple. I created a folder in my Bookmarks Toolbar in Firefox and placed the bookmarks I use the most in it, as shown below:</p>
<p><img class="alignnone size-full wp-image-148" title="wp-admin" src="http://www.andrejciho.com/wp-content/uploads/2009/08/wp-admin.PNG" alt="wp-admin" width="168" height="228" /></p>
<p>The way to make this URL/blog independent is link to relative page, for example &#8220;Add New Post&#8221; points to post-new.php (which needs to point to www.andrejciho.com/wp-admin/post-new.php on this blog). The &#8220;relativeness&#8221; is done via javascript so the &#8220;Location&#8221; of the bookmark is:</p>
<blockquote><p>javascript:window.location=&#8217;post-new.php&#8217;</p></blockquote>
<p>So you can really roll your own bookmarks following the pattern above. The links in the</p>
<blockquote><p>javascript:window.location=&#8217;post-new.php&#8217;<br />
javascript:window.location=&#8217;edit.php&#8217;<br />
javascript:window.location=&#8217;page-new.php&#8217;<br />
javascript:window.location=&#8217;edit-pages.php&#8217;<br />
javascript:window.location=&#8217;link-add.php&#8217;<br />
javascript:window.location=&#8217;link-manager.php&#8217;<br />
javascript:window.location=&#8217;plugins.php&#8217;</p></blockquote>
<p><strong>Note: </strong>These bookmarks only work once you are already logged in and within WordPress admin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/relative-bookmarks-for-wordpress-admin-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excerpt for Pages</title>
		<link>http://www.andrejciho.com/wordpress/excerpt-for-pages/</link>
		<comments>http://www.andrejciho.com/wordpress/excerpt-for-pages/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 01:59:38 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/?p=105</guid>
		<description><![CDATA[Brings back excerpt entry field to page edit]]></description>
			<content:encoded><![CDATA[<p>Some time ago, WordPress folks decided to discontinue excerpts for pages. All of my searches point to a blog that supposedly has a plugin that will bring this back but their server is not serving and I&#8217;m impatient so here&#8217;s an easy way how I got it running on my WordPress 2.6.2:</p>
<p>The only thing the code below does is that it enables the Excerpt field in the /wp-admin/page.php and saves it to the database. You still have to do the work of wiring it up into your template yourself. I <em>might</em> update it later.</p><pre><code>&lt;code&gt;
&lt;div id=&quot;postexcerpt&quot; class=&quot;postbox &lt;?php echo postbox_classes('postexcerpt', 'post'); ?&gt;&quot;&gt;
&lt;div class=&quot;inside&quot;&gt;
&lt;textarea id=&quot;excerpt&quot; cols=&quot;40&quot; rows=&quot;4&quot; name=&quot;excerpt&quot;&gt;&lt;?php echo $post-&amp;gt;post_excerpt ?&gt;&lt;/textarea&gt;
&lt;/div&gt;
&lt;/code&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/excerpt-for-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving WordPress to a different URL</title>
		<link>http://www.andrejciho.com/wordpress/moving-wordpress-to-a-different-url/</link>
		<comments>http://www.andrejciho.com/wordpress/moving-wordpress-to-a-different-url/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 15:48:41 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/wordpress/moving-wordpress-to-a-different-url/</guid>
		<description><![CDATA[A set of DB queries to help switch the URL]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve mentioned this in the past in my <a href="http://www.andrejciho.com/linux/nightly-mysql-backup/">Nightly Mysql Backup</a> but just recently realized I also have to update the <strong>guid</strong></p>
<pre><code>&lt;code&gt;
UPDATE wp_posts
SET post_content = REPLACE(post_content,'localhost/test','www.example.com'),
guid = REPLACE(guid,'localhost/test','www.example.com');
UPDATE wp_options
SET option_value = REPLACE(option_value,'localhost/test','www.example.com');
&lt;/code&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/moving-wordpress-to-a-different-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Placeholders for WordPress</title>
		<link>http://www.andrejciho.com/wordpress/placeholders-for-wordpress/</link>
		<comments>http://www.andrejciho.com/wordpress/placeholders-for-wordpress/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 18:17:18 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/wordpress/placeholders-for-wordpress/</guid>
		<description><![CDATA[Insert placeholders in your posts/pages and have functionality be tied to those.]]></description>
			<content:encoded><![CDATA[<p>When implementing WordPress for a client, there are the times when you need to place things like a PayPal donate button or a small javascript or whatever into a page. I wanted to give the client the ability to insert the PayPal button on any page they choose to without having to tell them about html. Inspired by the way <a href="http://www.deliciousdays.com/cforms-plugin">cform II</a> WordPress plug-in uses a placeholder to accomplish this, I came up with this plugin.Now I just tell the client to place for example ##paypalbutton## wherever, and the plugin replaces the placeholder with the real html behind the scenes.I could write a fancy interface to configure this, but instead, you can just edit the plugin file.</p>
<p><strong>Target Audience: </strong> Semi-advanced WordPress <em>Implementors</em></p>
<p><em></em>License: <a href="http://www.gnu.org/licenses/gpl.txt" target="_blank">GPL</a></p>
<p><a href="http://www.gnu.org/licenses/gpl.txt" target="_blank"></a><a title="Placeholders for WordPress" href="http://www.andrejciho.com/wp-content/uploads/2008/03/placeholdersphp.txt">Download placeholdersphp.txt</a> (don&#8217;t forget to rename to placeholders.php or whatever)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/placeholders-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress (or any CMS) to html files</title>
		<link>http://www.andrejciho.com/wordpress/wp2html/</link>
		<comments>http://www.andrejciho.com/wordpress/wp2html/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 00:37:26 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/wordpress/wp2html/</guid>
		<description><![CDATA[Can you host a website made in <em>WordPress on IIS</em>? Or one made in <em>DotNetNuke on Apache</em>? Sort of.]]></description>
			<content:encoded><![CDATA[<p>Can you host a website made in <em>WordPress on IIS</em>? Or one made in <em>DotNetNuke on Apache</em>? Yes! Now I am NOT about the describe how you can run those application where they weren&#8217;t meant to run. I&#8217;ll just show you how you can have a CMS spit out plain html files &#8211; no need for database or server-side scripting.</p>
<p>Yes, I&#8217;m probably crazy &#8211; I understand that situations where this would be applicable are only a few. That&#8217;s because my &quot;solution&quot; will work well (without additional labor) only for &quot;static&quot; websites &#8211; no forms (including contact/comment forms). I&#8217;ll list a few applicable situations at the bottom of this post.</p>
<ol>
<li>Let&#8217;s say you created the website and set it up under http://localhost/mywebsite. (If it is WordPress, you may need to change the relative references in your theme&#8217;s css to absolute) </li>
<li>In your Linux terminal or Cygwin on your Windows machine, run the following <em>wget</em> command:<br />
<pre><code>&lt;code&gt;wget --html-extension --recursive --page-requisites --progress=bar --mirror http://localhost/mywebsite&lt;/code&gt;</code></pre><br />
This will generate an html file for every page of your website.</li>
<li>Once you have all the files, you will want to mass find-and-replace all instances of localhost/mywebsite to e.g. www.andrejciho.com. The script below is a powerful one. It finds and replace stuff inside of all files under a folder, no matter how deep inside the directory structure:<br />
<pre><code>&lt;code&gt;find . -type f -exec sed -i 's/localhost\\/mywebsite/www.andrejciho.com/g' {} \\;&lt;/code&gt;</code></pre></li>
</ol>
<p>Possible applicable situations:</p>
<ul>
<li>University IT department gives a student government FrontPage access to a folder on their server, but no database access. The student government folks are good with WordPress.</li>
<li>Your client demands that you migrate the website you made for them in WordPress to their IIS server.</li>
<li>You want your server to exert as little energy as possible when serving your website.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/wp2html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Production and Development Environments using WordPress</title>
		<link>http://www.andrejciho.com/wordpress/production-and-development-environments/</link>
		<comments>http://www.andrejciho.com/wordpress/production-and-development-environments/#comments</comments>
		<pubDate>Sun, 11 Feb 2007 20:39:16 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/wordpress/production-and-development-environments-using-wordpress/</guid>
		<description><![CDATA[Short article about how you can set up a separate and independent <em>pre-production</em> environment for your wordpress website.]]></description>
			<content:encoded><![CDATA[<p>Several web hosting companies offer a one-click install (and one-click updates) of WordPress. While this is very convenient, I would not recommend using it for a production (LIVE) website with any kind of significant, around-the-clock traffic. Reasons? Among other things that could break, there is always the chance that one of your plugins is not compatible with the latest build &#8211; either by displaying some kind of ugly error after the upgrade or just silently ceasing to work properly.</p>
<p>My proposition is to set up a separate, development (DEV), instance of your website, under a separate URL, using its own database, and of course, separate file structure. In this environment, you can use the one-click install, try new plugins, perform and test theme modifications, etc. without the risk of breaking anything on your LIVE website.</p>
<p>The task this article wrestles with is trying to create an easy way to a) <em>deploy</em> your changes from DEV to LIVE environment, and b) to <em>restore</em> the LIVE environment to DEV to have the most current version for messing with. The scripts I show help me with semi-automating these tasks.</p>
<p>So to set up this DEV environment, you&#8217;ll need&#8230;</p>
<ul>
<li>A dedicated subdomain. To make it easy to remember, you can set up dev.yoururl.com to be your DEV environment for your www.yoururl.com.</li>
<li>A dedicated database</li>
</ul>
<hr />
<p><strong>SCRIPT 1: Restores LIVE database (or its <a href="http://www.andrejciho.com/linux/nightly-mysql-backup/">previously created dump</a>) to DEV database. </strong></p>
<pre><code>&lt;code&gt;
#!/bin/bash

# Directory to be used for temp files created by this script
BTEMP_DIR=         # e.g. /home/andrej/.restore_temp
# If you are restoring from a previously created database dump
BACKUP_DIR=        # e.g. /mnt/hda7/db_dump

# Your database access credentials
BMYSQL_HOST=       # e.g. localhost or mysql.yoururl.com
BMYSQL_USER=       # e.g. andrej
BMYSQL_PWD=        # your password

# Source Database
BMYSQL_DBNAME=     # e.g. wordpressLIVE

# Target Database
BMYSQL_DBTARGET=   # e.g. wordpressDEV

# Script (.sql) to run after the database is restored
BPOST_RESTORE=     # e.g. /home/andrej/.scripts/post_live_to_dev.sql
# This script mentioned above can contain these two useful statements 
# and possibly other
# UPDATE wp_posts 
# SET post_content = REPLACE(post_content,'www.yoururl.com','dev.yoururl.com');
# UPDATE wp_options 
# SET option_value = REPLACE(option_value,'www.yoururl.com','dev.yoururl.com');

#  Make sure output directory exists.
if [ ! -d $BTEMP_DIR ]; then
    mkdir -p $BTEMP_DIR
fi
&lt;/code&gt;</code></pre>
<p>If you are restoring from a previously generated backup as described in my post about nightly MySQL backups, add the following:</p>
<pre><code>&lt;code&gt;

# gunzip and write contents of the db backup to a temporary sql_to_run.sql
cat $BACKUP_DIR/$BMYSQL_DBNAME.gz.0 | gunzip &gt; $BTEMP_DIR/sql_to_run.sql 2&gt;/dev/null

&lt;/code&gt;</code></pre><p><p>otherwise add the following:</p>
<pre><code>&lt;code&gt;
# Dump (sounds scary, but really means export) database to a temp file
mysqldump --host=$BMYSQL_HOST --user=$BMYSQL_USER --pass=$BMYSQL_PWD --add-drop-table $BMYSQL_DBNAME | gzip &gt; $BTEMP_DIR/$BMYSQL_DBNAME

# gunzip and write contents of the temp file to a temporary sql_to_run.sql file
cat $BTEMP_DIR/$BMYSQL_DBNAME | gunzip &gt; $BTEMP_DIR/sql_to_run.sql 2&gt;/dev/null
&lt;/code&gt;</code></pre><p><p>
<p>&#8230;and now everybody continue here:</p>
<pre><code>&lt;code&gt;
# read from $BPOST_RESTORE file mentioned above and add to the end of
# the temporary sql_to_run.sql file
less $BPOST_RESTORE &gt;&gt; $BTEMP_DIR/sql_to_run.sql

# run the generated sql_to_run.sql file
mysql --host=$BMYSQL_HOST --user=$BMYSQL_USER --pass=$BMYSQL_PWD $BMYSQL_DBTARGET &lt; $BTEMP_DIR/sql_to_run.sq
&lt;/code&gt;</code></pre><p><p><p>
<p>OK, the DEV database should be successfully restored to what the LIVE looks like.</p>
<hr />
<p><strong>SCRIPT 2: Make an identical copy of the LIVE file structure to DEV:</strong></p>
<p>If you are restoring from a file backup described in <a href="http://www.andrejciho.com/linux/nightly-file-backup/">my previous post</a>, add the following:</p>
<pre><code>&lt;code&gt;
#!/bin/bash
# your backup file
SOURCE_FILE=     # e.g. /mnt7/backup/www.yoururl.com.tgz.0
# your DEV folder
TARGET_DIR=      # e.g. /var/www/dev.yoururl.com

# Clean everything in the DEV folder
rm $TARGET_DIR/* -R   &gt;/dev/null 2&gt;&amp;1
# Restore files from the backup file
tar xvzf $SOURCE_FILE -C $TARGET_DIR
&lt;/code&gt;</code></pre><p><p><p><p>
<p>If there is no file backup, just create a copy using <em>rsync</em>.</p>
<pre><code>&lt;code&gt;
#!/bin/bash
# Path to your LIVE file structure
SOURCE_DIR =   # e.g. /var/www/www.yoururl.com
# Path to your DEV file structure
TARGET_DIR =   # e.g. /var/www/dev.yoururl.com

# create a mirror of LIVE on DEV (deleting DEV files)
rsync -a --delete --exclude &quot;wp-config.php&quot; --exclude &quot;/cache/wp-cache-&quot; $SOURCE_DIR/ $TARGET_DIR
&lt;/code&gt;</code></pre><p><p><p><p><p>
<p><strong>IMPORTANT: After you restore your WordPress file system, make sure to edit your wp-config.php to reflect the correct database (DEV or LIVE). You may also have to regenerate permalinks in WordPress' interface under Options, Permalinks.</strong></p>
<p>Messing with the above 2 scripts, you can run this both directions - DEV to LIVE and LIVE to DEV.</p>
<p>Comments and corrections are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/production-and-development-environments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

