Create a Composer managed plugin for WordPress

There are two ways to have composer manage plugins and themes in a 12 factor wordpress app: as a separate repository or as a local path. The latter is more simple while the first is much reusable.

  1. create a remotely accessible repository (Github etc) — or just a directory in the main 12 factor wp repo: src/plugins/wp-comp-plug-pack
  2. add a composer.json file into its root with similar content:
{
"name": "evista/wp-comp-plug-pack",
"type": "wordpress-plugin",
"homepage": "http://digital-agency.co",
"license": "GPLv3",
"description": "Evista Dedicated Plugin",
"keywords": ["plugin","evista"],
 "require": {
"johnpbloch/wordpress": "^4.5"
}
}

3. mark it as stable with git tag to enable composer installs (in case of a separate repo):

git tag -a v1.0 -m “first stable version”
git push origin v1.0

4. add this repository to the main WordPress repo’s composer.json as a repository:

"repositories": [
    {
"type": "vcs",
"url": "git@github.com:balintsera/wp-comp-plug-pack-ex.git"
}
]

5. or if it’s a local directory add this directory as path type to the main WordPress repo’s composer.json as a repository:

"repositories": [
    {
"type": "path",
"url": "src/plugins/wp-comp-plug-pack"
}
]

6. install the result package with composer using the value of the name parameter of the package’s composer.json (Composer can manage Wordpress and its plugins, see the details here: https://github.com/balintsera/wordpress-12factor):

composer require --prefer-source evista/wp-comp-plug-pack

6. enable the plugin via wp-cli:

composer wp -- plugin enable wp-comp-plug-pack

Mind the prefer-source parameter. You can commit your changes to the original package from the plugin’s directory (twelve factor wordpress ignores the whole wordpress directory including plugins).

I’ve made an example plugin boilerplate: https://github.com/balintsera/wp-comp-plug-pack-ex

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.