On this page
If your plugin or theme will run on sites that may not have Paul Bunyan, log through a WordPress action instead of calling the pb_ functions. When Paul Bunyan is active it records the message. When it is not, nothing is listening and the action does nothing.
do_action( 'paul_bunyan_log', 'info', 'shop', 'Cache warmed', array( 'items' => 24 ) );The arguments
| Position | Value | Example |
|---|---|---|
| 1 | The action name | 'paul_bunyan_log' |
| 2 | Level: verbose, info, warn or error | 'info' |
| 3 | Component | 'shop' |
| 4 | Message | 'Cache warmed' |
| 5 | Optional data array | array( 'items' => 24 ) |
Why use the action
- No
function_exists()checks in your code. - No fatal error if someone deactivates Paul Bunyan.
- Your users who do run Paul Bunyan get your messages in their timeline, which makes their bug reports to you far more useful.
Context from code you ship
The same approach works for naming the operation a request belongs to:
do_action( 'paul_bunyan_context', 'import:' . $import_id );
