diff --git a/CHANGELOG.md b/CHANGELOG.md index 1518ee9d..306d3e2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to **DecaLog** are documented in this *changelog*. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and **DecaLog** adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.6.1] - Not Yet Released + +### Changed +- [WP-CLI] A warning is now triggered when an outdated version of WP-CLI is detected. + +### Fixed +- [WP-CLI] With outdated versions of WP-CLI, a PHP uncaught exception is thrown (thanks to [Jan Thiel](https://github.com/JanThiel)). + ## [3.6.0] - 2022-10-06 ### Added diff --git a/includes/plugin/class-initializer.php b/includes/plugin/class-initializer.php index 9c17bb88..55a6ba1b 100644 --- a/includes/plugin/class-initializer.php +++ b/includes/plugin/class-initializer.php @@ -61,19 +61,24 @@ public function late_initialize() { */ public function wpcli_initialize() { if ( defined( 'WP_CLI' ) && WP_CLI ) { - $class = str_replace( 'WP_CLI\Loggers\\', 'Decalog\Listener\WP_CLI\\', get_class( \WP_CLI::get_logger() ) ); - if ( class_exists( $class ) ) { - try { - $reflection = new \ReflectionClass( $class ); - $instance = $reflection->newInstance(); - \WP_CLI::set_logger( $instance ); - } catch ( \Exception $e ) { + if ( method_exists( '\WP_CLI', 'set_logger') && method_exists( '\WP_CLI', 'get_logger') ) { + $class = str_replace( 'WP_CLI\Loggers\\', 'Decalog\Listener\WP_CLI\\', get_class( \WP_CLI::get_logger() ) ); + if ( class_exists( $class ) ) { + try { + $reflection = new \ReflectionClass( $class ); + $instance = $reflection->newInstance(); + \WP_CLI::set_logger( $instance ); + } catch ( \Exception $e ) { + $logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION ); + $logger->critical( sprintf( 'Unable to instanciate `%s` class. DecaLog will not log following WP-CLI events.', $class ) ); + } + } else { $logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION ); - $logger->critical( sprintf( 'Unable to instanciate `%s` class. DecaLog will not log following WP-CLI events.', $class ) ); + $logger->critical( sprintf( 'Unable to find `%s` class. DecaLog will not log following WP-CLI events.', $class ) ); } } else { $logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION ); - $logger->critical( sprintf( 'Unable to find `%s` class. DecaLog will not log following WP-CLI events.', $class ) ); + $logger->warning( 'WP-CLI is outdated: DecaLog will not be able to report events triggered in interactive command-line session. Please, update WP-CLI!' ); } } } diff --git a/init.php b/init.php index dfae90bf..3d3372d9 100644 --- a/init.php +++ b/init.php @@ -12,7 +12,7 @@ define( 'DECALOG_PRODUCT_SHORTNAME', 'DecaLog' ); define( 'DECALOG_PRODUCT_ABBREVIATION', 'decalog' ); define( 'DECALOG_SLUG', 'decalog' ); -define( 'DECALOG_VERSION', '3.6.0' ); +define( 'DECALOG_VERSION', '3.6.1-dev0' ); define( 'DECALOG_API_VERSION', '3' ); define( 'DECALOG_MONOLOG_VERSION', '2.8.0' ); define( 'DECALOG_CODENAME', '"-"' );