Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions content/bones-console/writing-commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
```

<Callout type="info">
`$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`.
</Callout>

## 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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/wpkirk-api-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-blade-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-cpt-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-cron-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-database-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-hooks-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-internationalization-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-mantine-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-options-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-packages-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-reactjs-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-routes-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-typescript-boilerplate.zip
Binary file not shown.
Loading