Composer - Plugins & Themes

Summary: Seravo uses Composer by default to install plugins and themes. You don’t have to use it, but it’s pre-installed for you in case you want to have better management of your PHP code dependencies.

What is it?

Composer is a dependency manager for PHP that has been gaining popularity lately. Your first question is most likely “what is a dependency manager and why do I need one?”. Almost any code you write probably ends up depending on 3rd party libraries. All of these libraries (projects, frameworks, files, etc) become dependencies of your project. Composer lets you declare the dependencies for a project and it will install and manage them.

Explanation

Repositories section:

{"repositories":[{"type":"composer","url":"http://wpackagist.org"}]}

Repositories section tells Composer directions where to look for your packages. In order for Composer to find your beloved WordPress plugins and themes you’ll need to point it to wpackagist.org which is mirror of all plugins and themes which you can download from wordpress.org. You can add any custom repositories you have here, but for WordPress you’ll need to use wpackagist.

By default Composer installs everything to vendor directory in the root of your project. Luckily for us wpackagist uses clever plugin composer/installers which allows us to have custom installation path. In Extra section we can define installation paths for different types of packages.

Adding your own plugins and themes

Best way to develop custom plugins and themes is to add them into their own repositories and install them by Composer.

You can do this by adding composer.json file for into your plugin/theme repo:

Paid WordPress plugins and Composer

By default Composer only fetches modules that are publicly available on Github. Paid WordPress plugins are not, so for them there are basically two alternative approaches. Either you include them in our project repository and distribute them together with the project code, or you get a paid account from Packagist.com that includes the ability to have private Composer packages.