Rename DebugBar AJAX actions to prevent conflicts with previous versions.

This commit is contained in:
Yahnis Elsts 2016-12-19 19:05:06 +02:00
parent 8c7b3f80d6
commit f1e59b183c
4 changed files with 9 additions and 99 deletions

View File

@ -15,7 +15,7 @@ if ( !class_exists('Puc_v4_DebugBar_Extension', false) ):
add_filter('debug_bar_panels', array($this, 'addDebugBarPanel')); add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies')); add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
add_action('wp_ajax_puc_debug_check_now', array($this, 'ajaxCheckNow')); add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
} }
/** /**
@ -46,7 +46,7 @@ if ( !class_exists('Puc_v4_DebugBar_Extension', false) ):
'puc-debug-bar-js-v4', 'puc-debug-bar-js-v4',
$this->getLibraryUrl("/js/debug-bar.js"), $this->getLibraryUrl("/js/debug-bar.js"),
array('jquery'), array('jquery'),
'20161217-3' '20161219'
); );
} }

View File

@ -8,7 +8,7 @@ if ( !class_exists('Puc_v4_DebugBar_PluginExtension', false) ):
public function __construct($updateChecker) { public function __construct($updateChecker) {
parent::__construct($updateChecker, 'Puc_v4_DebugBar_PluginPanel'); parent::__construct($updateChecker, 'Puc_v4_DebugBar_PluginPanel');
add_action('wp_ajax_puc_debug_request_info', array($this, 'ajaxRequestInfo')); add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
} }
/** /**

View File

@ -21,12 +21,12 @@ jQuery(function($) {
} }
$('.puc-debug-bar-panel-v4 input[name="puc-check-now-button"]').click(function() { $('.puc-debug-bar-panel-v4 input[name="puc-check-now-button"]').click(function() {
runAjaxAction(this, 'puc_debug_check_now'); runAjaxAction(this, 'puc_v4_debug_check_now');
return false; return false;
}); });
$('.puc-debug-bar-panel-v4 input[name="puc-request-info-button"]').click(function() { $('.puc-debug-bar-panel-v4 input[name="puc-request-info-button"]').click(function() {
runAjaxAction(this, 'puc_debug_request_info'); runAjaxAction(this, 'puc_v4_debug_request_info');
return false; return false;
}); });

View File

@ -10,98 +10,8 @@
require dirname(__FILE__) . '/Puc/v4/Autoloader.php'; require dirname(__FILE__) . '/Puc/v4/Autoloader.php';
new Puc_v4_Autoloader(); new Puc_v4_Autoloader();
if ( !class_exists('PucFactory', false) ):
/**
* A factory that builds instances of other classes from this library.
*
* When multiple versions of the same class have been loaded (e.g. PluginUpdateChecker 1.2
* and 1.3), this factory will always use the latest available version. Register class
* versions by calling {@link PucFactory::addVersion()}.
*
* At the moment it can only build instances of the PluginUpdateChecker class. Other classes
* are intended mainly for internal use and refer directly to specific implementations. If you
* want to instantiate one of them anyway, you can use {@link PucFactory::getLatestClassVersion()}
* to get the class name and then create it with <code>new $class(...)</code>.
*/
class PucFactory {
protected static $classVersions = array();
protected static $sorted = false;
/**
* Create a new instance of PluginUpdateChecker.
*
* @see PluginUpdateChecker::__construct()
*
* @param $metadataUrl
* @param $pluginFile
* @param string $slug
* @param int $checkPeriod
* @param string $optionName
* @param string $muPluginFile
* @return Puc_v4_Plugin_UpdateChecker
*/
public static function buildUpdateChecker($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
$class = self::getLatestClassVersion('PluginUpdateChecker');
return new $class($metadataUrl, $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
}
/**
* Get the specific class name for the latest available version of a class.
*
* @param string $class
* @return string|null
*/
public static function getLatestClassVersion($class) {
if ( !self::$sorted ) {
self::sortVersions();
}
if ( isset(self::$classVersions[$class]) ) {
return reset(self::$classVersions[$class]);
} else {
return null;
}
}
/**
* Sort available class versions in descending order (i.e. newest first).
*/
protected static function sortVersions() {
foreach ( self::$classVersions as $class => $versions ) {
uksort($versions, array(__CLASS__, 'compareVersions'));
self::$classVersions[$class] = $versions;
}
self::$sorted = true;
}
protected static function compareVersions($a, $b) {
return -version_compare($a, $b);
}
/**
* Register a version of a class.
*
* @access private This method is only for internal use by the library.
*
* @param string $generalClass Class name without version numbers, e.g. 'PluginUpdateChecker'.
* @param string $versionedClass Actual class name, e.g. 'PluginUpdateChecker_1_2'.
* @param string $version Version number, e.g. '1.2'.
*/
public static function addVersion($generalClass, $versionedClass, $version) {
if ( !isset(self::$classVersions[$generalClass]) ) {
self::$classVersions[$generalClass] = array();
}
self::$classVersions[$generalClass][$version] = $versionedClass;
self::$sorted = false;
}
}
endif;
//Register classes defined in this file with the factory. //Register classes defined in this file with the factory.
PucFactory::addVersion('PluginUpdateChecker', 'Puc_v4_Plugin_UpdateChecker', '4.0'); Puc_v4_Factory::addVersion('Plugin_UpdateChecker', 'Puc_v4_Plugin_UpdateChecker', '4.0');
PucFactory::addVersion('PluginUpdate', 'Puc_v4_Plugin_Update', '4.0'); Puc_v4_Factory::addVersion('Theme_UpdateChecker', 'Puc_v4_Theme_UpdateChecker', '4.0');
PucFactory::addVersion('PluginInfo', 'Puc_v4_Plugin_Info', '4.0'); Puc_v4_Factory::addVersion('GitHub_PluginUpdateChecker', 'Puc_v4_GitHub_PluginUpdateChecker', '4.0');
PucFactory::addVersion('PucGitHubChecker', 'Puc_v4_GitHub_PluginChecker', '4.0'); Puc_v4_Factory::addVersion('GitHub_ThemeUpdateChecker', 'Puc_v4_GitHub_ThemeUpdateChecker', '4.0');