When you start adding your WordPress plugins to GitHub, one of the next things you’re likely going to want to do is make it easy for other developers to begin incorporating those packages into their composer.json file.
That is, they don’t have to download your plugin, include it in your project, watch for updates, or anything like that. Instead, they add the file then run:
$ composer update
…whenever they are ready to get the latest version of your work.
But simply contributing your work to GitHub is not enough. You have to submit your WordPress plugin to Packagist (of course, this works with other projects, too, but that’s outside the scope of this blog, really).
And here’s how to do it.
Add Your WordPress Plugin to Packagist
For those who aren’t familiar, here’s the gist of it:
Packagist is the main Composer repository. It aggregates public PHP packages installable with Composer.
In short, it makes it easy to include third-party libraries into your projects via Composer.
Anyway, once your plugin is on GitHub, there are a few more steps to include to get your work ready to register with Packagist. It’s easy, though:
- If you’ve not already, create an account with Packagist,
- Add a composer.json file to your project and make sure it includes the following:
Once done, make sure you update Composer to generate your composer.lock file. From there, navigate to the Submit page and add the URL to your GitHub repository.
From there, you and anyone else will be able to drop in a reference in their project’s respective composer.json file and then have it included in their project.
For a working example of what this may look like, see this project. (And I’ll have more information about this particular project in a future post.)