Installing WordPress Plugins with Composer

I found out a cool usage for composer that I didn’t know about; use it for installing WordPress plugins. I use Phing to do all my deployments (slowly moving towards continuous integration with Jenkins). I wanted a way to get the plugin files and include them with my deployment automagicly. Composer can download and extracting the plugin archive file rather than using the gui in the wordpress admin. This task can be done when all your other required libraries are installed.

I wanted to install Contact Form 7. In order for this to work you need to download the plugin from a custom repository, so I setup my composer.json file something like this:

{
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "takayukister/contact-form-7",
        "type": "wordpress-plugin",
        "version": "4.3.1",
        "dist": {
          "type": "zip",
          "url": "https://downloads.wordpress.org/plugin/contact-form-7.4.3.1.zip"
        },
        "require": {
          "composer/installers": "v1.0.7"
        }
      }
    }
  ],
  "require": {
    "takayukister/contact-form-7": "4.3.1"
  },
  "extra": {
    "installer-paths": {
      "public_html/wp-content/plugins/{$name}/": [
        "type:wordpress-plugin"
      ],
      "public_html/wp-content/themes/{$name}/": [
        "type:wordpress-theme"
      ]
    }
  }
}

I set the name of the repo to the “takayukister/contact-form-7″ and then used that as it’s require name with the current version (right now 4.3.1). The paths in the “extra” section tell composer where to put the plugin once it’s installed.

In my Phing build.xml I could then run this before any packaging tasks:

<exec command="php composer.phar install" level="verbose" passthru="true" />

If there’s a better way to do this I’d like to hear it.

12 thoughts on “Installing WordPress Plugins with Composer”

  1. http://www.mp3dj.eu
    a very nice post. Taking the time and actual effort to make a top notch article… but what can I say… I put things off a lot and don’t manage to get nearly anything done.|
    Wow that was strange. I just wrote an incredibly long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say great blog!|

  2. Wow, this post is pleasant, my younger sister
    is analyzing these kinds of things, so I am going to let know
    her.

  3. I blog often and I really appreciate your content.

    Your article has really peaked my interest. I am going to bookmark
    your website and keep checking for new information about once
    per week. I subscribed to your RSS feed too.

  4. I’m not sure why but this blog is loading extremely slow for me.

    Is anyone else having this problem or is it a problem on my end?
    I’ll check back later and see if the problem still exists.

  5. Hi there! This is kind of off topic but I need some advice from
    an established blog. Is it tough to set up your own blog?

    I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about making my own but I’m not sure where to start.
    Do you have any points or suggestions? Thank you

  6. Greetings from Ohio! I’m bored to death at work so I
    decided to check out your website on my iphone during lunch break.
    I love the information you provide here and can’t wait to take a look when I get home.
    I’m amazed at how fast your blog loaded on my mobile ..
    I’m not even using WIFI, just 3G .. Anyhow, very good site!

  7. I was just seeking this information for some time. After 6 hours of continuous Googleing, at last I got it in your web site. I wonder what’s the lack of Google strategy that don’t rank this kind of informative websites in top of the list. Normally the top web sites are full of garbage.

  8. Hi there. I found your web site by means of Google whilst searching for a related matter, your web site got here up. It seems to be good. I’ve bookmarked it in my google bookmarks to come back then.

Comments are closed.