Pink-Crab / debug-plugin

1 stars 0 forks source link

WP CLI #5

Open gin0115 opened 2 months ago

gin0115 commented 2 months ago

The error log should be better for wpcli

gin0115 commented 2 months ago

/views/cli-error.php

<?php
$stack_trace = explode( "\n", $error['message'] );
// Extract main error message
$subheader = array_shift( $stack_trace );
?>
************************************************************ <?php echo "\n"; ?>
CLI ERROR: <?php echo ( $message['response'] ); ?> <?php echo "\n"; ?>
************************************************************ <?php echo "\n"; ?>
<?php echo ( $subheader ); ?> <?php echo "\n"; ?>
************************************************************<?php echo "\n"; ?>
File: <?php echo "{$error['file']} on line {$error['line']}"; ?><?php echo "\n"; ?>
************************************************************<?php echo "\n"; ?>
add_filter(
    'wp_php_error_args',
    function ( $message, $error ) {
        if ( wp_doing_ajax() || pinkcrab_is_rest() ) {
            include 'views/ajax-error.php';
        } elseif ( defined( 'WP_CLI' ) && WP_CLI ) {
            include 'views/cli-error.php';
        } else {
            include 'views/wp-error.php';
        }
    },
    2,
    10
);