Skip to content

Instantly share code, notes, and snippets.

@grok
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grok/e3da281daeed15d1cb0d to your computer and use it in GitHub Desktop.
Save grok/e3da281daeed15d1cb0d to your computer and use it in GitHub Desktop.

WordPress and WorkFlows

By: Sterling Hamilton

From time to time we invite developers who are doing interesting things on Pantheon to share what they are doing with others. This time Sterling Hamilton of Noble Studios is sharing with us what he and his team have learned about using Pantheon and workflows with WordPress.

Git Workflows

The many combinations for workflows your team can use, will no doubt make it difficult in deciding how to begin working with WordPress on Pantheon. This article is intended to provide you a an example of a simple workflow for maintaining your WordPress installation.

As you read through, remember that this is not the "end all be all" solution. This is a guideline intended to give you an immediate path to follow. You can alter, or come up with alternatives down the road.

Assumptions

Before we begin, you need to know that I've made some assumptions about you. If your situation is different and you don't meet these criteria, this article won't make much sense to you.

Now that we are all on the same page, let's continue.

Local Setup

You should have your local environment setup and open for this article. You will also need the Git connection information from your website's Pantheon Dashboard. This will look something like this:

ssh://codeserver.dev.[somenumbers]@codeserver.dev.[morenumbers].drush.in:2222/~/repository.git myproject

For the purposes of this article, we're going to shorten that to:

git clone ssh://reallylongurl:2222/~/repository.git myproject

Executing this command from the command line will create a local repo of your site in a directory titled myproject in the local directory. Now that you have a local copy of your WordPress site, you can begin working with it.

Upgrading WordPress

Now that you have a local copy of your project, working on it will be easier. One of the things you can do is control the upgrade process. You may want to maintain your site at a specific version, or you may want to load in the most recent Beta. Whatever your reason, updating the WordPress core manually is easy from this point.

There are a few options.

  1. Clone down your Pantheon repository, setup a local stack, and run the built in WordPress updater from a browser. This is typically done through the administration screen of WordPress.
  2. Clone down your Pantheon repository and run the following commands:

  • cd myproject
  • mv wp-content /tmp << Backup our content directory.
  • mv wp-config.php /tmp << Backup our configuration file.
  • rm -vR \.* << Get rid of hidden files.
  • rm -vR * << Get rid of all other files.
  • wget wordpress.org/latest.zip << Download the latest version of WordPress.
  • unzip latest.zip << Unpack the latest version of WordPress.
  • mv wordpress/* . << Move the unpacked files into our current working directory.
  • rm -vR wordpress << Clean up unpacked directory.
  • rm -vR wp-content << Remove default wp-content directory as it will be replaced by our own.
  • mv /tmp/wp-content . << Move our content directory back in place.
  • mv /tmp/wp-config.php . << Move our configuration file back in place.

Your local repo should be good now :) All you need to do to see it in Pantheon is to git push origin master your repo back up to Pantheon. If you have your Pantheon Dashboard open, you will notice that as soon as you do your push, it will begin the process of updating your site in development. Once the process is complete, you can click the "View development site" button and see your changes.

If your goal was to update WordPress to the latest and greatest, yor other option is to wait for Pantheon to push the changes to your development repo. These usually take place within 24 hours of a new version of WordPress being released.

Adding Plugins & Themes

Another thing you can do with your local repo is to add themes or plugins. This workflow works for many developers over the normal WordPress admin interfaces. One reason is that you can include sub-repos that contain your custom themes or plugins instead of just including the code itself. Here is an example of adding in a custom theme from your repo.

cd myproject

Now that we are in the cloned project, let's add a Theme.

git remote add -f theme git@bitbucket.org:username/ourtheme.git

With -f option, git fetch is run immediately after the remote information is set up.

From here on out you can get updates for your theme like this:

  • git fetch theme
  • git subtree pull --prefix wp-content/themes/ourtheme theme --sqaush

Then you can push up to Pantheon!

You can do the exact same thing with a plugin, here's how.

git remote add -f plugin git@bitbucket.org:username/ourplugin.git

Then your process will be:

  • git fetch plugin
  • git subtree pull --prefix wp-content/plugins/ourplugin plugin --sqaush

As you can see it is very easy to add you own projects into your local repo and them push them back up.

Conclusion

Workflow is the secret sauce in any site hosted on Pantheon. Since every developer and team have their own workflow procedures, merging Pantheon's workflow into your existing workflow will be an important task. I hope this short example will show you one way you can do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment