0
votes

I've been putting some thought recently into how to integrate composer with Wordpress plugins. And yes, before anyone suggests it, Wordpress is a requirement. I've come up with a few ideas, but they all have pretty major drawbacks.

The first system would be to just include the composer packages with each plugin (aka run composer install locally and then zip the vendor folder with the plugin for easy uploading). The benefits are the ease of install, and simplicity. Issues arise when multiple plugins get installed with the same dependencies. Not only is it then pretty bloated, but if any there are dependency version differences between the plugins, the autoloaders would screw each other up, loading only one version.

Another option would be to continue to have composer packages with each plugin, but also have another plugin (we'll call it the framework plugin) which just has the packages which multiple plugins would use. The benefits to this would be no duplicated packages, all plugins would be kept working with the package versions shipped with the framework plugin; but there would be a lot of autoloaders at this point, never a good thing, and version management becomes very complex.

This of course would be so much easier if I could treat my plugins as composer packages, and have one vendor folder in the root directory, and install via the composer commandline; but one requirement of this system is plugins can be managed via ftp, no ssh.

The more I think about it, the less possible it seems, I know composer wasn't designed for this; but does anybody have any thoughts on how this might be achieved?

1

1 Answers

2
votes

Wordpress can be fully integrated with composer - if you use the composer/installers library you can then include plugins or themes which have their own composer.json files with the type set to wordpress-plugin or wordpress-theme and it will put them in the correct location (wp-content/themes rather than vendor/).

All public wordpress plugins and themes are available via the Wordpress Packagist - http://wpackagist.org/ you will just need include it in the composer.json for the whole project like so:

{
    "name": "acme/brilliant-wordpress-site",
    "description": "My brilliant WordPress site",
    "repositories":[
        {
            "type":"composer",
            "url":"http://wpackagist.org"
        }
    ],
    "require": {
        "aws/aws-sdk-php":"*",
        "wpackagist/advanced-custom-fields":"*",
        "wpackagist/posts-to-posts":"1.4.x"
    },
    "autoload": {
        "psr-0": {
            "Acme": "src/"
        }
    }
}

You can install your own composer'd plugins/themes if they are in github (or similar) by including adding the repo for them like so:

{
    "type": "vcs",
    "url": "https://github.com/YourUserName/MyWordPressPlugin.git"
},

Make sure you have a composer.json in your own plugin's git repo with the type set to wordpress-plugin or wordpress-theme. The just add their name to the require part of the composer.json for the project. I often do this for purchased plugins - I create a new private repo for them and add a composer.json.

When it comes to deploying - you wont be able to run composer install on the remote server, but you can just FTP from a working copy where you have run the install command. Or if you are using Git, you could have a post receive hook setup which exports the project, runs composer install and then FTPs.