WordPress plugin + Composer?

I’m making WordPress plugin that is using a few third party libraries. Is it common practice to use Composer for WordPress plugin?

If it’s okay to use it, then I assume that I should provide all Composer files along with my plugin, because I don’t want to make people manually run composer install.

Read More

Another question is, is it safe to use Composer’s autoloading? I configured it to autoload my own classes and the libraries are of course autoloaded as well. That’s convenient.

Is using Composer with WordPress plugin an overhead? Or does it have any additional issues?

Related posts

1 comment

  1. This is old question, but nothing has changed since 3 years. Using Composer for requiring dependencies in WordPress plugin/themes is usually a bad idea. PHP does not allow to load more than one class with the same FQN. So if two different plugins will install the same library independently, classes from random installation of library will be loaded which may result really weird bugs (especially if these are different versions of the same library). To avoid such problems you should have only one composer.json instance per project, so in this case Composer should be run at WordPress level.

    In general if you have the same package installed multiple times, you probably will get some troubles (and this will happen if every plugin maintainer will use Composer on its own). Note that this is not directly related to Composer – if you copy libraries manually you will get exactly the same problem (maybe even worse).

    If you really want to use Composer in your plugin you may try tools like humbug/php-scoper which will modify namespaces of used dependencies and make them unique.

Comments are closed.