Neither contains either a solid reference or a solution.
I learned that:
Plugin’s composer.json needs to define it as "type": "wordpress-plugin" if you want it to be loaded into site/web/app/plugins (or it ends up in site/vendor.)
Still struggling with:
The rest of the "require" dependencies are being put in site/vendor, unless they also have "type": "wordpress-plugin" defined in their composer.json, in which case they are installed as separate plugins.
No dependencies are installed inside of myplugin/vendor. (They’re all in site/vendor or web/app/plugins.)
Well, @allwaysblank, thank you, as usual for your input.
It seems like something is wrong if the dependencies from the plugin are residing simultaneously in two places: site/vendor and app/plugins/my-plugin/vendor.
On a practical level, the autoload_real files composer is trying to require aren’t all there. For example:
/srv/www/ellipticastudios.com/current/vendor/composer/autoload_real.php is trying to find
It’s a little difficult to debug this w/o knowing a little more about what your plugin does and how you intend to distribute it. If you intended to distribute this plugin generally (i.e. it’s not for a specific project/your internal use) you may run into some difficulties w/ packaging and playing nice w/ Bedrock that I don’t know if I can help you with).
A plugin installed through composer is just a composer package installed to a different location. In the context of Bedrock, the code that the plugin executes at runtime will have access to all the dependencies install by Bedrock’s composer.json, and you should write your plugin code accordingly.
You’re correct that this is wrong: They should all be in site/vendor. Your plugin should not have its own vendor folder and composer context (or if it must you can’t/shouldn’t install it w/ Bedrock’s composer.json).
Your plugin’s composer.json is trying to manually load the wp-custom-bulk-actions file but doesn’t ever define wp-custom-bulk-actions as a dependency so I’m not sure how you expect that file to be there. Additionally, if wp-custom-bulk-actionsis defined as a dependency (i.e. GitHub - Seravo/wp-custom-bulk-actions: Custom bulk actions for any type of post in wordpress), then it will be loaded and available to your plugin automatically–no need to manually load the file.
It’s not clear to me why you want the non-standard file organization you’re describing above.
Let’s ignore that for now as I don’t actually need Custom Bulk Actions, which was included in the plugin boiler plate template I’m trying.
In other words, if I’m using a plugin that defines composer dependencies, Composer should install them in site/vendor as opposed to within their individual directories?
Is that also what happens with Sage’s composer dependencies?
Sage and Bedrock are built as separate products–they work well together but neither requires the other. In theory I believe you could move all of the composer stuff Sage depends on (autoloading, dependencies, etc) up to Bedrock–I do this w/ dependencies–but this would fuse your Bedrock and Sage instances together. For the sites I’m usually building, this is fine–they’re not meant to ever be distributed separately–but it’s something to keep in mind depending on future use cases for your theme. That’s why the suggested build-before tasks in Trellis run composer install for Sage on deploy.
You could, in theory, treat your plugins the same way: Keep each one isolated and include a composer install task for each plugin in your deploy setup. I wouldn’t recommend this, because it gets complicated quickly and increases the likelihood of two separate composer installs installing the same package and then exploding at runtime because things are trying to redefine functions or what have you.
The composer paradigm (and the Roots paradigm, insofar as we can cram it into WordPress) is about treating your site as a single app, and everything else as a dependency for that app. In Roots this means that WordPress, plugins, and composer packages are dependencies–conceptually it’s pretty “flat.” Unfortunately WordPress has a different conception of what things are, what they mean, and where they go, and that makes it hard to line up the paradigms perfectly.
Yes. It is being annoying and I’m not necessarily planning to use this plugin elsewhere. So I have added !web/app/plugins/myplugin to git ignore and am including as part of the single Trellis/Bedrock app.
So in the plugin where I call on the dependencies:
Would you update MY_PLUGIN_ROOT to instead point to whatever bedrock defines current/site as? (If you know off-hand what that is, I’m poking around for it now.)
I have moved the composer requirements from the plugin’s own composer.json file into site/composer.json, including the psr4 autoloads which I am currently pointing into the plugin
Currently requireing the Composer\Autoload\ClassLoader object (as opposed to require_once) in the plugin, because of the way the plugin is setup to “Initialize”. Using require_once, instead of returning the object, was returning boolean true, because that file has already been loaded (at the top of wp-config.). Thank you, SO.
This is, maybe, redundant. I’m thinking of refactoring the plugin into the Acorn framework.
For now, at least, I seem to be up and running again.
Thanks. At this point I have it working with the codebase as part of the Bedrock app, managing the plugins dependencies via site/composer.php. Since it’s setup to require the Composer\Autoload\ClassLoader, I’m requiring that a second time from within the plugin itself and it seems to be working.
As mentioned above, I may migrate to Acorn, but I discovered some new dependencies, like codeception, that I’m glad to now be aware of.