From 5e48f0c8530fea82b6683f15c8cc89485d262875 Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Thu, 22 Feb 2018 18:51:25 +0200 Subject: [PATCH] Fixed slug conflict detection. Also fixed a related bug where calling the triggerError() method inside the update checker constructor would not trigger an error even if WP_DEBUG was enabled. The `debugMode` property didn't get initialized until the base class constructor was run. To fix that, I've added a new isDebugModeEnabled() method that performs lazy initialisation. The downside is that it duplicates one line of code from the constructor. Closes #180 --- Puc/v4p4/Plugin/UpdateChecker.php | 4 ++-- Puc/v4p4/UpdateChecker.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Puc/v4p4/Plugin/UpdateChecker.php b/Puc/v4p4/Plugin/UpdateChecker.php index 865df8e..2d99437 100644 --- a/Puc/v4p4/Plugin/UpdateChecker.php +++ b/Puc/v4p4/Plugin/UpdateChecker.php @@ -41,12 +41,12 @@ if ( !class_exists('Puc_v4p4_Plugin_UpdateChecker', false) ): } //Plugin slugs must be unique. - $slugCheckFilter = 'puc_is_slug_in_use-' . $this->slug; + $slugCheckFilter = 'puc_is_slug_in_use-' . $slug; $slugUsedBy = apply_filters($slugCheckFilter, false); if ( $slugUsedBy ) { $this->triggerError(sprintf( 'Plugin slug "%s" is already in use by %s. Slugs must be unique.', - htmlentities($this->slug), + htmlentities($slug), htmlentities($slugUsedBy) ), E_USER_ERROR); } diff --git a/Puc/v4p4/UpdateChecker.php b/Puc/v4p4/UpdateChecker.php index 2eea878..7ead6fe 100644 --- a/Puc/v4p4/UpdateChecker.php +++ b/Puc/v4p4/UpdateChecker.php @@ -12,7 +12,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ): * and should be logged to the standard PHP error log. * @var bool */ - public $debugMode = false; + public $debugMode = null; /** * @var string Where to store the update info. @@ -330,11 +330,21 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ): * @param int $errorType */ protected function triggerError($message, $errorType) { - if ($this->debugMode) { + if ($this->isDebugModeEnabled()) { trigger_error($message, $errorType); } } + /** + * @return bool + */ + protected function isDebugModeEnabled() { + if ($this->debugMode === null) { + $this->debugMode = (bool)(constant('WP_DEBUG')); + } + return $this->debugMode; + } + /** * Get the full name of an update checker filter, action or DB entry. *