diff --git a/content/bones-console/writing-commands.mdx b/content/bones-console/writing-commands.mdx index b3d209f..e1b8d2d 100644 --- a/content/bones-console/writing-commands.mdx +++ b/content/bones-console/writing-commands.mdx @@ -74,6 +74,32 @@ class Kernel extends ConsoleKernel } ``` +## Using WordPress in a command + +A command runs in the terminal, outside WordPress, and `php bones` does not load WordPress for it. +Call `$this->loadWordPress()` at the start of `handle()` when the command needs WordPress functions +or your plugin. After it, `$this->plugin` is your plugin instance: + +```php filename="plugin/Console/Commands/MyCommand.php" copy +public function handle() +{ + $this->loadWordPress(); + + $this->line('Log type: ' . $this->plugin->config('plugin.logging.type')); + + foreach (get_users() as $user) { + $this->line($user->ID . ' - ' . $user->display_name); + } +} +``` + + + `$this->plugin` is available from WP Bones **v2.0.8**. When your plugin is active it is the very + instance WordPress created, so hooks are not registered twice; when it is not active, + `loadWordPress()` boots it for the command. Run the command from the plugin root: WordPress is + looked up three folders above it, and if it is not there `$this->plugin` stays `null`. + + ## Customizing Deploy You can customize the deployment process by using the action `wpbones_console_deploy_completed`. This is very useful, for example, to delete a folder and write a new file. To do that, you can override the `__construct` method in your command. diff --git a/package.json b/package.json index 9cbda24..223b2a0 100644 --- a/package.json +++ b/package.json @@ -77,5 +77,5 @@ "test": "yarn next typegen && yarn format:test && yarn lint && yarn typecheck && yarn jest", "typecheck": "tsc --noEmit" }, - "version": "2.0.7" + "version": "2.0.8" } diff --git a/public/newsletter/wpbones-2.0.8-console-commands.png b/public/newsletter/wpbones-2.0.8-console-commands.png new file mode 100644 index 0000000..713f1bd Binary files /dev/null and b/public/newsletter/wpbones-2.0.8-console-commands.png differ diff --git a/public/wpkirk-api-boilerplate.zip b/public/wpkirk-api-boilerplate.zip index 5523d12..1884ab3 100644 Binary files a/public/wpkirk-api-boilerplate.zip and b/public/wpkirk-api-boilerplate.zip differ diff --git a/public/wpkirk-blade-boilerplate.zip b/public/wpkirk-blade-boilerplate.zip index fdbefbc..b4f239a 100644 Binary files a/public/wpkirk-blade-boilerplate.zip and b/public/wpkirk-blade-boilerplate.zip differ diff --git a/public/wpkirk-boilerplate.zip b/public/wpkirk-boilerplate.zip index 22a30ab..2867a3b 100644 Binary files a/public/wpkirk-boilerplate.zip and b/public/wpkirk-boilerplate.zip differ diff --git a/public/wpkirk-cpt-boilerplate.zip b/public/wpkirk-cpt-boilerplate.zip index 7210afa..ecee0b2 100644 Binary files a/public/wpkirk-cpt-boilerplate.zip and b/public/wpkirk-cpt-boilerplate.zip differ diff --git a/public/wpkirk-cron-boilerplate.zip b/public/wpkirk-cron-boilerplate.zip index 148149d..6647bb4 100644 Binary files a/public/wpkirk-cron-boilerplate.zip and b/public/wpkirk-cron-boilerplate.zip differ diff --git a/public/wpkirk-database-boilerplate.zip b/public/wpkirk-database-boilerplate.zip index 82e1865..47189d0 100644 Binary files a/public/wpkirk-database-boilerplate.zip and b/public/wpkirk-database-boilerplate.zip differ diff --git a/public/wpkirk-hooks-boilerplate.zip b/public/wpkirk-hooks-boilerplate.zip index e6a3caf..db56d31 100644 Binary files a/public/wpkirk-hooks-boilerplate.zip and b/public/wpkirk-hooks-boilerplate.zip differ diff --git a/public/wpkirk-internationalization-boilerplate.zip b/public/wpkirk-internationalization-boilerplate.zip index eab7235..ce406a8 100644 Binary files a/public/wpkirk-internationalization-boilerplate.zip and b/public/wpkirk-internationalization-boilerplate.zip differ diff --git a/public/wpkirk-mantine-boilerplate.zip b/public/wpkirk-mantine-boilerplate.zip index 8a6cf42..434c6c4 100644 Binary files a/public/wpkirk-mantine-boilerplate.zip and b/public/wpkirk-mantine-boilerplate.zip differ diff --git a/public/wpkirk-options-boilerplate.zip b/public/wpkirk-options-boilerplate.zip index 1717d4b..b3fdf9d 100644 Binary files a/public/wpkirk-options-boilerplate.zip and b/public/wpkirk-options-boilerplate.zip differ diff --git a/public/wpkirk-packages-boilerplate.zip b/public/wpkirk-packages-boilerplate.zip index e943806..3d044ca 100644 Binary files a/public/wpkirk-packages-boilerplate.zip and b/public/wpkirk-packages-boilerplate.zip differ diff --git a/public/wpkirk-reactjs-boilerplate.zip b/public/wpkirk-reactjs-boilerplate.zip index 7677505..dd9a004 100644 Binary files a/public/wpkirk-reactjs-boilerplate.zip and b/public/wpkirk-reactjs-boilerplate.zip differ diff --git a/public/wpkirk-routes-boilerplate.zip b/public/wpkirk-routes-boilerplate.zip index 322851f..8085833 100644 Binary files a/public/wpkirk-routes-boilerplate.zip and b/public/wpkirk-routes-boilerplate.zip differ diff --git a/public/wpkirk-typescript-boilerplate.zip b/public/wpkirk-typescript-boilerplate.zip index 0e3619d..8b328ba 100644 Binary files a/public/wpkirk-typescript-boilerplate.zip and b/public/wpkirk-typescript-boilerplate.zip differ