WordPress, Git and WP-Skeleton – a tutorial

Following a series of videos from Amelia Briscoe to setup a workflow with wordpress and git

1. Importing a wordpress git repository

– Sign up to a bitbucket account
– Import Jaquith’s WordPress-Skeleton into Bitbucket

2. Clone a WP repository to a local server

– Create a fork of the wordpress-skeleton
– clone this repository into local map, using the recursive option

git clone --recursive 
https://sdims@bitbucket.org/sdims/wptest5-dev.git .

3. Configure the repo

– Create local database
– Duplicate the local-config-sample.php and rename it to local-config.php
– Fill in the local db name and credentials

Now edit the part of the config.php file that looks like this:

// ========================
// Custom Content Directory
// ========================
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );

– Set up an alias for your local website if it is not in the WAMP/www directory

– Change the second definition to point WP_CONTENT_URL to your local directory:

define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/wptest5/content' );

– Optional increase memory that can be used by php

define('WP_MEMORY_LIMIT',  '96M');

– Optional: change to table prefix

4. Installing wordpress from a Git repository

– First, add and commit the modified wp-config.php
– Then open up the url localhost/wptest5/wp/wp-admin in your browser
– Do the install
– Log in
– Change the site address to the root folder (instead of the sub folder wp)
– Optional: change tagline, time format, timezone
– Change permalinks to postname (preset)

– Add and commit the changes (to .htaccess) with message: ‘changed permalinks and site url’
– Push to bitbucket

5. Add a WordPress theme via git branch

– git checkout -b test_theme
– git branch
– cd content/themes

Now clone a theme. The tutorial uses Bones, so let’s follow that example

git clone https://github.com/eddiemachado/bones.git

remove the .git directory and all the other .git files
Then add and commit hte changes

git status
git add .
git commit -m'Addition of the Bones Theme'
git status
git checkout master

Because we switched to a different branch, we have to log out from WordPress first and then log in again to see the theme.

Do this.

Important:
– If you switch back to the master branch, then you have to log out and in again
– If your new theme is activated, switching to the master branch and then logging in into your wordpress will produce several errors.

Therefore it is best to keep working on the testing branch until it is finished and then merge it back into the master branch.  After that you can go ahead and activate the theme.

Now assume we have done a lot of work on the theme:

– Log out of wordpress
– Checkout the master branch
– Merge the testing branch

6. Install a plugin via git branch

– Create and checkout a new branch test_plugin
– create a new folder in the plugins folder
– create a new file test_plugin.php
– Edit the file (use ‘plugin head’ snippet in sublime) and save
– Do a git status (it shows the folder that is added)
– Add this as follows (from the repo root)

git add content/plugins/test-plugin/

Log out of WordPress, and log back in. Check that the plugin is there
Do some work and merge the test_plugin branch when you are finished.

7. Add the WordPress upload folder to the git repository

When you install a new plugin you will probably encounter an error with WP-skeleton.

unable to create directory uploads/2013/04. Is the parent directory workable by the server?

This is caused by the symbolic link in the content:

 uploads -> ../shared/content/uploads

So, thse folders has to be created first, starting in the root folder:

mkdir shared; cd shared; mkdir content; cd uploads; mkdir uploads

8. Block unecessary Plugins during development

There are certain plugins that you don’t need to have active during development. Think about: Spam Destroyer, Sucuri Security, W3 Cash, Database backup plugins

For this we can use Jaquith’s plugin that disables plugins when you are on a local environment. Note that the working of this plugin depends on the constant WP_LOCAL_DEV, which is defined in the wp-config.php of the wp-skeleton

To add this Gist (a static file), download it and put it in the mu-plugins folder

Add and submit

To test its working, log in to wordpress and install and activate a plugin to remove spam. Akismet and Spam destroyer for example.  Add and submit

Now add the main files of these plugins to the end of Jaquith’s plugin:

if ( defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV ) {
    new CWS_Disable_Plugins_When_Local_Dev( array( 'vaultpress.php',        'spam-destroyer/index.php', 'akismet/akismet.php') );

Check if the plugins are indeed deactivated (no need to log out)

9. Deploying a WordPress Git repo to a live server