<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<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/"
	>

<channel>
	<title>Index of /andrejciho</title>
	<link>http://www.andrejciho.com</link>
	<description>...about Linux, Windows, WebDev, etc.</description>
	<pubDate>Fri, 25 Apr 2008 15:48:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<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[I&#039;ve mentioned this in the past in my Nightly Mysql Backup but just recently realized I also have to update the guid
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');
]]></description>
			<content:encoded><![CDATA[<p>I&#039;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>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');</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress/moving-wordpress-to-a-different-url/feed/</wfw:commentRss>
		</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.<strong>Target Audience: </strong> Semi-advanced WordPress <em>Implementors</em>License: <a href="http://www.gnu.org/licenses/gpl.txt" target="_blank">GPL</a><a href="http://www.andrejciho.com/wp-content/uploads/2008/03/placeholdersphp.txt" title="Placeholders for Wordpress">Download placeholdersphp.txt</a> (don&#039;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>
		</item>
		<item>
		<title>New Design</title>
		<link>http://www.andrejciho.com/general/new-design/</link>
		<comments>http://www.andrejciho.com/general/new-design/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 10:39:07 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/general/new-design/</guid>
		<description><![CDATA[How I got inspired to create this fancy theme]]></description>
			<content:encoded><![CDATA[<p>I was inspired to design this new theme by a friend who at one point registered a domain name and got himself a hosting account, but for some time he didn&#039;t actually put up any files, so his website had the &#034;Index of /&#034; title and a link to parent directory. Many of us teased him about it; in the midst of it, I thought to myself: I need to create a WordPress theme around this &#034;design!&#034; So here it is and I&#039;m keeping it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/general/new-design/feed/</wfw:commentRss>
		</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[<p>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&#039;t meant to run. I&#039;ll just show you how you can have a CMS spit out plain html files - no need for database or server-side scripting. </p>
<p>Yes, I&#039;m probably crazy - I understand that situations where this would be applicable are only a few. That&#039;s because my &quot;solution&quot; will work well (without additional labor) only for &quot;static&quot; websites - no forms (including contact/comment forms). I&#039;ll list a few applicable situations at the bottom of this post.</p>
<ol>
<li>Let&#039;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&#039;s css to absolute) </li>
<li>In your Linux terminal or Cygwin on your Windows machine, run the following <em>wget</em> command:
<pre><code>wget --html-extension --recursive --page-requisites --progress=bar --mirror http://localhost/mywebsite</code></pre>
<p>
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:
<pre><code>find . -type f -exec sed -i 's/localhost\/mywebsite/www.andrejciho.com/g' {} \;</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>
		</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[<p>Short article about how you can set up a separate and independent <em>pre-production</em> environment for your wordpress website.</p>]]></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 - 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&#039;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>#!/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</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>
# 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
</code></pre>
<p>
otherwise add the following:
</p>
<pre><code># 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</code></pre>
<p>&#8230;and now everybody continue here:</p>
<pre><code># 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</code></pre>
<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>#!/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</code></pre>
<p>If there is no file backup, just create a copy using <em>rsync</em>.</p>
<pre><code>#!/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 "wp-config.php" --exclude "/cache/wp-cache-" $SOURCE_DIR/ $TARGET_DIR</code></pre>
<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&#039; 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>
		</item>
		<item>
		<title>Nightly File Backup</title>
		<link>http://www.andrejciho.com/linux/nightly-file-backup/</link>
		<comments>http://www.andrejciho.com/linux/nightly-file-backup/#comments</comments>
		<pubDate>Sun, 11 Feb 2007 19:03:34 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/linux/nightly-file-backup/</guid>
		<description><![CDATA[<p>In a fashion similar to how I described <a href="http://www.andrejciho.com/linux/nightly-mysql-backup/">nightly mysql backup</a>, you can also do nightly file backup.</p>]]></description>
			<content:encoded><![CDATA[<p>In a fashion similar to how I described <a href="http://www.andrejciho.com/linux/nightly-mysql-backup/">nightly mysql backup</a>, you can also do nightly file backup. In this particular example, I used tar with gzip compression because I like to keep the last 7 backups of a website. If I was looking for a script that just backs up one location to another, using <em>rsync</em> with publick key authentication would have been more appropriate and I might talk about that in another post.</p>
<p>As with majority of my posts, I offer nothing new or unique. This is just a script that has been useful to me and if you find it useful, my time and effort in writing this up have been validated.</p>
<p>
<pre><code>#!/bin/sh

#Define your variables here:
SOURCE_DIR=     # e.g. /home/andrej/documents
TARGET_DIR=     # e.g. /mnt/hda7/docbackups
BACKUP_FILENAME=     # e.g. andrejdocs

#  Make sure output directory exists.
if [ ! -d $TARGET_DIR ]; then
    mkdir -p $TARGET_DIR
fi

#  Rotate backups
for j in  6 5 4 3 2 1 0; do
    for i in $TARGET_DIR/$BACKUP_FILENAME.tgz.$j; do
        if [ -e $i ]; then
            mv $i ${i/.$j/}.$(( $j + 1 ));
        fi
    done
done

cd $SOURCE_DIR
tar -cvzf $TARGET_DIR/$BACKUP_FILENAME.tgz.0 *

chmod 600 $TARGET_DIR/$BACKUP_FILENAME.tgz.0
</code></pre>
<p></p>
<p>In the <a href="http://www.andrejciho.com/linux/nightly-mysql-backup/">Nightly MySQL Backup</a> I briefly talk about how to use cron in scheduling scripts to run periodically.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/linux/nightly-file-backup/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Nightly MySQL Backup</title>
		<link>http://www.andrejciho.com/linux/nightly-mysql-backup/</link>
		<comments>http://www.andrejciho.com/linux/nightly-mysql-backup/#comments</comments>
		<pubDate>Sat, 23 Dec 2006 19:43:05 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/linux/nightly-mysql-backup/</guid>
		<description><![CDATA[<p>Simple script to nightly backup your DB and keep last 7 backups.</p>]]></description>
			<content:encoded><![CDATA[<p>For a long time I thought it would be nice to have some kind of automatic regular backup procedure of all of my and my clients&#039; MySQL databases. I just never quite found the time to research it. Then&#8230; the other day, I REALLY wished I would have had a backup.</p>
<p>Either way, after <em>the</em> other day, I did some research and found out how simple it was. So this post isn&#039;t really anything new, just a short compilation of what I found online.</p>
<p>(You will need shell access to the hosting server and your hosting company will need to allow you to run scripts and use cron.)</p>
<p><strong>Backup Script</strong></p>
<p>First you&#039;ll need a backup script that will dump (export, <em>not</em> destroy) the database. I found <a href="http://www.debian-administration.org/articles/218">this one</a> on <a href="http://www.debian-administration.org">www.debian-administration.org</a> and really liked it because it keeps last seven backups - every time you run it, it adds a new backup and gets rid of the oldest one. I had to add the <em>&#8211;host=</em> part, because my hosting company has the databases spread across multiple servers. So here&#039;s what I have:</p>
<pre><code>#!/bin/sh

#Define your variables here:
BACKUP_DIR=
BMYSQL_HOST=
BMYSQL_DBNAME=
BMYSQL_USER=
BMYSQL_PWD=

#  Make sure output directory exists.
if [ ! -d $BACKUP_DIR ]; then
    mkdir -p $BACKUP_DIR
fi

#  Rotate backups
for j in  6 5 4 3 2 1 0; do
    for i in $BACKUP_DIR/$BMYSQL_DBNAME.gz.$j; do
        if [ -e $i ]; then
            mv $i ${i/.$j/}.$(( $j + 1 ));
        fi
    done
done

mysqldump --host=$BMYSQL_HOST --user=$BMYSQL_USER --pass=$BMYSQL_PWD $BMYSQL_DBNAME | gzip &gt; $BACKUP_DIR/$BMYSQL_DBNAME.gz.0</code></pre>
<p>Once you have this script in place, make sure it has the right permissions - my hosting company requires this: -rwx&#8211;x&#8212; with the default group.</p>
<p><strong>Schedule your script to run</strong></p>
<p>I found <a href="http://wiki.dreamhost.com/index.php/Crontab">this helpful wiki article</a> at Dreamhost. So I did the following:</p>
<p><code>crontab -e</code></p>
<p>Borrowing from Dreamhost&#039;s Handy Crontab Header and adding a line that will run my script at 1:15am every day, this is what I have:</p>
<pre><code># minute (0-59),
# |      hour (0-23),
# |      |       day of the month (1-31),
# |      |       |       month of the year (1-12),
# |      |       |       |       day of the week (0-6 with 0=Sunday).
# |      |       |       |       |       commands
15       1       *       *       *       /home/path/to/your/script</code></pre>
<p>Save the file (don&#039;t forget to leave the last line blank). To see if the file saved correctly, just list the crontab file by this command:</p>
<p><code>crontab -l</code></p>
<p>and you should see it printed on the screen. That&#039;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/linux/nightly-mysql-backup/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Firefox Extension Incompatible?</title>
		<link>http://www.andrejciho.com/general/firefox-extension-incompatible/</link>
		<comments>http://www.andrejciho.com/general/firefox-extension-incompatible/#comments</comments>
		<pubDate>Sat, 23 Dec 2006 16:02:19 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/general/firefox-extension-incompatible/</guid>
		<description><![CDATA[Rename, unzip, compatibilize, zip-up, use]]></description>
			<content:encoded><![CDATA[<p>Just updated to the latest version of Firefox only to receive a message that your favorite extension is not compatible? Of course, the best thing to do is to check the same exact place where you downloaded the extension - to see if there is a newer version. If there is not, a friend showed me what you can do in the meantime, before the particular developer releases a newer version.</p>
<ol>
<li>Download the extension instead of directly installing it. (You know, right-click and <em>Save Link As&#8230;</em>)</li>
<li>Rename the extension from filename.<em>xpi</em> to filename.<em>zip</em>.</li>
<li>Unzip the extension, and open <em>install.rdf</em> for editing.</li>
<li>Change the <em>em:maxVersion</em> parameter value to include your version of Firefox, better yet, change it to 4.0 just to be safe.</li>
<li>Save the file, zip up the folder and rename the new filename.<em>zip</em> to filename.<em>xpi</em>.</li>
<li>To install it, open the filename.xpi file with firefox.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/general/firefox-extension-incompatible/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Performing maintenance on WPMU</title>
		<link>http://www.andrejciho.com/wordpress-mu/performing-maintenance-on-wpmu/</link>
		<comments>http://www.andrejciho.com/wordpress-mu/performing-maintenance-on-wpmu/#comments</comments>
		<pubDate>Wed, 20 Dec 2006 02:14:28 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
		
		<category><![CDATA[Wordpress MU]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/wordpress-mu/performing-maintenance-on-wpmu/</guid>
		<description><![CDATA[<p>Temporary polite off-line page to everyone but you.</p>]]></description>
			<content:encoded><![CDATA[<p>Recently I did an upgrade of WPMU 1.0 RC1 to 1.0 for a client. I was determined to do it right - without making anyone angry because they lost the post they were working on for the last 20 minutes and definitely without anyone seeing any errors. If you already have a procedure for this, great - otherwise you may consider this quick and easy solution.</p>
<p>First of all I put up an announcement into the admin interface half-a-day in advance (could have done couple days) so that anyone who logs in knows it&#039;s coming. WordPress MultiUser has a neat action hook called <em>admin_notices</em> which you can call in a plugin. So I put together this simple one:</p>
<pre><code>&lt;?php
add_action('admin_notices','displayAnnouncement');
function displayAnnouncement() {
  $msg = '
    &lt;div style="background: #ff0000;color: #000000;font-size: 12pt;"&gt;
      &lt;p&gt;your message goes here&lt;/p&gt;
    &lt;/div&gt;
  ';
  echo trim($msg);
}
?&gt;</code></pre>
<p>Then I created an offline page that all the visitors would be redirected to, while I was working on the site. I just created a folder called &#034;offline&#034;, copied the main page&#039;s theme (CSS and images) and whipped up a nice .html document (no PHP) telling users that the site is temporarily unavailable due to maintenance.</p>
<p>After all the users knew not to log in and the offline page was ready for the public, it was time for the redirect. The beauty in the following few lines of code is that it redirected everyone BUT me - so I could use and test the site all I wanted without anyone seeing any ugly unprofessional errors. So here goes what I inserted at the top of index.php, wp-admin/admin.php (included in all the admin pages) and wp-login.php. If you have wp-signup.php enabled, I&#039;d put it there too.</p>
<pre><code>&lt;?php
$ip = $_SERVER['REMOTE_ADDR'];
if ('xxx.xxx.xxx.xxx' &lt;&gt; $ip ) {
  header('Location: http://your-WPMU-url/offline/');
  wp_redirect('http://your-WPMU-url/offline/');
}
?&gt;</code></pre>
<p>*Replace the xxx.xxx.xxx.xxx with your IP address. <br />
**I used the wp_redirect just to be sure it works - you know, in case some other headers get passed before the regular redirect.</p>
<p><em>Now</em> I was ready for the upgrade and maintenance. (Just a note - if you plan to overwrite any of the files that contain your custom redirect during your maintenance/upgrade, don&#039;t forget to include the redirect in the new ones as well :-) - at least until you are done with the maintenance.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress-mu/performing-maintenance-on-wpmu/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WPMU CAS Integration</title>
		<link>http://www.andrejciho.com/wordpress-mu/wpmu-cas-integration/</link>
		<comments>http://www.andrejciho.com/wordpress-mu/wpmu-cas-integration/#comments</comments>
		<pubDate>Sun, 29 Oct 2006 00:28:59 +0000</pubDate>
		<dc:creator>Andrej</dc:creator>
		
		<category><![CDATA[Wordpress MU]]></category>

		<guid isPermaLink="false">http://www.andrejciho.com/wordpress-mu/wpmu-cas-integration/</guid>
		<description><![CDATA[<p>Integrate WordPress MU with phpCAS</p>]]></description>
			<content:encoded><![CDATA[<p>I was asked to set up WordPress MultiUser (WPMU) for a project for <a href="http://www.cornerstone.edu">Cornerstone University</a>. They already had most of their online services integrated into a single sign-on using <a href="http://esup-phpcas.sourceforge.net/">phpCAS</a> and asked me to integrate WPMU with it as well. This document attempts to enable others to easily duplicate the same integration. I will also list some of the implications that I had to address as a consequence of the integration.</p>
<ul>
<li><a href="#before">Before you start</a></li>
<li><a href="#casmod">CAS modification</a></li>
<li><a href="#auth">Authentication</a></li>
<li><a href="#admin">Admin username</a></li>
<li><a href="#welcome">Welcome email</a></li>
</ul>
<p><strong><a name="before"></a>Before you start</strong></p>
<p>Download <a href="http://sourceforge.net/projects/esup-phpcas/">phpCAS</a> and after extracting it, copy the folder esup-phpcas-x.x.xx/source/CAS into the ./wp-content/mu-plugins folder of your WPMU install so that the path to CAS.php is ./wp-content/mu-plugins/CAS/CAS.php.</p>
<p>Make sure, that you have access to your MySQL database either through <a href="http://www.phpmyadmin.net">phpMyAdmin</a> or another similar tool or at least that you can execute queries through the command line.</p>
<p><strong><a name="casmod"></a>CAS modification</strong></p>
<p>In the CAS that you copied into your mu-plugins folder: Comment out the following section in the beginning of CAS/PGTStorate/pgt-db.php so that it looks like this:</p>
<p><code>/*<br />
if (!class_exists('DB')) {<br />
include_once('DB.php');<br />
}<br />
*/</code></p>
<p>(Otherwise you&#039;ll see errors.)</p>
<p><strong><a name="auth"></a>Authentication</strong></p>
<p>Make a backup copy of your current ./wp-login.php and replace the content of the original file with <a target="_blank" href="http://www.andrejciho.com/wp-content/uploads/2006/10/wp-login.txt">my wp-login.php</a>.</p>
<p>Make a backup copy of your current ./wp-content/mu-plugins/pluggable.php and replace it with <a target="_blank" href="http://www.andrejciho.com/wp-content/uploads/2006/10/pluggable.txt">my pluggable.php</a>. <strong>Edit</strong> the file and modify the CASloginURL and CASlogoutURL variables based on your setup.</p>
<p><strong><a name="admin"></a>Admin username</strong></p>
<p>Most likely your username in your CAS user directory is not &#039;admin&#039;. At least mine wasn&#039;t. In order for you to be able to log in to your WPMU install, you&#039;ll have to edit the users table (<em>wp_users</em>) to change the username (<em>user_login</em>) of admin (ID = 1) to your CAS user directory username. </p>
<p>Since your username is no longer &#039;admin&#039;, WPMU may not consider you a site administrator (administrator of the site and all blogs). If this is the case, you will have to modify the function is_site_admin() in ./wp-includes/wpmu-functions.php to include the following clause:</p>
<p><code>$userid = get_current_user_id();<br />
if ($userid == 1) return true;</code></p>
<p>What this will accomplish is that the person with userid = 1 (the person who installed WPMU) is considered a site admin regardless of their username.</p>
<p>Once you are the site admin again, you can add more users to have the same permissions in the <em>Site Admin</em> | <em>Options</em> section of the WPMU control panel / dash board. If that still doesn&#039;t give them site admin permissions, you can hardcode their username in the same is_site_admin() function, although I would not recommend that. You would just insert some thing like this inside the is_site_admin() function:</p>
<p><code>if ($user_login === 'a12345') {return true;}</code></p>
<p><strong><a name="welcome"></a>Welcome email</strong></p>
<p>When you create a new blog in the site admin area, an email is sent to the new user created at the same time. The email contains a random password generated by WordPress - a password that will not work, because you are using CAS instead of the WordPress authentication. So in order to avoid any confusion, you&#039;ll have to change the text of this Welcome email. Even though it may seem that the place you could edit that text is in the site admin area, the text is actually hard-coded into a php file. So to make the change you&#039;ll have to edit it there.</p>
<p>Copy the function <em>wp_new_user_notification</em> from ./wp-includes/pluggable.php and insert it into ./wp-content/mu-plugins/pluggable.php at the end of the file. The functions in pluggable.php in wp-includes are preceded by<br />
<em>if ( !function_exists)</em> (meaning if it was already defined earlier) because you can first define them in pluggable.php in mu-plugins which gets executed earlier in the sequence.
<p>All <em>that</em> to say: if you want to modify a function that&#039;s in ./wp-includes/pluggable.php, you are best off to copy it to ./wp-content/mu-plugins/pluggable.php first and modify it there so that you have as many of your WPMU modifications in one place - the mu-plugins folder - as possible.</p>
<p>But back to our <em>wp_new_user_notification</em> function. Now that it&#039;s in ./wp-content/mu-plugins/pluggable.php, modify the line that says:</p>
<p><code>$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";</code></p>
<p>to say something like:</p>
<p><code>$message .= sprintf(__('Password: (use your domain password)'), $plaintext_pass) . "\r\n";</code></p>
<p>That should be it. If you discover other things that may have to be addresses due to the integration, please let me know so that I can add them here for everyone to benefit from. </p>
<p><strong>If you make any improvements, I kindly ask that you send them to me as a courtesy.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrejciho.com/wordpress-mu/wpmu-cas-integration/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
