mirror of
https://gh.wpcy.net/https://github.com/YahnisElsts/plugin-update-checker.git
synced 2026-04-26 01:22:55 +08:00
While most PUC class names use version number suffixes to avoid conflicts with older versions of the library, the classes responsible for Debug Bar integration did not (until now). This is because those classes are fairly simple and they have stayed mostly unchanged since version 1.0. Mostly, but not completely. For example, the debug bar panel depends on the getCronHookName() function, and that function was recently moved to the new PucScheduler class. This is a problem because when your site has two plugins using two different versions of this library (e.g. 3.0 and 1.3), you can end up in a situation where PluginUpdateChecker_3_0 unintentionally instantiates the old version of PluginUpdateCheckerPanel (1.3). Then the panel then tries to access a non-existent field or method of PluginUpdateChecker_3_0 and crashes. It produces errors like this: [26-Apr-2016 13:34:14 UTC] PHP Fatal error: Call to undefined method PluginUpdateChecker_3_0::getCronHookName() in [redacted]\wp-content\plugins\plugin-name-here\inc\plugin-updates\debug-bar-panel.php on line 58 Fixed by versioning debug bar panel class names.
102 lines
No EOL
2.6 KiB
PHP
102 lines
No EOL
2.6 KiB
PHP
<?php
|
|
if ( !class_exists('PucDebugBarPlugin_3_0', false) ) {
|
|
|
|
class PucDebugBarPlugin_3_0 {
|
|
/** @var PluginUpdateChecker_3_0 */
|
|
private $updateChecker;
|
|
|
|
public function __construct($updateChecker) {
|
|
$this->updateChecker = $updateChecker;
|
|
|
|
add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
|
|
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_debug_request_info', array($this, 'ajaxRequestInfo'));
|
|
}
|
|
|
|
/**
|
|
* Register the PUC Debug Bar panel.
|
|
*
|
|
* @param array $panels
|
|
* @return array
|
|
*/
|
|
public function addDebugBarPanel($panels) {
|
|
require_once dirname(__FILE__) . '/debug-bar-panel.php';
|
|
if ( current_user_can('update_plugins') && class_exists('PluginUpdateCheckerPanel_3_0', false) ) {
|
|
$panels[] = new PluginUpdateCheckerPanel_3_0($this->updateChecker);
|
|
}
|
|
return $panels;
|
|
}
|
|
|
|
/**
|
|
* Enqueue our Debug Bar scripts and styles.
|
|
*/
|
|
public function enqueuePanelDependencies() {
|
|
wp_enqueue_style(
|
|
'puc-debug-bar-style',
|
|
plugins_url( "/css/puc-debug-bar.css", __FILE__ ),
|
|
array('debug-bar'),
|
|
'20130927'
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'puc-debug-bar-js',
|
|
plugins_url( "/js/debug-bar.js", __FILE__ ),
|
|
array('jquery'),
|
|
'20121026'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Run an update check and output the result. Useful for making sure that
|
|
* the update checking process works as expected.
|
|
*/
|
|
public function ajaxCheckNow() {
|
|
if ( $_POST['slug'] !== $this->updateChecker->slug ) {
|
|
return;
|
|
}
|
|
$this->preAjaxReqest();
|
|
$update = $this->updateChecker->checkForUpdates();
|
|
if ( $update !== null ) {
|
|
echo "An update is available:";
|
|
echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
|
|
} else {
|
|
echo 'No updates found.';
|
|
}
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Request plugin info and output it.
|
|
*/
|
|
public function ajaxRequestInfo() {
|
|
if ( $_POST['slug'] !== $this->updateChecker->slug ) {
|
|
return;
|
|
}
|
|
$this->preAjaxReqest();
|
|
$info = $this->updateChecker->requestInfo();
|
|
if ( $info !== null ) {
|
|
echo 'Successfully retrieved plugin info from the metadata URL:';
|
|
echo '<pre>', htmlentities(print_r($info, true)), '</pre>';
|
|
} else {
|
|
echo 'Failed to retrieve plugin info from the metadata URL.';
|
|
}
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Check access permissions and enable error display (for debugging).
|
|
*/
|
|
private function preAjaxReqest() {
|
|
if ( !current_user_can('update_plugins') ) {
|
|
die('Access denied');
|
|
}
|
|
check_ajax_referer('puc-ajax');
|
|
|
|
error_reporting(E_ALL);
|
|
@ini_set('display_errors','On');
|
|
}
|
|
}
|
|
|
|
} |