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
This commit is contained in:
parent
b75f5555c2
commit
5e48f0c853
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue