diff --git a/CHANGELOG.md b/CHANGELOG.md index 1413afff..e046545e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Improved layout for WordPress traces viewer. - Better events messages for lost password form submission. - Improved APCu storage for loggers. +- Reduction of the events' level for the `wp_die` ajax handler because it is not used consistently in the WordPress core (thanks to [Jan Thiel](https://github.com/JanThiel) for the suggestion). - Updated DecaLog SDK from version 2.0.0 to version 2.0.2. - Updated PerfOps One library from 2.2.1 to 2.2.2. - Improved bubbles display when width is less than 500px (thanks to [Pat Ol](https://profiles.wordpress.org/pasglop/)). diff --git a/includes/listeners/class-corelistener.php b/includes/listeners/class-corelistener.php index 1d6af119..d70605e5 100644 --- a/includes/listeners/class-corelistener.php +++ b/includes/listeners/class-corelistener.php @@ -174,7 +174,7 @@ protected function launch() { add_action( 'after_setup_theme', [ $this, 'after_setup_theme' ], PHP_INT_MAX ); add_action( 'switch_theme', [ $this, 'switch_theme' ], 10, 3 ); // Errors. - add_filter( 'wp_die_ajax_handler', [ $this, 'wp_die_handler' ], 10, 1 ); + add_filter( 'wp_die_ajax_handler', [ $this, 'wp_die_ajax_handler' ], 10, 1 ); add_filter( 'wp_die_xmlrpc_handler', [ $this, 'wp_die_handler' ], 10, 1 ); add_filter( 'wp_die_handler', [ $this, 'wp_die_handler' ], 10, 1 ); add_filter( 'wp_die_json_handler', [ $this, 'wp_die_handler' ], 10, 1 ); @@ -1220,8 +1220,6 @@ public function wp_die_handler( $handler ) { } elseif ( '' !== $msg ) { if ( 0 === strpos( $msg, '[' ) || 0 === strpos( $msg, '{' ) ) { $this->logger->debug( wp_kses( $msg, [] ), $code ); - } elseif ( false !== strpos( $msg, '‎' ) ) { // hack to filter wp_ajax_sample_permalink hook. - $this->logger->debug( wp_kses( $msg, [] ), $code ); } else { $this->logger->critical( wp_kses( $msg, [] ), $code ); } @@ -1230,6 +1228,40 @@ public function wp_die_handler( $handler ) { }; } + /** + * "wp_die_*" events. + * + * @since 1.0.0 + */ + public function wp_die_ajax_handler( $handler ) { + if ( ! $handler || ! is_callable( $handler ) ) { + return $handler; + } + return function ( $message, $title = '', $args = [] ) use ( $handler ) { + $msg = ''; + $code = 0; + if ( is_string( $title ) && '' !== $title ) { + $title .= ': '; + } + if ( is_numeric( $title ) ) { + $code = $title; + $title = ''; + } + if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { + $msg = $title . $message->get_error_message(); + $code = $message->get_error_code(); + } elseif ( is_string( $message ) ) { + $msg = $title . $message; + } + if ( is_numeric( $msg ) ) { + $this->logger->debug( 'Malformed wp_die call.', $code ); + } elseif ( '' !== $msg ) { + $this->logger->debug( wp_kses( $msg, [] ), $code ); + } + return $handler( $message, $title, $args ); + }; + } + /** * "wp" event. *