🐛 fix: expose $this->plugin in Console commands#67
Open
dansleboby wants to merge 1 commit intowpbones:masterfrom
Open
🐛 fix: expose $this->plugin in Console commands#67dansleboby wants to merge 1 commit intowpbones:masterfrom
dansleboby wants to merge 1 commit intowpbones:masterfrom
Conversation
Contributor
dansleboby
commented
Feb 23, 2026
- Add protected $plugin property and setPluginAttribute() setter to Command
- Fix loadWordPress() to use $currentDir (plugin root via $_SERVER['PWD']) instead of DIR for vendor/bootstrap paths, which was resolving to the wrong directory inside the vendor tree
- Capture the return value of bootstrap/plugin.php so $this->plugin is populated after calling loadWordPress()
- Add Kernel::setPlugin() to propagate the plugin instance to all registered command instances
- Store plugin in BonesCommandLine and pass it to the kernel before dispatching custom commands
- Add protected $plugin property and setPluginAttribute() setter to Command - Fix loadWordPress() to use $currentDir (plugin root via $_SERVER['PWD']) instead of __DIR__ for vendor/bootstrap paths, which was resolving to the wrong directory inside the vendor tree - Capture the return value of bootstrap/plugin.php so $this->plugin is populated after calling loadWordPress() - Add Kernel::setPlugin() to propagate the plugin instance to all registered command instances - Store plugin in BonesCommandLine and pass it to the kernel before dispatching custom commands
There was a problem hiding this comment.
Pull request overview
This PR aims to make the plugin instance available inside custom console commands (via $this->plugin) by capturing it from bootstrap/plugin.php and propagating it through the console kernel, while also fixing WordPress/bootstrap path resolution when running commands from a plugin root directory.
Changes:
- Add a
$pluginproperty + setter onConsole\Command, and populate it frombootstrap/plugin.phpduringloadWordPress(). - Add
Kernel::setPlugin()to inject the plugin instance into registered command instances. - Track the plugin instance in the
bonesCLI and pass it into the kernel before dispatching custom commands.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Foundation/Console/Kernel.php | Adds setPlugin() to propagate the plugin instance to registered command objects. |
| src/Console/bin/bones | Stores plugin instance in the CLI runtime and attempts to pass it to the kernel before handling custom commands. |
| src/Console/Command.php | Introduces a protected $plugin property + setter and updates loadWordPress() to use the working directory for vendor/bootstrap paths and to capture the plugin instance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.