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.

Adding Your WordPress Plugin To Packagist

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:

  1. If you’ve not already, create an account with Packagist,
  2. 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.

An Example

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.)


Join the conversation! 8 Comments

  1. Using packagist for WordPress related stuff is great and I really appreciate it when developers do that.

    However, I assume you are aware of that, but for completion’s sake, there is https://wpackagist.org/ which makes every wordpress.org hosted plugin and theme available through composer.

    I would like to hear your thoughts on that: Do you prefer Packagist or is WPackagist also an option for you?

    • I would like to hear your thoughts on that: Do you prefer Packagist or is WPackagist also an option for you?

      It really just depends on the plugin. The more work I do for others, the more inclined I am to keep it on Packagist though this one particular plugin is just an example. I don’t have much of anything else on there right now.

  2. I host mine on github, composer can be tweeked to pull in the repo as seen here https://github.com/MetuMaribe/sweetapi-php-client

  3. Lest the above critique be misconstrued, i appreciate this blog and have used and intend to continue to use it as a resource, the attempt at clarification is for my and others use so “we” get the best out of these resources as we continually seek improvements, i may also like you said be following a totally different thought pattern from you regarding this implementation. Thanks again Tom.

  4. Thanks for the post Tom, this will greatly help , it’s will make it easy for adding WordPress plugin project dependencies out of the box .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.