From 54ba716ba866aeb479bc981409ea7aefc99b9bb9 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Tue, 2 Jul 2019 14:42:19 +0300 Subject: [PATCH] Fixed crash from broken plugin loaded hook input from global Fixes #35 --- CHANGELOG.md | 3 +++ src/Record/Collector/Plugin_Load_Collector.php | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5690eb2..7655220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Fixed +- crash from broken plugin loaded hook input from global + ## 3.3 - 2019-03-27 ### Added diff --git a/src/Record/Collector/Plugin_Load_Collector.php b/src/Record/Collector/Plugin_Load_Collector.php index 60fca42..22f8d95 100644 --- a/src/Record/Collector/Plugin_Load_Collector.php +++ b/src/Record/Collector/Plugin_Load_Collector.php @@ -32,15 +32,22 @@ public function __construct() { * * @param string $plugin Plugin file path. */ - public function plugin_loaded( string $plugin ): void { + public function plugin_loaded( $plugin ): void { + + $time = microtime( true ); + + if ( ! is_string( $plugin ) ) { // Broken hook input from global. + $this->last = $time; + + return; + } - $time = microtime( true ); $this->entries[] = [ 'name' => $plugin, 'origin' => $this->last, 'duration' => $time - $this->last, ]; - $this->last = $time; + $this->last = $time; } /**