WP_CLI::debug()
Display debug message prefixed with "Debug: " when --debug is used.
Debug message is written to STDERR, and includes script execution time.
Helpful for optionally showing greater detail when needed. Used throughout WP-CLI bootstrap process for easier debugging and profiling.
# Called in `WP_CLI\Runner::set_wp_root()`. private static function set_wp_root( $path ) { define( 'ABSPATH', Utils\trailingslashit( $path ) ); WP_CLI::debug( 'ABSPATH defined: ' . ABSPATH ); $_SERVER['DOCUMENT_ROOT'] = realpath( $path ); } # Debug details only appear when `--debug` is used. # $ wp --debug # [...] # Debug: ABSPATH defined: /srv/www/wordpress-develop.dev/src/ (0.225s)
Method of the class: WP_CLI{}
No Hooks.
Return
null
. Nothing (null).
Usage
$result = WP_CLI::debug( $message, $group );
- $message(string|WP_Error|Exception|Throwable) (required)
- Message to write to STDERR.
- $group(string|true|false)
- Organize debug message to a specific group. Use false to not group the message.
Default: false
WP_CLI::debug() WP CLI::debug code WP-CLI 2.8.0-alpha
public static function debug( $message, $group = false ) { static $storage = []; if ( ! self::$logger ) { $storage[] = [ $message, $group ]; return; } if ( ! empty( $storage ) && self::$logger ) { foreach ( $storage as $entry ) { list( $stored_message, $stored_group ) = $entry; self::$logger->debug( self::error_to_string( $stored_message ), $stored_group ); } $storage = []; } self::$logger->debug( self::error_to_string( $message ), $group ); }