Skip to content

🐛 fix: expose $this->plugin in Console commands#67

Open
dansleboby wants to merge 1 commit intowpbones:masterfrom
dansleboby:fix/console-command-plugin-access
Open

🐛 fix: expose $this->plugin in Console commands#67
dansleboby wants to merge 1 commit intowpbones:masterfrom
dansleboby:fix/console-command-plugin-access

Conversation

@dansleboby
Copy link
Contributor

  • 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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 $plugin property + setter on Console\Command, and populate it from bootstrap/plugin.php during loadWordPress().
  • Add Kernel::setPlugin() to inject the plugin instance into registered command instances.
  • Track the plugin instance in the bones CLI 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants