Composerpress

Following along the lines of a Smashing Magazine article about Composer-managed WordPress installations I’ve created my version of it.

Setting up the site

My workflow involves setting up a WordPress local installation to work on and make daily “commits” (it’s in quotes as it’s done via FTP and git-ftp ) to the staging/live server.
I’ve modified Smashing Magazine guide to my own needs and taste and created composerpress; the name is not the most original ever seen yet it carries the message across.
Step by step process is, supposing git and composer globally installed already, just 3 steps. I keep my local installations in the /www folder and will make those locally available using MAMP, at Terminal

cd /www
git clone git@github.com:lucatume/composerpress.git client-site
rm -rf .git*
git init

where client-site will be the name of the client I’m working for.
The last two lines will remove any bond to the composerpress repository and initialize a new git repository.
I will then install the dependencies specified in the composer.json file that came with the repository

cd client-site
composer install

will wait for composer to work its magic. [caption id=“attachment_1014” align=“aligncenter” width=“1024”]Composer installing dependencies Composer installing dependencies[/caption] The last thing to do is to modify the client-site/wp-config.php file to make it talk to the local MySql server. [caption id=“attachment_1015” align=“aligncenter” width=“1024”]Setting the config Setting the config[/caption] Once MAMP or any other local hosting solution is set to serve the site from that folder the site will be ready to use and sport some plugins and Twentyfourteen theme.

Installing themes and plugins

WordPress makes installing plugins and themes easy using its administration interface but to keep the installation consistent that’s not the way to go. In this Composer-managed installation the right way is to go and modify the composer.json file and run composer update.
If I want to install the Hello Dolly plugin I will go to WordPress plugin repository, will find it and take note of its “slug”

https://wordpress.org/plugins/hello-dolly/

in this case hello-dolly. I will add that to the site dependencies [caption id=“attachment_1016” align=“aligncenter” width=“1024”]Adding Hello Dolly Adding Hello Dolly[/caption] and will then update the site installation using composer

composer update

[caption id=“attachment_1017” align=“aligncenter” width=“1024”]Hello Dolly installation Hello Dolly installation[/caption] The same goes for themes.
Removing themes and plugins requires just the deletion of the require line in the composer.json file and another update.
[caption id=“attachment_1018” align=“aligncenter” width=“1024”]Removing Hello Dolly Removing Hello Dolly[/caption] Since more complex plugins might use activation, deactivation and uninstallation hooks to allow all of those hooks to fire follow these steps to install a plugin:

  1. update composer.json with dependency
  2. run composer update
  3. activate the plugin on the site

To remove a plugin:

  1. deactivate the plugin on the site
  2. remove the plugin from the site
  3. update composer.json dependency removing the require statement
  4. run composer update

Next

While the process above is two sites old managing plugin and themes dependencies via Composer is a recent (polite synonim of “never used before”) approach I’m testing right now: I will illustrate that as well in a next article.