Private or Commercial WordPress Plugins as Composer Dependencies

@szepeviktor funny timing - I’ve just been working on something similar. Mine is a hosted solution that also solves for versioning. I’m looking for beta testers. Shoot me a message if you’d like to put it through its paces.

I think PMs are not available for me

kép

my email address is viktor@szepe.net

Am I mistaken, or are the following correct about the scope of the article?

  1. One repo for one plugin
  2. plugin is unzipped and commited in that format
1 Like

Yep, that’s the intended structure :+1:

2 Likes

I just set up my bedrock with some private plugins according to the guide the op shared, and it’s working well.
BUT my concern is now how I deal with those private plugins, which have an own repo logically, while I’m still developing them.

Creating some edits in a plugin and pushing this to itss repo, now leaves me with having to ‘composer update’ my bedrock repo to the newest plugin version I just pushed, right? But if I do that, my local private plugin repo is kinda f*cked. I’m sure that can’t be the right way… But what is?

TL;DR: What is the recommended way of dealing with private plugin repo’s inside of a bedrock repo, while still developing those plugins?

Those repos should be on GitHub/BitBucket and referenced as custom repositories in your Bedrock project’s composer.json. Docs here. If you have your SSH keys set up properly to push to those private repos, Composer should have no problem installing from them.

If you go to production/staging like that and try running composer install, you’ll have to also provide that server with a way to authenticate against GitHub/BitBucket as well. Like this.

2 Likes

When I set up my own custom repos to pull from bitbucket, composer is cloning them in, with their git files and everything.

When I try to run composer update, this is creating some issues where the filemode setting on the plugins is making it think the files have been changed and preventing composer from running updates.

Is there a way to make it pull my private vcs bitbucket repos WITHOUT the git files?

EDIT: After hours of trying to figure out what was wrong, I solved the following problem. I made a typo (in my username!) in the composer.json in the GitHub repo. This seems kind of silly, but I’ll leave this up, embarrassing as it is, as the “name” field in the composer.json of the repo needs also to be an exact match which makes sense. I didn’t think to look there until hours went by.

Also, just so anyone else reading this in the future the tags work, and are great, but you can also use “dev-master” or any branch you choose to pull the latest if you don’t feel like using the tags.


Hmm… I do appreciate the guide and this is exactly what I’m looking for.

I’ve been following the instructions and started over several times so far though with no luck.

I keep getting stuck with this error:

$ composer update
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires sabelapaulo/mytheme, it could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

There are no typos and the repo is in repositories as instructed. The minimum stability is “dev”. As for the version, I tagged and released 1.0.0, but wasn’t able to get this exact (1.0.0), nor ^1.0, nor even “dev-master” to work.

I also tried composer require from the command line. Same results.

I’m using composer 2 if that matters.

Anyone have any ideas what I might be doing wrong?

2 Likes

I have done this at least twice; once when I didn’t know better (as you did here) and at least once more when I thought I was being super clever. Nice job troubleshooting. You fixed it.

1 Like

How do you deal with the Your GitHub credentials are required to fetch private repository metadata message that comes with private repositories?

Configure composer to use a GitHub auth token:

1 Like

Is this topic still up-to-date/recommended? Unfortunately I seem to be unable to expand the top post. Network tab says: {"errors":["There was an error loading that post."]}

Sorry about that! Our guides are temporarily offline while we’re re-organizing our site and docs

In the meantime you can reach it from the archive

This guide is still relevant/applicable if you’re wanting to use a private git repo for a WP plugin and pull it into your project

Update: This guide is back on our site at Private or Commercial WordPress Plugins as Composer Dependencies | Bedrock Docs | Roots

1 Like

The private WordPress plugin I was hoping to add using a private GitHub repository has it’s own composer.json file at its root which would conflict with the composer.json file I would add following the guide: Private or Commercial WordPress Plugins as Composer Dependencies | Bedrock Docs | Roots

I haven’t seen documentation for composer that suggests how to handle this situation.

In case it’s of help to anyone else, I was able to resolve my issue as follows. I’ll note that I thought I would have to create my own private GitHub repository for the plugin I wanted to include as a dependency because I thought it was private, but it turned out that the plugin has its own public GitHub repository, and so I’m not sure if the resolution here would help with a private dependency (it might!).

Thanks to Daggerhart Lab for providing this guide, which set me on the right track. Essentially, I was able to include this buddyboss-platform WordPress plugin as a dependency in a local WordPress installation using default Bedrock even though the plugin already has a composer.json file in its own root by treating it as a “package” of “type” wordpress-plugin. I’ll post the relevant part of my local composer.json below so you can see how it worked following Daggerhart’s guide.

  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org",
      "only": ["wpackagist-plugin/*", "wpackagist-theme/*"]
    },
    {
      "type": "package",
      "package": {
        "name": "buddyboss/buddyboss-platform",
        "version": "2.2.7",
        "type": "wordpress-plugin",
        "source": {
          "url": "https://github.com/buddyboss/buddyboss-platform.git",
          "type": "git",
          "reference": "2.2.7"
        }
      }
    }
  ],
  "require": {
    "php": ">=7.4",
    "composer/installers": "^2.2",
    "vlucas/phpdotenv": "^5.5",
    "oscarotero/env": "^2.1",
    "roots/bedrock-autoloader": "^1.0",
    "roots/bedrock-disallow-indexing": "^2.0",
    "roots/wordpress": "6.1.1",
    "roots/wp-config": "1.0.0",
    "roots/wp-password-bcrypt": "1.1.0",
    "wpackagist-theme/twentytwentythree": "^1.0",
    "buddyboss/buddyboss-platform": "2.2.7"
  },

At the risk of self-promotion, the recommended solution in this guide can be time-consuming to maintain, so I built this repository template that uses GH Actions to keep your mirror up-to-date.

3 Likes

This looks super cool, thank you!

Hey man, I took a stab at the EDD challenge using your method and SearchWP, and ran into some road blocks. It seems that to get the EDD package link using the method you mentioned, we would need either the exact entry name as it appears in the EDD admin, or the WordPress object ID, neither of which seems readily available from the front-end.

I tried searchwp as the entry name, but that gives me the final version of SearchWP 3, not SearchWP ^4 like I want.

If there’s some way to glean EDD’s ID for the file from the front-end, this is ready to work, otherwise maybe we could contact the SearchWP and FacetWP teams and ask for this detail?

Submit an in progress pull request and we can continue discussion there. Have you attempted to hit the REST API on those sites? It’s possible the EDD post type is public, which would give you the ID.

I’m continuing to poke away at automatically updating private mirrors of premium plugins using @ethanclevenger91’s GitHub Actions method above, and I’ve hit a wall with WooCommerce addons.

If anyone knows how WooCommerce handles authorizing downloads and wants to take a look at this, that would be a great help! Meanwhile I’ll keep pushing.