forked from YahnisElsts/plugin-update-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug-bar-plugin.php
102 lines (90 loc) · 2.52 KB
/
debug-bar-plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
if ( !class_exists('PucDebugBarPlugin') ) {
class PucDebugBarPlugin {
/** @var PluginUpdateChecker */
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') ) {
$panels[] = new PluginUpdateCheckerPanel($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'),
'20121026-3'
);
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');
}
}
}