A Script for Creating Custom Wordpress Templates

November 26, 2008 by John Jenkins · 1 Comment
Filed under: Tools 

How many wordpress blogs have you created? If you’re an affiliate marketer I bet it is a few. Most of them start the same way by setting up wordpress, then adding a few plugins and then some themes. I use the same plugins and themes on all (three!) blogs so after going through the same steps for a third time I figured I would write a script.

As I didn’t want to write anything too complicated, the script depends on everything being in a particular location. It needs to be run from the same directory as the wordpress tarball and plugins and themes need to be in directories called plugins and themes respectively. Therefore, the directory structure will be:

wp-maker/
wp-maker/plugins
wp-maker/themes

When I looked at the files in my directory it looked like this:

$ find wp-maker/
wp-maker/
wp-maker/plugins
wp-maker/plugins/wassup.1.6.3.zip
wp-maker/plugins/google-sitemap-generator.3.1.0.1.zip
wp-maker/plugins/clean-archives-reloaded.zip
wp-maker/plugins/all-in-one-seo-pack.zip
wp-maker/plugins/stats.1.3.5.zip
wp-maker/extras.tar.gz
wp-maker/themes
wp-maker/themes/my-code-blue.tar.gz
wp-maker/make-tarball.sh
wp-maker/wordpress-2.7.tar.gz
$

The script also adds any files in a tarball called extras.tar.gz if present. You can download it here. Note: all code written by me in this blog is licensed under the GNU GPL which is the same license as Wordpress itself. The license states (amongst other things), you are free to use it but I provide no warranty and accept no liability. You can read the license here.


This function extracts files from either zipfiles or tarballs. It isn’t particularly important to understand how it works but if you’re interested, let me know in the comments.

extract_files()
{
    SOURCE=$1

    if [ ! -e "$SOURCE" ]; then
        return 1
    elif [ ! -z "`echo $SOURCE | egrep -i '\\.zip$'`" ]; then
        unzip $SOURCE
    elif [ ! -z "`echo $SOURCE | egrep -i '\\.gz$'`" ]; then
        gunzip -c $SOURCE | tar -xvf -
    else
        echo "Unrecognised filetype: $SOURCE"
    fi
}

Set up some useful variables including the list of themes and plugins that are present.

TOP=`pwd`
EXTRAS="$TOP/extras.tar.gz"

THEME_DIR=$TOP/wordpress/wp-content/themes
PLUGIN_DIR=$TOP/wordpress/wp-content/plugins

THEMES=`echo $TOP/themes/*.gz $TOP/themes/*.zip`
PLUGINS=`echo $TOP/plugins/*.gz $TOP/plugins/*.zip`
WORDPRESS=$1
if [ -z "$WORDPRESS" ]; then
    WORDPRESS=`echo wordpress*.tar.gz`
    if [ -z "$WORDPRESS" ]; then
        echo "Error: unable to find wordpress tarball"
        exit
    fi
    WORDPRESS="$TOP/$WORDPRESS"
fi
# Extract files from tarball
gunzip -c $WORDPRESS | tar -xvf -
if [ -e "$EXTRAS" ]; then
    gunzip -c $EXTRAS | tar -xvf -
fi
cd $TOP/wordpress
tar -cvf $TOP/wp-basic.tar *
gzip $TOP/wp-basic.tar
# Extract the required themes into the theme directory
echo "Info: Extracting themes"
cd $THEME_DIR
for theme in $THEMES; do
    extract_files $theme
done

# Extract the required plugins into the plugin directory
echo "Info: Extracting plugins"
cd $PLUGIN_DIR
rm hello.php
for plugin in $PLUGINS; do
    extract_files $plugin
done
# Create the final tarball
echo "Info: Creating the tarball"
cd $TOP/wordpress
find . -name RCS -type d | xargs rm -rf
tar -cvf $TOP/wp-starter.tar *
gzip $TOP/wp-starter.tar

My extras tarball contains the following shell script called init.sh which creates some handy files.

#!/bin/sh

# Create empty files that will be populated by wordpress later
touch .htaccess sitemap.xml sitemap.xml.gz
chmod 666 .htaccess sitemap.xml sitemap.xml.gz

Comments

One Response to “A Script for Creating Custom Wordpress Templates”
  1. baron says:

    I`m involved there`s a lot of articles on casino gambling. There are dissimilar methods, tactics, strategies, algorithms of counting, calculations and so on.
    But these items are only heap of ads and i don`t want to analyze them `cause i don`t have any basic knowledge. It`s useless. Estimation i think will be wrong.
    Is there anyone here who is interested in such topic?
    I`d appreciate someone`s explaining to me is there any systems or strategies, what are they (what approaches or concepts lay in basis) and in which casinos could they be applied to?
    Thanx a lot.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!