WP_CLI::error()
Display error message prefixed with "Error: " and exit script.
Error message is written to STDERR. Defaults to halting script execution with return code 1.
Use WP_CLI::warning() instead when script execution should be permitted to continue.
# `wp cache flush` considers flush failure to be a fatal error. if ( false === wp_cache_flush() ) { WP_CLI::error( 'The object cache could not be flushed.' ); }
Method of the class: WP_CLI{}
No Hooks.
Return
null
. Nothing (null).
Usage
$result = WP_CLI::error( $message, $exit );
- $message(string|WP_Error|Exception|Throwable) (required)
- Message to write to STDERR.
- $exit(true|false|int)
- True defaults to exit(1).
Default: true
WP_CLI::error() WP CLI::error code WP-CLI 2.8.0-alpha
public static function error( $message, $exit = true ) { if ( null !== self::$logger && ! isset( self::get_runner()->assoc_args['completions'] ) ) { self::$logger->error( self::error_to_string( $message ) ); } $return_code = false; if ( true === $exit ) { $return_code = 1; } elseif ( is_int( $exit ) && $exit >= 1 ) { $return_code = $exit; } if ( $return_code ) { if ( self::$capture_exit ) { throw new ExitException( null, $return_code ); } exit( $return_code ); } }