I’ve recently been introduced to managing WordPress.org plugins via Composer. This makes it more convenient when excluding plugins from your working repository. Composer is capable of doing far more than managing plugins but at this point, that is the extent of how I’m using it.
This allows me to exclude my plugins via .gitignore
yet check in my composer.json
file, allowing me to quickly install the correct plugins in a newly cloned instance.
Install Composer
You can install composer with the following line.
curl -sS https://getcomposer.org/installer | php;mv composer.phar /usr/local/bin/composer
Composer Configuration
Create a file called composer.json
in the root of your project. This file includes the list of plugins you want to manage via Composer. Here is an example file that manages two plugins WordPress SEO and Simple Google Analytics Tracking.
{ | |
"repositories":[ | |
{ | |
"type":"composer", | |
"url":"https://wpackagist.org" | |
} | |
], | |
"require": { | |
"wpackagist-plugin/wordpress-seo":">1.7.3", | |
"wpackagist-plugin/simple-google-analytics-tracking":">1.0" | |
} | |
} |
Install Plugins
After your composer.json
file is in place, from the command line run
composer install
This reads your composer.json
file and creates your plugins in the wp-content/plugins/
directory.
The install command also creates a directory called vendor. You can ignore this directory, both in the sense of not paying attention to it and making sure your .gitignore
excludes it from your repository.
Plugins Not on WordPress.org
For plugins not on WordPress.org, Composer can be used to load the plugin directly from a Git repo. I wrote about how I do this in my post Loading a Private WordPress Plugin with Composer.
Leave a Reply