Skip to content
Paul Bunyan Message Logger by Diamond Sierra

Log without depending on Paul Bunyan

Use the paul_bunyan_log action in code you ship to others. It logs when Paul Bunyan is active and does nothing when it is not.

Updated · By Diamond Sierra

The Fix first screen: problems ranked by cost, each with its PB code and what to do
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

PositionValueExample
1The action name'paul_bunyan_log'
2Level: verbose, info, warn or error'info'
3Component'shop'
4Message'Cache warmed'
5Optional data arrayarray( '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 );

See Context, events and markers.