@@ -4,109 +4,109 @@ |
||
4 | 4 | |
5 | 5 | class Profiler |
6 | 6 | { |
7 | - /** |
|
8 | - * This is the time that WordPress takes to execute the profiler hook. |
|
9 | - * @var int |
|
10 | - */ |
|
11 | - protected $noise = 0; |
|
7 | + /** |
|
8 | + * This is the time that WordPress takes to execute the profiler hook. |
|
9 | + * @var int |
|
10 | + */ |
|
11 | + protected $noise = 0; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @var int |
|
15 | - */ |
|
16 | - protected $start = null; |
|
13 | + /** |
|
14 | + * @var int |
|
15 | + */ |
|
16 | + protected $start = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @var int |
|
20 | - */ |
|
21 | - protected $stop = null; |
|
18 | + /** |
|
19 | + * @var int |
|
20 | + */ |
|
21 | + protected $stop = null; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $timers = array(); |
|
23 | + /** |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $timers = array(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public function getMeasure() |
|
32 | - { |
|
33 | - return $this->timers; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public function getMeasure() |
|
32 | + { |
|
33 | + return $this->timers; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param array $timer |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getMemoryString($timer) |
|
41 | - { |
|
42 | - $timer = $this->normalize($timer); |
|
43 | - return sprintf('%s kB', round($timer['memory'] / 1000)); |
|
44 | - } |
|
36 | + /** |
|
37 | + * @param array $timer |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getMemoryString($timer) |
|
41 | + { |
|
42 | + $timer = $this->normalize($timer); |
|
43 | + return sprintf('%s kB', round($timer['memory'] / 1000)); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $timer |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getNameString($timer) |
|
51 | - { |
|
52 | - $timer = $this->normalize($timer); |
|
53 | - return $timer['name']; |
|
54 | - } |
|
46 | + /** |
|
47 | + * @param array $timer |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getNameString($timer) |
|
51 | + { |
|
52 | + $timer = $this->normalize($timer); |
|
53 | + return $timer['name']; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param array $timer |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getTimeString($timer) |
|
61 | - { |
|
62 | - $timer = $this->normalize($timer); |
|
63 | - $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
64 | - $start = $this->start + ($index * $this->noise); |
|
65 | - $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
66 | - return sprintf('%s ms', $time); |
|
67 | - } |
|
56 | + /** |
|
57 | + * @param array $timer |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getTimeString($timer) |
|
61 | + { |
|
62 | + $timer = $this->normalize($timer); |
|
63 | + $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
64 | + $start = $this->start + ($index * $this->noise); |
|
65 | + $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
66 | + return sprintf('%s ms', $time); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return int Microseconds |
|
71 | - */ |
|
72 | - public function getTotalTime() |
|
73 | - { |
|
74 | - $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
75 | - return $this->stop - $this->start - $totalNoise; |
|
76 | - } |
|
69 | + /** |
|
70 | + * @return int Microseconds |
|
71 | + */ |
|
72 | + public function getTotalTime() |
|
73 | + { |
|
74 | + $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
75 | + return $this->stop - $this->start - $totalNoise; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $name |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function trace($name) |
|
83 | - { |
|
84 | - $microtime = microtime(true); |
|
85 | - if (!$this->start) { |
|
86 | - $this->start = $microtime; |
|
87 | - } |
|
88 | - if ('blackbar/profiler/noise' === $name) { |
|
89 | - $this->noise = $microtime - $this->start; |
|
90 | - return; |
|
91 | - } |
|
92 | - $this->timers[] = array( |
|
93 | - 'memory' => memory_get_peak_usage(), |
|
94 | - 'name' => $name, |
|
95 | - 'time' => $microtime, |
|
96 | - ); |
|
97 | - $this->stop = $microtime; |
|
98 | - } |
|
78 | + /** |
|
79 | + * @param string $name |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function trace($name) |
|
83 | + { |
|
84 | + $microtime = microtime(true); |
|
85 | + if (!$this->start) { |
|
86 | + $this->start = $microtime; |
|
87 | + } |
|
88 | + if ('blackbar/profiler/noise' === $name) { |
|
89 | + $this->noise = $microtime - $this->start; |
|
90 | + return; |
|
91 | + } |
|
92 | + $this->timers[] = array( |
|
93 | + 'memory' => memory_get_peak_usage(), |
|
94 | + 'name' => $name, |
|
95 | + 'time' => $microtime, |
|
96 | + ); |
|
97 | + $this->stop = $microtime; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param array $timer |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - protected function normalize($timer) |
|
105 | - { |
|
106 | - return wp_parse_args((array) $timer, array( |
|
107 | - 'memory' => 0, |
|
108 | - 'name' => '', |
|
109 | - 'time' => 0, |
|
110 | - )); |
|
111 | - } |
|
100 | + /** |
|
101 | + * @param array $timer |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + protected function normalize($timer) |
|
105 | + { |
|
106 | + return wp_parse_args((array) $timer, array( |
|
107 | + 'memory' => 0, |
|
108 | + 'name' => '', |
|
109 | + 'time' => 0, |
|
110 | + )); |
|
111 | + } |
|
112 | 112 | } |
@@ -37,33 +37,33 @@ discard block |
||
37 | 37 | * @param array $timer |
38 | 38 | * @return string |
39 | 39 | */ |
40 | - public function getMemoryString($timer) |
|
40 | + public function getMemoryString( $timer ) |
|
41 | 41 | { |
42 | - $timer = $this->normalize($timer); |
|
43 | - return sprintf('%s kB', round($timer['memory'] / 1000)); |
|
42 | + $timer = $this->normalize( $timer ); |
|
43 | + return sprintf( '%s kB', round( $timer[ 'memory' ] / 1000 ) ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param array $timer |
48 | 48 | * @return string |
49 | 49 | */ |
50 | - public function getNameString($timer) |
|
50 | + public function getNameString( $timer ) |
|
51 | 51 | { |
52 | - $timer = $this->normalize($timer); |
|
53 | - return $timer['name']; |
|
52 | + $timer = $this->normalize( $timer ); |
|
53 | + return $timer[ 'name' ]; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @param array $timer |
58 | 58 | * @return string |
59 | 59 | */ |
60 | - public function getTimeString($timer) |
|
60 | + public function getTimeString( $timer ) |
|
61 | 61 | { |
62 | - $timer = $this->normalize($timer); |
|
63 | - $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
64 | - $start = $this->start + ($index * $this->noise); |
|
65 | - $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
66 | - return sprintf('%s ms', $time); |
|
62 | + $timer = $this->normalize( $timer ); |
|
63 | + $index = array_search( $timer[ 'name' ], array_column( $this->timers, 'name' ) ); |
|
64 | + $start = $this->start + ( $index * $this->noise ); |
|
65 | + $time = number_format( round( ( $timer[ 'time' ] - $start ) * 1000, 4 ), 4 ); |
|
66 | + return sprintf( '%s ms', $time ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function getTotalTime() |
73 | 73 | { |
74 | - $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
74 | + $totalNoise = ( count( $this->timers ) - 1 ) * $this->noise; |
|
75 | 75 | return $this->stop - $this->start - $totalNoise; |
76 | 76 | } |
77 | 77 | |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | * @param string $name |
80 | 80 | * @return void |
81 | 81 | */ |
82 | - public function trace($name) |
|
82 | + public function trace( $name ) |
|
83 | 83 | { |
84 | - $microtime = microtime(true); |
|
85 | - if (!$this->start) { |
|
84 | + $microtime = microtime( true ); |
|
85 | + if( !$this->start ) { |
|
86 | 86 | $this->start = $microtime; |
87 | 87 | } |
88 | - if ('blackbar/profiler/noise' === $name) { |
|
88 | + if( 'blackbar/profiler/noise' === $name ) { |
|
89 | 89 | $this->noise = $microtime - $this->start; |
90 | 90 | return; |
91 | 91 | } |
92 | - $this->timers[] = array( |
|
92 | + $this->timers[ ] = array( |
|
93 | 93 | 'memory' => memory_get_peak_usage(), |
94 | 94 | 'name' => $name, |
95 | 95 | 'time' => $microtime, |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | * @param array $timer |
102 | 102 | * @return array |
103 | 103 | */ |
104 | - protected function normalize($timer) |
|
104 | + protected function normalize( $timer ) |
|
105 | 105 | { |
106 | - return wp_parse_args((array) $timer, array( |
|
106 | + return wp_parse_args( (array) $timer, array( |
|
107 | 107 | 'memory' => 0, |
108 | 108 | 'name' => '', |
109 | 109 | 'time' => 0, |
110 | - )); |
|
110 | + ) ); |
|
111 | 111 | } |
112 | 112 | } |
@@ -4,289 +4,289 @@ |
||
4 | 4 | |
5 | 5 | class Controller |
6 | 6 | { |
7 | - /** |
|
8 | - * @var Application |
|
9 | - */ |
|
10 | - protected $app; |
|
7 | + /** |
|
8 | + * @var Application |
|
9 | + */ |
|
10 | + protected $app; |
|
11 | 11 | |
12 | - public function __construct(Application $app) |
|
13 | - { |
|
14 | - $this->app = $app; |
|
15 | - } |
|
12 | + public function __construct(Application $app) |
|
13 | + { |
|
14 | + $this->app = $app; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return void |
|
19 | - * @action admin_enqueue_scripts |
|
20 | - * @action wp_enqueue_scripts |
|
21 | - */ |
|
22 | - public function enqueueAssets() |
|
23 | - { |
|
24 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
25 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), array('dashicons')); |
|
26 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
27 | - } |
|
17 | + /** |
|
18 | + * @return void |
|
19 | + * @action admin_enqueue_scripts |
|
20 | + * @action wp_enqueue_scripts |
|
21 | + */ |
|
22 | + public function enqueueAssets() |
|
23 | + { |
|
24 | + wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
25 | + wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), array('dashicons')); |
|
26 | + wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param string $classes |
|
31 | - * @return string |
|
32 | - * @action admin_body_class |
|
33 | - */ |
|
34 | - public function filterBodyClasses($classes) |
|
35 | - { |
|
36 | - return trim($classes.' '.Application::ID); |
|
37 | - } |
|
29 | + /** |
|
30 | + * @param string $classes |
|
31 | + * @return string |
|
32 | + * @action admin_body_class |
|
33 | + */ |
|
34 | + public function filterBodyClasses($classes) |
|
35 | + { |
|
36 | + return trim($classes.' '.Application::ID); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return void |
|
41 | - * @filter all |
|
42 | - */ |
|
43 | - public function initConsole() |
|
44 | - { |
|
45 | - if (Application::CONSOLE_HOOK != func_get_arg(0)) { |
|
46 | - return; |
|
47 | - } |
|
48 | - $args = array_pad(func_get_args(), 4, ''); |
|
49 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
50 | - $entry = array_pop($backtrace); |
|
51 | - $location = $args[3]; |
|
52 | - if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
53 | - $path = explode(ABSPATH, $entry['file']); |
|
54 | - $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
55 | - } |
|
56 | - $this->app->console->store($args[1], $args[2], '['.$location.'] '); |
|
57 | - } |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + * @filter all |
|
42 | + */ |
|
43 | + public function initConsole() |
|
44 | + { |
|
45 | + if (Application::CONSOLE_HOOK != func_get_arg(0)) { |
|
46 | + return; |
|
47 | + } |
|
48 | + $args = array_pad(func_get_args(), 4, ''); |
|
49 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
50 | + $entry = array_pop($backtrace); |
|
51 | + $location = $args[3]; |
|
52 | + if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
53 | + $path = explode(ABSPATH, $entry['file']); |
|
54 | + $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
55 | + } |
|
56 | + $this->app->console->store($args[1], $args[2], '['.$location.'] '); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return void |
|
61 | - * @filter all |
|
62 | - */ |
|
63 | - public function initProfiler() |
|
64 | - { |
|
65 | - if (Application::PROFILER_HOOK != func_get_arg(0)) { |
|
66 | - return; |
|
67 | - } |
|
68 | - $this->app->profiler->trace(func_get_arg(1)); |
|
69 | - } |
|
59 | + /** |
|
60 | + * @return void |
|
61 | + * @filter all |
|
62 | + */ |
|
63 | + public function initProfiler() |
|
64 | + { |
|
65 | + if (Application::PROFILER_HOOK != func_get_arg(0)) { |
|
66 | + return; |
|
67 | + } |
|
68 | + $this->app->profiler->trace(func_get_arg(1)); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return void |
|
73 | - * @filter all |
|
74 | - */ |
|
75 | - public function measureSlowActions() |
|
76 | - { |
|
77 | - $this->app->actions->startTimer(); |
|
78 | - } |
|
71 | + /** |
|
72 | + * @return void |
|
73 | + * @filter all |
|
74 | + */ |
|
75 | + public function measureSlowActions() |
|
76 | + { |
|
77 | + $this->app->actions->startTimer(); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return void |
|
82 | - * @action plugins_loaded |
|
83 | - */ |
|
84 | - public function registerLanguages() |
|
85 | - { |
|
86 | - load_plugin_textdomain(Application::ID, false, |
|
87 | - plugin_basename($this->app->path()).Application::LANG |
|
88 | - ); |
|
89 | - } |
|
80 | + /** |
|
81 | + * @return void |
|
82 | + * @action plugins_loaded |
|
83 | + */ |
|
84 | + public function registerLanguages() |
|
85 | + { |
|
86 | + load_plugin_textdomain(Application::ID, false, |
|
87 | + plugin_basename($this->app->path()).Application::LANG |
|
88 | + ); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - * @action admin_footer |
|
94 | - * @action wp_footer |
|
95 | - */ |
|
96 | - public function renderBar() |
|
97 | - { |
|
98 | - apply_filters('debug', 'Profiler Stopped'); |
|
99 | - $this->app->render('debug-bar', array( |
|
100 | - 'blackbar' => $this->app, |
|
101 | - 'actions' => $this->app->actions, |
|
102 | - 'actionsLabel' => $this->getSlowActionsLabel(), |
|
103 | - 'consoleEntries' => $this->getConsoleEntries(), |
|
104 | - 'consoleLabel' => $this->getConsoleLabel(), |
|
105 | - 'profiler' => $this->app->profiler, |
|
106 | - 'profilerLabel' => $this->getProfilerLabel(), |
|
107 | - 'queries' => $this->getQueries(), |
|
108 | - 'queriesLabel' => $this->getQueriesLabel(), |
|
109 | - 'templates' => $this->getTemplates(), |
|
110 | - )); |
|
111 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + * @action admin_footer |
|
94 | + * @action wp_footer |
|
95 | + */ |
|
96 | + public function renderBar() |
|
97 | + { |
|
98 | + apply_filters('debug', 'Profiler Stopped'); |
|
99 | + $this->app->render('debug-bar', array( |
|
100 | + 'blackbar' => $this->app, |
|
101 | + 'actions' => $this->app->actions, |
|
102 | + 'actionsLabel' => $this->getSlowActionsLabel(), |
|
103 | + 'consoleEntries' => $this->getConsoleEntries(), |
|
104 | + 'consoleLabel' => $this->getConsoleLabel(), |
|
105 | + 'profiler' => $this->app->profiler, |
|
106 | + 'profilerLabel' => $this->getProfilerLabel(), |
|
107 | + 'queries' => $this->getQueries(), |
|
108 | + 'queriesLabel' => $this->getQueriesLabel(), |
|
109 | + 'templates' => $this->getTemplates(), |
|
110 | + )); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param int $time |
|
115 | - * @param int $decimals |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function convertToMiliseconds($time, $decimals = 2) |
|
119 | - { |
|
120 | - return number_format($time * 1000, $decimals); |
|
121 | - } |
|
113 | + /** |
|
114 | + * @param int $time |
|
115 | + * @param int $decimals |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function convertToMiliseconds($time, $decimals = 2) |
|
119 | + { |
|
120 | + return number_format($time * 1000, $decimals); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - protected function getConsoleEntries() |
|
127 | - { |
|
128 | - return array_merge($this->getErrors(), $this->app->console->entries); |
|
129 | - } |
|
123 | + /** |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + protected function getConsoleEntries() |
|
127 | + { |
|
128 | + return array_merge($this->getErrors(), $this->app->console->entries); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - protected function getConsoleLabel() |
|
135 | - { |
|
136 | - $class = ''; |
|
137 | - $entries = $this->getConsoleEntries(); |
|
138 | - $entryCount = count($entries); |
|
139 | - $errorCount = 0; |
|
140 | - $label = __('Console', 'blackbar'); |
|
141 | - foreach ($entries as $entry) { |
|
142 | - if (in_array($entry['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
143 | - $class = 'glbb-warning'; |
|
144 | - } |
|
145 | - if (in_array($entry['errno'], [E_WARNING])) { |
|
146 | - ++$errorCount; |
|
147 | - } |
|
148 | - } |
|
149 | - if ($entryCount > 0) { |
|
150 | - $label .= sprintf(' (%d)', $entryCount); |
|
151 | - } |
|
152 | - if ($errorCount > 0) { |
|
153 | - $class = 'glbb-error'; |
|
154 | - $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
155 | - } |
|
156 | - return '<span class="'.$class.'">'.$label.'</span>'; |
|
157 | - } |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + protected function getConsoleLabel() |
|
135 | + { |
|
136 | + $class = ''; |
|
137 | + $entries = $this->getConsoleEntries(); |
|
138 | + $entryCount = count($entries); |
|
139 | + $errorCount = 0; |
|
140 | + $label = __('Console', 'blackbar'); |
|
141 | + foreach ($entries as $entry) { |
|
142 | + if (in_array($entry['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
143 | + $class = 'glbb-warning'; |
|
144 | + } |
|
145 | + if (in_array($entry['errno'], [E_WARNING])) { |
|
146 | + ++$errorCount; |
|
147 | + } |
|
148 | + } |
|
149 | + if ($entryCount > 0) { |
|
150 | + $label .= sprintf(' (%d)', $entryCount); |
|
151 | + } |
|
152 | + if ($errorCount > 0) { |
|
153 | + $class = 'glbb-error'; |
|
154 | + $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
155 | + } |
|
156 | + return '<span class="'.$class.'">'.$label.'</span>'; |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - protected function getErrors() |
|
163 | - { |
|
164 | - $errors = array(); |
|
165 | - foreach ($this->app->errors as $error) { |
|
166 | - $class = 'glbb-info'; |
|
167 | - if (in_array($error['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
168 | - $class = 'glbb-warning'; |
|
169 | - } |
|
170 | - if (E_WARNING == $error['errno']) { |
|
171 | - $class = 'glbb-error'; |
|
172 | - } |
|
173 | - if ($error['count'] > 1) { |
|
174 | - $error['name'] .= ' ('.$error['count'].')'; |
|
175 | - } |
|
176 | - $errors[] = array( |
|
177 | - 'errno' => $error['errno'], |
|
178 | - 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
179 | - 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
180 | - $error['message'], |
|
181 | - $error['line'], |
|
182 | - $error['file'] |
|
183 | - ), |
|
184 | - ); |
|
185 | - } |
|
186 | - return $errors; |
|
187 | - } |
|
159 | + /** |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + protected function getErrors() |
|
163 | + { |
|
164 | + $errors = array(); |
|
165 | + foreach ($this->app->errors as $error) { |
|
166 | + $class = 'glbb-info'; |
|
167 | + if (in_array($error['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
168 | + $class = 'glbb-warning'; |
|
169 | + } |
|
170 | + if (E_WARNING == $error['errno']) { |
|
171 | + $class = 'glbb-error'; |
|
172 | + } |
|
173 | + if ($error['count'] > 1) { |
|
174 | + $error['name'] .= ' ('.$error['count'].')'; |
|
175 | + } |
|
176 | + $errors[] = array( |
|
177 | + 'errno' => $error['errno'], |
|
178 | + 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
179 | + 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
180 | + $error['message'], |
|
181 | + $error['line'], |
|
182 | + $error['file'] |
|
183 | + ), |
|
184 | + ); |
|
185 | + } |
|
186 | + return $errors; |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - protected function getIncludedFiles() |
|
193 | - { |
|
194 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
195 | - $bool = false !== strpos($file, '/themes/') |
|
196 | - && false === strpos($file, '/functions.php'); |
|
197 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
198 | - })); |
|
199 | - return array_map(function ($key, $value) { |
|
200 | - $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
201 | - return sprintf('[%s] => %s', $key, $value); |
|
202 | - }, array_keys($files), $files); |
|
203 | - } |
|
189 | + /** |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + protected function getIncludedFiles() |
|
193 | + { |
|
194 | + $files = array_values(array_filter(get_included_files(), function ($file) { |
|
195 | + $bool = false !== strpos($file, '/themes/') |
|
196 | + && false === strpos($file, '/functions.php'); |
|
197 | + return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
198 | + })); |
|
199 | + return array_map(function ($key, $value) { |
|
200 | + $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
201 | + return sprintf('[%s] => %s', $key, $value); |
|
202 | + }, array_keys($files), $files); |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - protected function getProfilerLabel() |
|
209 | - { |
|
210 | - $label = __('Profiler', 'blackbar'); |
|
211 | - $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
212 | - if ($profilerTime > 0) { |
|
213 | - $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
214 | - } |
|
215 | - return $label; |
|
216 | - } |
|
205 | + /** |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + protected function getProfilerLabel() |
|
209 | + { |
|
210 | + $label = __('Profiler', 'blackbar'); |
|
211 | + $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
212 | + if ($profilerTime > 0) { |
|
213 | + $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
214 | + } |
|
215 | + return $label; |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - protected function getQueries() |
|
222 | - { |
|
223 | - global $wpdb; |
|
224 | - $queries = array(); |
|
225 | - $search = array( |
|
226 | - 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LIMIT', 'ON DUPLICATE KEY UPDATE', |
|
227 | - 'ORDER BY', 'SET', 'WHERE', |
|
228 | - ); |
|
229 | - $replace = array_map(function ($value) { |
|
230 | - return PHP_EOL.$value; |
|
231 | - }, $search); |
|
232 | - foreach ($wpdb->queries as $query) { |
|
233 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
234 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
235 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
236 | - $sql = str_replace($search, $replace, $sql); |
|
237 | - $queries[] = array( |
|
238 | - 'ms' => $miliseconds, |
|
239 | - 'sql' => $sql, |
|
240 | - ); |
|
241 | - } |
|
242 | - return $queries; |
|
243 | - } |
|
218 | + /** |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + protected function getQueries() |
|
222 | + { |
|
223 | + global $wpdb; |
|
224 | + $queries = array(); |
|
225 | + $search = array( |
|
226 | + 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LIMIT', 'ON DUPLICATE KEY UPDATE', |
|
227 | + 'ORDER BY', 'SET', 'WHERE', |
|
228 | + ); |
|
229 | + $replace = array_map(function ($value) { |
|
230 | + return PHP_EOL.$value; |
|
231 | + }, $search); |
|
232 | + foreach ($wpdb->queries as $query) { |
|
233 | + $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
234 | + $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
235 | + $sql = str_replace(PHP_EOL, ' ', $sql); |
|
236 | + $sql = str_replace($search, $replace, $sql); |
|
237 | + $queries[] = array( |
|
238 | + 'ms' => $miliseconds, |
|
239 | + 'sql' => $sql, |
|
240 | + ); |
|
241 | + } |
|
242 | + return $queries; |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - protected function getQueriesLabel() |
|
249 | - { |
|
250 | - $label = __('SQL', 'blackbar'); |
|
251 | - if (!SAVEQUERIES) { |
|
252 | - return $label; |
|
253 | - } |
|
254 | - global $wpdb; |
|
255 | - $queryTime = 0; |
|
256 | - foreach ($wpdb->queries as $query) { |
|
257 | - $queryTime += $query[1]; |
|
258 | - } |
|
259 | - $queriesCount = '<span class="glbb-queries-count">'.count($wpdb->queries).'</span>'; |
|
260 | - $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds($queryTime).'</span>'; |
|
261 | - return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
262 | - } |
|
245 | + /** |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + protected function getQueriesLabel() |
|
249 | + { |
|
250 | + $label = __('SQL', 'blackbar'); |
|
251 | + if (!SAVEQUERIES) { |
|
252 | + return $label; |
|
253 | + } |
|
254 | + global $wpdb; |
|
255 | + $queryTime = 0; |
|
256 | + foreach ($wpdb->queries as $query) { |
|
257 | + $queryTime += $query[1]; |
|
258 | + } |
|
259 | + $queriesCount = '<span class="glbb-queries-count">'.count($wpdb->queries).'</span>'; |
|
260 | + $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds($queryTime).'</span>'; |
|
261 | + return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - protected function getSlowActionsLabel() |
|
268 | - { |
|
269 | - $label = __('Hooks', 'blackbar'); |
|
270 | - $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
271 | - if ($totalTime > 0) { |
|
272 | - $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
273 | - } |
|
274 | - return $label; |
|
275 | - } |
|
264 | + /** |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + protected function getSlowActionsLabel() |
|
268 | + { |
|
269 | + $label = __('Hooks', 'blackbar'); |
|
270 | + $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
271 | + if ($totalTime > 0) { |
|
272 | + $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
273 | + } |
|
274 | + return $label; |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * @return void|string |
|
279 | - */ |
|
280 | - protected function getTemplates() |
|
281 | - { |
|
282 | - if (is_admin()) { |
|
283 | - return; |
|
284 | - } |
|
285 | - if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
286 | - ob_start(); |
|
287 | - \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
|
288 | - return ob_get_clean(); |
|
289 | - } |
|
290 | - return '<pre>'.implode(PHP_EOL, $this->getIncludedFiles()).'</pre>'; |
|
291 | - } |
|
277 | + /** |
|
278 | + * @return void|string |
|
279 | + */ |
|
280 | + protected function getTemplates() |
|
281 | + { |
|
282 | + if (is_admin()) { |
|
283 | + return; |
|
284 | + } |
|
285 | + if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
286 | + ob_start(); |
|
287 | + \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
|
288 | + return ob_get_clean(); |
|
289 | + } |
|
290 | + return '<pre>'.implode(PHP_EOL, $this->getIncludedFiles()).'</pre>'; |
|
291 | + } |
|
292 | 292 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | protected $app; |
11 | 11 | |
12 | - public function __construct(Application $app) |
|
12 | + public function __construct( Application $app ) |
|
13 | 13 | { |
14 | 14 | $this->app = $app; |
15 | 15 | } |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function enqueueAssets() |
23 | 23 | { |
24 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
25 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), array('dashicons')); |
|
26 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
24 | + wp_enqueue_script( Application::ID, $this->app->url( 'assets/main.js' ) ); |
|
25 | + wp_enqueue_style( Application::ID, $this->app->url( 'assets/main.css' ), array( 'dashicons' ) ); |
|
26 | + wp_enqueue_style( Application::ID . '-syntax', $this->app->url( 'assets/syntax.css' ) ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @return string |
32 | 32 | * @action admin_body_class |
33 | 33 | */ |
34 | - public function filterBodyClasses($classes) |
|
34 | + public function filterBodyClasses( $classes ) |
|
35 | 35 | { |
36 | - return trim($classes.' '.Application::ID); |
|
36 | + return trim( $classes . ' ' . Application::ID ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function initConsole() |
44 | 44 | { |
45 | - if (Application::CONSOLE_HOOK != func_get_arg(0)) { |
|
45 | + if( Application::CONSOLE_HOOK != func_get_arg( 0 ) ) { |
|
46 | 46 | return; |
47 | 47 | } |
48 | - $args = array_pad(func_get_args(), 4, ''); |
|
49 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
50 | - $entry = array_pop($backtrace); |
|
51 | - $location = $args[3]; |
|
52 | - if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
53 | - $path = explode(ABSPATH, $entry['file']); |
|
54 | - $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
48 | + $args = array_pad( func_get_args(), 4, '' ); |
|
49 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 4 ); |
|
50 | + $entry = array_pop( $backtrace ); |
|
51 | + $location = $args[ 3 ]; |
|
52 | + if( empty( trim( $location ) ) && array_key_exists( 'file', $entry ) ) { |
|
53 | + $path = explode( ABSPATH, $entry[ 'file' ] ); |
|
54 | + $location = sprintf( '%s:%s', array_pop( $path ), $entry[ 'line' ] ); |
|
55 | 55 | } |
56 | - $this->app->console->store($args[1], $args[2], '['.$location.'] '); |
|
56 | + $this->app->console->store( $args[ 1 ], $args[ 2 ], '[' . $location . '] ' ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function initProfiler() |
64 | 64 | { |
65 | - if (Application::PROFILER_HOOK != func_get_arg(0)) { |
|
65 | + if( Application::PROFILER_HOOK != func_get_arg( 0 ) ) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | - $this->app->profiler->trace(func_get_arg(1)); |
|
68 | + $this->app->profiler->trace( func_get_arg( 1 ) ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function registerLanguages() |
85 | 85 | { |
86 | - load_plugin_textdomain(Application::ID, false, |
|
87 | - plugin_basename($this->app->path()).Application::LANG |
|
86 | + load_plugin_textdomain( Application::ID, false, |
|
87 | + plugin_basename( $this->app->path() ) . Application::LANG |
|
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function renderBar() |
97 | 97 | { |
98 | - apply_filters('debug', 'Profiler Stopped'); |
|
99 | - $this->app->render('debug-bar', array( |
|
98 | + apply_filters( 'debug', 'Profiler Stopped' ); |
|
99 | + $this->app->render( 'debug-bar', array( |
|
100 | 100 | 'blackbar' => $this->app, |
101 | 101 | 'actions' => $this->app->actions, |
102 | 102 | 'actionsLabel' => $this->getSlowActionsLabel(), |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | 'queries' => $this->getQueries(), |
108 | 108 | 'queriesLabel' => $this->getQueriesLabel(), |
109 | 109 | 'templates' => $this->getTemplates(), |
110 | - )); |
|
110 | + ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * @param int $decimals |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - protected function convertToMiliseconds($time, $decimals = 2) |
|
118 | + protected function convertToMiliseconds( $time, $decimals = 2 ) |
|
119 | 119 | { |
120 | - return number_format($time * 1000, $decimals); |
|
120 | + return number_format( $time * 1000, $decimals ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | protected function getConsoleEntries() |
127 | 127 | { |
128 | - return array_merge($this->getErrors(), $this->app->console->entries); |
|
128 | + return array_merge( $this->getErrors(), $this->app->console->entries ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -135,25 +135,25 @@ discard block |
||
135 | 135 | { |
136 | 136 | $class = ''; |
137 | 137 | $entries = $this->getConsoleEntries(); |
138 | - $entryCount = count($entries); |
|
138 | + $entryCount = count( $entries ); |
|
139 | 139 | $errorCount = 0; |
140 | - $label = __('Console', 'blackbar'); |
|
141 | - foreach ($entries as $entry) { |
|
142 | - if (in_array($entry['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
140 | + $label = __( 'Console', 'blackbar' ); |
|
141 | + foreach( $entries as $entry ) { |
|
142 | + if( in_array( $entry[ 'errno' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) { |
|
143 | 143 | $class = 'glbb-warning'; |
144 | 144 | } |
145 | - if (in_array($entry['errno'], [E_WARNING])) { |
|
145 | + if( in_array( $entry[ 'errno' ], [ E_WARNING ] ) ) { |
|
146 | 146 | ++$errorCount; |
147 | 147 | } |
148 | 148 | } |
149 | - if ($entryCount > 0) { |
|
150 | - $label .= sprintf(' (%d)', $entryCount); |
|
149 | + if( $entryCount > 0 ) { |
|
150 | + $label .= sprintf( ' (%d)', $entryCount ); |
|
151 | 151 | } |
152 | - if ($errorCount > 0) { |
|
152 | + if( $errorCount > 0 ) { |
|
153 | 153 | $class = 'glbb-error'; |
154 | - $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
154 | + $label .= sprintf( ' (%d, %d!)', $entryCount, $errorCount ); |
|
155 | 155 | } |
156 | - return '<span class="'.$class.'">'.$label.'</span>'; |
|
156 | + return '<span class="' . $class . '">' . $label . '</span>'; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -162,24 +162,24 @@ discard block |
||
162 | 162 | protected function getErrors() |
163 | 163 | { |
164 | 164 | $errors = array(); |
165 | - foreach ($this->app->errors as $error) { |
|
165 | + foreach( $this->app->errors as $error ) { |
|
166 | 166 | $class = 'glbb-info'; |
167 | - if (in_array($error['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
167 | + if( in_array( $error[ 'errno' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) { |
|
168 | 168 | $class = 'glbb-warning'; |
169 | 169 | } |
170 | - if (E_WARNING == $error['errno']) { |
|
170 | + if( E_WARNING == $error[ 'errno' ] ) { |
|
171 | 171 | $class = 'glbb-error'; |
172 | 172 | } |
173 | - if ($error['count'] > 1) { |
|
174 | - $error['name'] .= ' ('.$error['count'].')'; |
|
173 | + if( $error[ 'count' ] > 1 ) { |
|
174 | + $error[ 'name' ] .= ' (' . $error[ 'count' ] . ')'; |
|
175 | 175 | } |
176 | - $errors[] = array( |
|
177 | - 'errno' => $error['errno'], |
|
178 | - 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
179 | - 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
180 | - $error['message'], |
|
181 | - $error['line'], |
|
182 | - $error['file'] |
|
176 | + $errors[ ] = array( |
|
177 | + 'errno' => $error[ 'errno' ], |
|
178 | + 'name' => '<span class="' . $class . '">' . $error[ 'name' ] . '</span>', |
|
179 | + 'message' => sprintf( __( '%s on line %s in file %s', 'blackbar' ), |
|
180 | + $error[ 'message' ], |
|
181 | + $error[ 'line' ], |
|
182 | + $error[ 'file' ] |
|
183 | 183 | ), |
184 | 184 | ); |
185 | 185 | } |
@@ -191,15 +191,15 @@ discard block |
||
191 | 191 | */ |
192 | 192 | protected function getIncludedFiles() |
193 | 193 | { |
194 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
195 | - $bool = false !== strpos($file, '/themes/') |
|
196 | - && false === strpos($file, '/functions.php'); |
|
197 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
198 | - })); |
|
199 | - return array_map(function ($key, $value) { |
|
200 | - $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
201 | - return sprintf('[%s] => %s', $key, $value); |
|
202 | - }, array_keys($files), $files); |
|
194 | + $files = array_values( array_filter( get_included_files(), function( $file ) { |
|
195 | + $bool = false !== strpos( $file, '/themes/' ) |
|
196 | + && false === strpos( $file, '/functions.php' ); |
|
197 | + return (bool) apply_filters( 'blackbar/templates/file', $bool, $file ); |
|
198 | + }) ); |
|
199 | + return array_map( function( $key, $value ) { |
|
200 | + $value = str_replace( trailingslashit( WP_CONTENT_DIR ), '', $value ); |
|
201 | + return sprintf( '[%s] => %s', $key, $value ); |
|
202 | + }, array_keys( $files ), $files ); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -207,10 +207,10 @@ discard block |
||
207 | 207 | */ |
208 | 208 | protected function getProfilerLabel() |
209 | 209 | { |
210 | - $label = __('Profiler', 'blackbar'); |
|
211 | - $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
212 | - if ($profilerTime > 0) { |
|
213 | - $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
210 | + $label = __( 'Profiler', 'blackbar' ); |
|
211 | + $profilerTime = $this->convertToMiliseconds( $this->app->profiler->getTotalTime(), 0 ); |
|
212 | + if( $profilerTime > 0 ) { |
|
213 | + $label .= sprintf( ' (%s %s)', $profilerTime, __( 'ms', 'blackbar' ) ); |
|
214 | 214 | } |
215 | 215 | return $label; |
216 | 216 | } |
@@ -226,15 +226,15 @@ discard block |
||
226 | 226 | 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LIMIT', 'ON DUPLICATE KEY UPDATE', |
227 | 227 | 'ORDER BY', 'SET', 'WHERE', |
228 | 228 | ); |
229 | - $replace = array_map(function ($value) { |
|
230 | - return PHP_EOL.$value; |
|
231 | - }, $search); |
|
232 | - foreach ($wpdb->queries as $query) { |
|
233 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
234 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
235 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
236 | - $sql = str_replace($search, $replace, $sql); |
|
237 | - $queries[] = array( |
|
229 | + $replace = array_map( function( $value ) { |
|
230 | + return PHP_EOL . $value; |
|
231 | + }, $search ); |
|
232 | + foreach( $wpdb->queries as $query ) { |
|
233 | + $miliseconds = number_format( round( $query[ 1 ] * 1000, 4 ), 4 ); |
|
234 | + $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) ); |
|
235 | + $sql = str_replace( PHP_EOL, ' ', $sql ); |
|
236 | + $sql = str_replace( $search, $replace, $sql ); |
|
237 | + $queries[ ] = array( |
|
238 | 238 | 'ms' => $miliseconds, |
239 | 239 | 'sql' => $sql, |
240 | 240 | ); |
@@ -247,18 +247,18 @@ discard block |
||
247 | 247 | */ |
248 | 248 | protected function getQueriesLabel() |
249 | 249 | { |
250 | - $label = __('SQL', 'blackbar'); |
|
251 | - if (!SAVEQUERIES) { |
|
250 | + $label = __( 'SQL', 'blackbar' ); |
|
251 | + if( !SAVEQUERIES ) { |
|
252 | 252 | return $label; |
253 | 253 | } |
254 | 254 | global $wpdb; |
255 | 255 | $queryTime = 0; |
256 | - foreach ($wpdb->queries as $query) { |
|
257 | - $queryTime += $query[1]; |
|
256 | + foreach( $wpdb->queries as $query ) { |
|
257 | + $queryTime += $query[ 1 ]; |
|
258 | 258 | } |
259 | - $queriesCount = '<span class="glbb-queries-count">'.count($wpdb->queries).'</span>'; |
|
260 | - $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds($queryTime).'</span>'; |
|
261 | - return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
259 | + $queriesCount = '<span class="glbb-queries-count">' . count( $wpdb->queries ) . '</span>'; |
|
260 | + $queriesTime = '<span class="glbb-queries-time">' . $this->convertToMiliseconds( $queryTime ) . '</span>'; |
|
261 | + return $label . sprintf( ' (%s %s | %s %s)', $queriesCount, __( 'queries', 'blackbar' ), $queriesTime, __( 'ms', 'blackbar' ) ); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | */ |
267 | 267 | protected function getSlowActionsLabel() |
268 | 268 | { |
269 | - $label = __('Hooks', 'blackbar'); |
|
270 | - $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
271 | - if ($totalTime > 0) { |
|
272 | - $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
269 | + $label = __( 'Hooks', 'blackbar' ); |
|
270 | + $totalTime = $this->convertToMiliseconds( $this->app->actions->getTotalTime(), 0 ); |
|
271 | + if( $totalTime > 0 ) { |
|
272 | + $label .= sprintf( ' (%s %s)', $totalTime, __( 'ms', 'blackbar' ) ); |
|
273 | 273 | } |
274 | 274 | return $label; |
275 | 275 | } |
@@ -279,14 +279,14 @@ discard block |
||
279 | 279 | */ |
280 | 280 | protected function getTemplates() |
281 | 281 | { |
282 | - if (is_admin()) { |
|
282 | + if( is_admin() ) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | - if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
285 | + if( class_exists( '\GeminiLabs\Castor\Facades\Development' ) ) { |
|
286 | 286 | ob_start(); |
287 | 287 | \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
288 | 288 | return ob_get_clean(); |
289 | 289 | } |
290 | - return '<pre>'.implode(PHP_EOL, $this->getIncludedFiles()).'</pre>'; |
|
290 | + return '<pre>' . implode( PHP_EOL, $this->getIncludedFiles() ) . '</pre>'; |
|
291 | 291 | } |
292 | 292 | } |
@@ -191,12 +191,14 @@ discard block |
||
191 | 191 | */ |
192 | 192 | protected function getIncludedFiles() |
193 | 193 | { |
194 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
194 | + $files = array_values(array_filter(get_included_files(), function ($file) |
|
195 | + { |
|
195 | 196 | $bool = false !== strpos($file, '/themes/') |
196 | 197 | && false === strpos($file, '/functions.php'); |
197 | 198 | return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
198 | 199 | })); |
199 | - return array_map(function ($key, $value) { |
|
200 | + return array_map(function ($key, $value) |
|
201 | + { |
|
200 | 202 | $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
201 | 203 | return sprintf('[%s] => %s', $key, $value); |
202 | 204 | }, array_keys($files), $files); |
@@ -226,7 +228,8 @@ discard block |
||
226 | 228 | 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LIMIT', 'ON DUPLICATE KEY UPDATE', |
227 | 229 | 'ORDER BY', 'SET', 'WHERE', |
228 | 230 | ); |
229 | - $replace = array_map(function ($value) { |
|
231 | + $replace = array_map(function ($value) |
|
232 | + { |
|
230 | 233 | return PHP_EOL.$value; |
231 | 234 | }, $search); |
232 | 235 | foreach ($wpdb->queries as $query) { |
@@ -4,161 +4,161 @@ |
||
4 | 4 | |
5 | 5 | class SlowActions |
6 | 6 | { |
7 | - /** |
|
8 | - * @var array |
|
9 | - */ |
|
10 | - protected $flow; |
|
11 | - |
|
12 | - /** |
|
13 | - * This is the time that WordPress takes to execute the all hook. |
|
14 | - * @var int |
|
15 | - */ |
|
16 | - protected $noise = 0; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var int |
|
20 | - */ |
|
21 | - protected $start = null; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var int |
|
25 | - */ |
|
26 | - protected $stop = null; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var int |
|
30 | - */ |
|
31 | - protected $totalActions = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var int |
|
35 | - */ |
|
36 | - protected $totalTime = 0; |
|
37 | - |
|
38 | - public function __construct() |
|
39 | - { |
|
40 | - $this->flow = []; |
|
41 | - $this->start = microtime(true); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function getTotalTimeForHook(array $data) |
|
48 | - { |
|
49 | - $total = 0; |
|
50 | - foreach ($data['time'] as $time) { |
|
51 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
52 | - } |
|
53 | - return $total; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function addCallbacksForAction($action) |
|
60 | - { |
|
61 | - global $wp_filter; |
|
62 | - if (!array_key_exists($action, $this->flow)) { |
|
63 | - return; |
|
64 | - } |
|
65 | - $this->flow[$action]['callbacks_count'] = 0; |
|
66 | - foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
67 | - if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) { |
|
68 | - $this->flow[$action]['callbacks'][$priority] = []; |
|
69 | - } |
|
70 | - foreach ($callbacks as $callback) { |
|
71 | - if (is_array($callback['function']) && 2 == count($callback['function'])) { |
|
72 | - list($object, $method) = $callback['function']; |
|
73 | - if (is_object($object)) { |
|
74 | - $object = get_class($object); |
|
75 | - } |
|
76 | - $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
77 | - } elseif (is_object($callback['function'])) { |
|
78 | - $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
79 | - } else { |
|
80 | - $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
|
81 | - } |
|
82 | - ++$this->flow[$action]['callbacks_count']; |
|
83 | - } |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public function getMeasure() |
|
91 | - { |
|
92 | - foreach ($this->flow as $action => $data) { |
|
93 | - $total = $this->getTotalTimeForHook($data); |
|
94 | - $this->flow[$action]['total'] = $total; |
|
95 | - $this->totalTime += $total; |
|
96 | - $this->totalActions += $data['count']; |
|
97 | - $this->addCallbacksForAction($action); |
|
98 | - } |
|
99 | - uasort($this->flow, [$this, 'sortByTime']); |
|
100 | - return $this->flow; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public function getTotalActions() |
|
107 | - { |
|
108 | - return $this->totalActions; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return int Microseconds |
|
113 | - */ |
|
114 | - public function getTotalTime() |
|
115 | - { |
|
116 | - return $this->totalTime; |
|
117 | - // $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
118 | - // return $this->stop - $this->start - $totalNoise; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $name |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function startTimer() |
|
126 | - { |
|
127 | - if (!isset($this->flow[current_filter()])) { |
|
128 | - $this->flow[current_filter()] = [ |
|
129 | - 'callbacks' => [], |
|
130 | - 'count' => 0, |
|
131 | - 'stack' => [], |
|
132 | - 'time' => [], |
|
133 | - ]; |
|
134 | - add_action(current_filter(), [$this, 'stopTimer'], 9000); |
|
135 | - } |
|
136 | - $count = ++$this->flow[current_filter()]['count']; |
|
137 | - array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param mixed $possibleFilter |
|
142 | - * @return mixed |
|
143 | - */ |
|
144 | - public function stopTimer($possibleFilter = null) |
|
145 | - { |
|
146 | - $time = array_pop($this->flow[current_filter()]['stack']); |
|
147 | - $time['stop'] = microtime(true); |
|
148 | - array_push($this->flow[current_filter()]['time'], $time); |
|
149 | - return $possibleFilter; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param array $a |
|
154 | - * @param array $b |
|
155 | - * @return int |
|
156 | - */ |
|
157 | - protected function sortByTime($a, $b) |
|
158 | - { |
|
159 | - if ($a['total'] == $b['total']) { |
|
160 | - return 0; |
|
161 | - } |
|
162 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
163 | - } |
|
7 | + /** |
|
8 | + * @var array |
|
9 | + */ |
|
10 | + protected $flow; |
|
11 | + |
|
12 | + /** |
|
13 | + * This is the time that WordPress takes to execute the all hook. |
|
14 | + * @var int |
|
15 | + */ |
|
16 | + protected $noise = 0; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var int |
|
20 | + */ |
|
21 | + protected $start = null; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var int |
|
25 | + */ |
|
26 | + protected $stop = null; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var int |
|
30 | + */ |
|
31 | + protected $totalActions = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var int |
|
35 | + */ |
|
36 | + protected $totalTime = 0; |
|
37 | + |
|
38 | + public function __construct() |
|
39 | + { |
|
40 | + $this->flow = []; |
|
41 | + $this->start = microtime(true); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function getTotalTimeForHook(array $data) |
|
48 | + { |
|
49 | + $total = 0; |
|
50 | + foreach ($data['time'] as $time) { |
|
51 | + $total += ($time['stop'] - $time['start']) * 1000; |
|
52 | + } |
|
53 | + return $total; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function addCallbacksForAction($action) |
|
60 | + { |
|
61 | + global $wp_filter; |
|
62 | + if (!array_key_exists($action, $this->flow)) { |
|
63 | + return; |
|
64 | + } |
|
65 | + $this->flow[$action]['callbacks_count'] = 0; |
|
66 | + foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
67 | + if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) { |
|
68 | + $this->flow[$action]['callbacks'][$priority] = []; |
|
69 | + } |
|
70 | + foreach ($callbacks as $callback) { |
|
71 | + if (is_array($callback['function']) && 2 == count($callback['function'])) { |
|
72 | + list($object, $method) = $callback['function']; |
|
73 | + if (is_object($object)) { |
|
74 | + $object = get_class($object); |
|
75 | + } |
|
76 | + $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
77 | + } elseif (is_object($callback['function'])) { |
|
78 | + $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
79 | + } else { |
|
80 | + $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
|
81 | + } |
|
82 | + ++$this->flow[$action]['callbacks_count']; |
|
83 | + } |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public function getMeasure() |
|
91 | + { |
|
92 | + foreach ($this->flow as $action => $data) { |
|
93 | + $total = $this->getTotalTimeForHook($data); |
|
94 | + $this->flow[$action]['total'] = $total; |
|
95 | + $this->totalTime += $total; |
|
96 | + $this->totalActions += $data['count']; |
|
97 | + $this->addCallbacksForAction($action); |
|
98 | + } |
|
99 | + uasort($this->flow, [$this, 'sortByTime']); |
|
100 | + return $this->flow; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public function getTotalActions() |
|
107 | + { |
|
108 | + return $this->totalActions; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return int Microseconds |
|
113 | + */ |
|
114 | + public function getTotalTime() |
|
115 | + { |
|
116 | + return $this->totalTime; |
|
117 | + // $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
118 | + // return $this->stop - $this->start - $totalNoise; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $name |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function startTimer() |
|
126 | + { |
|
127 | + if (!isset($this->flow[current_filter()])) { |
|
128 | + $this->flow[current_filter()] = [ |
|
129 | + 'callbacks' => [], |
|
130 | + 'count' => 0, |
|
131 | + 'stack' => [], |
|
132 | + 'time' => [], |
|
133 | + ]; |
|
134 | + add_action(current_filter(), [$this, 'stopTimer'], 9000); |
|
135 | + } |
|
136 | + $count = ++$this->flow[current_filter()]['count']; |
|
137 | + array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param mixed $possibleFilter |
|
142 | + * @return mixed |
|
143 | + */ |
|
144 | + public function stopTimer($possibleFilter = null) |
|
145 | + { |
|
146 | + $time = array_pop($this->flow[current_filter()]['stack']); |
|
147 | + $time['stop'] = microtime(true); |
|
148 | + array_push($this->flow[current_filter()]['time'], $time); |
|
149 | + return $possibleFilter; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param array $a |
|
154 | + * @param array $b |
|
155 | + * @return int |
|
156 | + */ |
|
157 | + protected function sortByTime($a, $b) |
|
158 | + { |
|
159 | + if ($a['total'] == $b['total']) { |
|
160 | + return 0; |
|
161 | + } |
|
162 | + return ($a['total'] > $b['total']) ? -1 : 1; |
|
163 | + } |
|
164 | 164 | } |
@@ -37,18 +37,18 @@ discard block |
||
37 | 37 | |
38 | 38 | public function __construct() |
39 | 39 | { |
40 | - $this->flow = []; |
|
41 | - $this->start = microtime(true); |
|
40 | + $this->flow = [ ]; |
|
41 | + $this->start = microtime( true ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @return array |
46 | 46 | */ |
47 | - public function getTotalTimeForHook(array $data) |
|
47 | + public function getTotalTimeForHook( array $data ) |
|
48 | 48 | { |
49 | 49 | $total = 0; |
50 | - foreach ($data['time'] as $time) { |
|
51 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
50 | + foreach( $data[ 'time' ] as $time ) { |
|
51 | + $total += ( $time[ 'stop' ] - $time[ 'start' ] ) * 1000; |
|
52 | 52 | } |
53 | 53 | return $total; |
54 | 54 | } |
@@ -56,30 +56,30 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * @return array |
58 | 58 | */ |
59 | - public function addCallbacksForAction($action) |
|
59 | + public function addCallbacksForAction( $action ) |
|
60 | 60 | { |
61 | 61 | global $wp_filter; |
62 | - if (!array_key_exists($action, $this->flow)) { |
|
62 | + if( !array_key_exists( $action, $this->flow ) ) { |
|
63 | 63 | return; |
64 | 64 | } |
65 | - $this->flow[$action]['callbacks_count'] = 0; |
|
66 | - foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
67 | - if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) { |
|
68 | - $this->flow[$action]['callbacks'][$priority] = []; |
|
65 | + $this->flow[ $action ][ 'callbacks_count' ] = 0; |
|
66 | + foreach( $wp_filter[ $action ] as $priority => $callbacks ) { |
|
67 | + if( !array_key_exists( $priority, $this->flow[ $action ][ 'callbacks' ] ) ) { |
|
68 | + $this->flow[ $action ][ 'callbacks' ][ $priority ] = [ ]; |
|
69 | 69 | } |
70 | - foreach ($callbacks as $callback) { |
|
71 | - if (is_array($callback['function']) && 2 == count($callback['function'])) { |
|
72 | - list($object, $method) = $callback['function']; |
|
73 | - if (is_object($object)) { |
|
74 | - $object = get_class($object); |
|
70 | + foreach( $callbacks as $callback ) { |
|
71 | + if( is_array( $callback[ 'function' ] ) && 2 == count( $callback[ 'function' ] ) ) { |
|
72 | + list( $object, $method ) = $callback[ 'function' ]; |
|
73 | + if( is_object( $object ) ) { |
|
74 | + $object = get_class( $object ); |
|
75 | 75 | } |
76 | - $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
77 | - } elseif (is_object($callback['function'])) { |
|
78 | - $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
76 | + $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = sprintf( '%s::%s', $object, $method ); |
|
77 | + } elseif( is_object( $callback[ 'function' ] ) ) { |
|
78 | + $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = get_class( $callback[ 'function' ] ); |
|
79 | 79 | } else { |
80 | - $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
|
80 | + $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = $callback[ 'function' ]; |
|
81 | 81 | } |
82 | - ++$this->flow[$action]['callbacks_count']; |
|
82 | + ++$this->flow[ $action ][ 'callbacks_count' ]; |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function getMeasure() |
91 | 91 | { |
92 | - foreach ($this->flow as $action => $data) { |
|
93 | - $total = $this->getTotalTimeForHook($data); |
|
94 | - $this->flow[$action]['total'] = $total; |
|
92 | + foreach( $this->flow as $action => $data ) { |
|
93 | + $total = $this->getTotalTimeForHook( $data ); |
|
94 | + $this->flow[ $action ][ 'total' ] = $total; |
|
95 | 95 | $this->totalTime += $total; |
96 | - $this->totalActions += $data['count']; |
|
97 | - $this->addCallbacksForAction($action); |
|
96 | + $this->totalActions += $data[ 'count' ]; |
|
97 | + $this->addCallbacksForAction( $action ); |
|
98 | 98 | } |
99 | - uasort($this->flow, [$this, 'sortByTime']); |
|
99 | + uasort( $this->flow, [ $this, 'sortByTime' ] ); |
|
100 | 100 | return $this->flow; |
101 | 101 | } |
102 | 102 | |
@@ -124,28 +124,28 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function startTimer() |
126 | 126 | { |
127 | - if (!isset($this->flow[current_filter()])) { |
|
128 | - $this->flow[current_filter()] = [ |
|
129 | - 'callbacks' => [], |
|
127 | + if( !isset( $this->flow[ current_filter() ] ) ) { |
|
128 | + $this->flow[ current_filter() ] = [ |
|
129 | + 'callbacks' => [ ], |
|
130 | 130 | 'count' => 0, |
131 | - 'stack' => [], |
|
132 | - 'time' => [], |
|
131 | + 'stack' => [ ], |
|
132 | + 'time' => [ ], |
|
133 | 133 | ]; |
134 | - add_action(current_filter(), [$this, 'stopTimer'], 9000); |
|
134 | + add_action( current_filter(), [ $this, 'stopTimer' ], 9000 ); |
|
135 | 135 | } |
136 | - $count = ++$this->flow[current_filter()]['count']; |
|
137 | - array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]); |
|
136 | + $count = ++$this->flow[ current_filter() ][ 'count' ]; |
|
137 | + array_push( $this->flow[ current_filter() ][ 'stack' ], [ 'start' => microtime( true ) ] ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * @param mixed $possibleFilter |
142 | 142 | * @return mixed |
143 | 143 | */ |
144 | - public function stopTimer($possibleFilter = null) |
|
144 | + public function stopTimer( $possibleFilter = null ) |
|
145 | 145 | { |
146 | - $time = array_pop($this->flow[current_filter()]['stack']); |
|
147 | - $time['stop'] = microtime(true); |
|
148 | - array_push($this->flow[current_filter()]['time'], $time); |
|
146 | + $time = array_pop( $this->flow[ current_filter() ][ 'stack' ] ); |
|
147 | + $time[ 'stop' ] = microtime( true ); |
|
148 | + array_push( $this->flow[ current_filter() ][ 'time' ], $time ); |
|
149 | 149 | return $possibleFilter; |
150 | 150 | } |
151 | 151 | |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @param array $b |
155 | 155 | * @return int |
156 | 156 | */ |
157 | - protected function sortByTime($a, $b) |
|
157 | + protected function sortByTime( $a, $b ) |
|
158 | 158 | { |
159 | - if ($a['total'] == $b['total']) { |
|
159 | + if( $a[ 'total' ] == $b[ 'total' ] ) { |
|
160 | 160 | return 0; |
161 | 161 | } |
162 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
162 | + return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1; |
|
163 | 163 | } |
164 | 164 | } |
@@ -74,9 +74,11 @@ |
||
74 | 74 | $object = get_class($object); |
75 | 75 | } |
76 | 76 | $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
77 | - } elseif (is_object($callback['function'])) { |
|
77 | + } |
|
78 | + elseif (is_object($callback['function'])) { |
|
78 | 79 | $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
79 | - } else { |
|
80 | + } |
|
81 | + else { |
|
80 | 82 | $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
81 | 83 | } |
82 | 84 | ++$this->flow[$action]['callbacks_count']; |
@@ -6,70 +6,70 @@ |
||
6 | 6 | |
7 | 7 | class Console |
8 | 8 | { |
9 | - const ERROR_CODES = array( |
|
10 | - E_ERROR => 'Error', // 1 |
|
11 | - E_WARNING => 'Warning', // 2 |
|
12 | - E_NOTICE => 'Notice', // 8 |
|
13 | - E_STRICT => 'Strict', // 2048 |
|
14 | - E_DEPRECATED => 'Deprecated', // 8192 |
|
15 | - ); |
|
9 | + const ERROR_CODES = array( |
|
10 | + E_ERROR => 'Error', // 1 |
|
11 | + E_WARNING => 'Warning', // 2 |
|
12 | + E_NOTICE => 'Notice', // 8 |
|
13 | + E_STRICT => 'Strict', // 2048 |
|
14 | + E_DEPRECATED => 'Deprecated', // 8192 |
|
15 | + ); |
|
16 | 16 | |
17 | - const MAPPED_ERROR_CODES = array( |
|
18 | - 'debug' => 0, |
|
19 | - 'info' => 0, |
|
20 | - 'notice' => 0, |
|
21 | - 'warning' => E_NOTICE, // 8 |
|
22 | - 'error' => E_WARNING, // 2 |
|
23 | - 'critical' => E_WARNING, // 2 |
|
24 | - 'alert' => E_WARNING, // 2 |
|
25 | - 'emergency' => E_WARNING, // 2 |
|
26 | - ); |
|
17 | + const MAPPED_ERROR_CODES = array( |
|
18 | + 'debug' => 0, |
|
19 | + 'info' => 0, |
|
20 | + 'notice' => 0, |
|
21 | + 'warning' => E_NOTICE, // 8 |
|
22 | + 'error' => E_WARNING, // 2 |
|
23 | + 'critical' => E_WARNING, // 2 |
|
24 | + 'alert' => E_WARNING, // 2 |
|
25 | + 'emergency' => E_WARNING, // 2 |
|
26 | + ); |
|
27 | 27 | |
28 | - public $entries = array(); |
|
28 | + public $entries = array(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param string $message |
|
32 | - * @return static |
|
33 | - */ |
|
34 | - public function store($message, $errno = 0, $location = '') |
|
35 | - { |
|
36 | - $errname = 'Debug'; |
|
37 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
38 | - $errname = ucfirst($errno); |
|
39 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | - $errname = static::ERROR_CODES[$errno]; |
|
42 | - } |
|
43 | - $this->entries[] = array( |
|
44 | - 'errno' => $errno, |
|
45 | - 'message' => $location.$this->normalizeValue($message), |
|
46 | - 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
47 | - ); |
|
48 | - return $this; |
|
49 | - } |
|
30 | + /** |
|
31 | + * @param string $message |
|
32 | + * @return static |
|
33 | + */ |
|
34 | + public function store($message, $errno = 0, $location = '') |
|
35 | + { |
|
36 | + $errname = 'Debug'; |
|
37 | + if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
38 | + $errname = ucfirst($errno); |
|
39 | + $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
40 | + } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | + $errname = static::ERROR_CODES[$errno]; |
|
42 | + } |
|
43 | + $this->entries[] = array( |
|
44 | + 'errno' => $errno, |
|
45 | + 'message' => $location.$this->normalizeValue($message), |
|
46 | + 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
47 | + ); |
|
48 | + return $this; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param mixed $value |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - protected function isObjectOrArray($value) |
|
56 | - { |
|
57 | - return is_object($value) || is_array($value); |
|
58 | - } |
|
51 | + /** |
|
52 | + * @param mixed $value |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + protected function isObjectOrArray($value) |
|
56 | + { |
|
57 | + return is_object($value) || is_array($value); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param mixed $value |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function normalizeValue($value) |
|
65 | - { |
|
66 | - if ($value instanceof DateTime) { |
|
67 | - $value = $value->format('Y-m-d H:i:s'); |
|
68 | - } elseif ($this->isObjectOrArray($value)) { |
|
69 | - $value = print_r(json_decode(json_encode($value)), true); |
|
70 | - } elseif (is_resource($value)) { |
|
71 | - $value = (string) $value; |
|
72 | - } |
|
73 | - return esc_html($value); |
|
74 | - } |
|
60 | + /** |
|
61 | + * @param mixed $value |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function normalizeValue($value) |
|
65 | + { |
|
66 | + if ($value instanceof DateTime) { |
|
67 | + $value = $value->format('Y-m-d H:i:s'); |
|
68 | + } elseif ($this->isObjectOrArray($value)) { |
|
69 | + $value = print_r(json_decode(json_encode($value)), true); |
|
70 | + } elseif (is_resource($value)) { |
|
71 | + $value = (string) $value; |
|
72 | + } |
|
73 | + return esc_html($value); |
|
74 | + } |
|
75 | 75 | } |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | * @param string $message |
32 | 32 | * @return static |
33 | 33 | */ |
34 | - public function store($message, $errno = 0, $location = '') |
|
34 | + public function store( $message, $errno = 0, $location = '' ) |
|
35 | 35 | { |
36 | 36 | $errname = 'Debug'; |
37 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
38 | - $errname = ucfirst($errno); |
|
39 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | - $errname = static::ERROR_CODES[$errno]; |
|
37 | + if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { |
|
38 | + $errname = ucfirst( $errno ); |
|
39 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; |
|
40 | + } elseif( array_key_exists( $errno, static::ERROR_CODES ) ) { |
|
41 | + $errname = static::ERROR_CODES[ $errno ]; |
|
42 | 42 | } |
43 | - $this->entries[] = array( |
|
43 | + $this->entries[ ] = array( |
|
44 | 44 | 'errno' => $errno, |
45 | - 'message' => $location.$this->normalizeValue($message), |
|
46 | - 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
45 | + 'message' => $location . $this->normalizeValue( $message ), |
|
46 | + 'name' => sprintf( '<span class="glbb-info glbb-%s">%s</span>', strtolower( $errname ), $errname ), |
|
47 | 47 | ); |
48 | 48 | return $this; |
49 | 49 | } |
@@ -52,24 +52,24 @@ discard block |
||
52 | 52 | * @param mixed $value |
53 | 53 | * @return bool |
54 | 54 | */ |
55 | - protected function isObjectOrArray($value) |
|
55 | + protected function isObjectOrArray( $value ) |
|
56 | 56 | { |
57 | - return is_object($value) || is_array($value); |
|
57 | + return is_object( $value ) || is_array( $value ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @param mixed $value |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - protected function normalizeValue($value) |
|
64 | + protected function normalizeValue( $value ) |
|
65 | 65 | { |
66 | - if ($value instanceof DateTime) { |
|
67 | - $value = $value->format('Y-m-d H:i:s'); |
|
68 | - } elseif ($this->isObjectOrArray($value)) { |
|
69 | - $value = print_r(json_decode(json_encode($value)), true); |
|
70 | - } elseif (is_resource($value)) { |
|
66 | + if( $value instanceof DateTime ) { |
|
67 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
68 | + } elseif( $this->isObjectOrArray( $value ) ) { |
|
69 | + $value = print_r( json_decode( json_encode( $value ) ), true ); |
|
70 | + } elseif( is_resource( $value ) ) { |
|
71 | 71 | $value = (string) $value; |
72 | 72 | } |
73 | - return esc_html($value); |
|
73 | + return esc_html( $value ); |
|
74 | 74 | } |
75 | 75 | } |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
38 | 38 | $errname = ucfirst($errno); |
39 | 39 | $errno = static::MAPPED_ERROR_CODES[$errno]; |
40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
40 | + } |
|
41 | + elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
41 | 42 | $errname = static::ERROR_CODES[$errno]; |
42 | 43 | } |
43 | 44 | $this->entries[] = array( |
@@ -65,9 +66,11 @@ discard block |
||
65 | 66 | { |
66 | 67 | if ($value instanceof DateTime) { |
67 | 68 | $value = $value->format('Y-m-d H:i:s'); |
68 | - } elseif ($this->isObjectOrArray($value)) { |
|
69 | + } |
|
70 | + elseif ($this->isObjectOrArray($value)) { |
|
69 | 71 | $value = print_r(json_decode(json_encode($value)), true); |
70 | - } elseif (is_resource($value)) { |
|
72 | + } |
|
73 | + elseif (is_resource($value)) { |
|
71 | 74 | $value = (string) $value; |
72 | 75 | } |
73 | 76 | return esc_html($value); |
@@ -18,15 +18,15 @@ |
||
18 | 18 | defined('WPINC') || die; |
19 | 19 | |
20 | 20 | if (!class_exists('GL_Plugin_Check_v3')) { |
21 | - require_once __DIR__.'/activate.php'; |
|
21 | + require_once __DIR__.'/activate.php'; |
|
22 | 22 | } |
23 | 23 | if (!(new GL_Plugin_Check_v3(__FILE__, array('php' => '5.6', 'wordpress' => '5.2.0')))->canProceed()) { |
24 | - return; |
|
24 | + return; |
|
25 | 25 | } |
26 | 26 | require_once __DIR__.'/autoload.php'; |
27 | 27 | require_once __DIR__.'/compatibility.php'; |
28 | 28 | |
29 | 29 | if (!defined('SAVEQUERIES')) { |
30 | - define('SAVEQUERIES', 1); |
|
30 | + define('SAVEQUERIES', 1); |
|
31 | 31 | } |
32 | 32 | (new GeminiLabs\BlackBar\Application())->init(); |
@@ -15,18 +15,18 @@ |
||
15 | 15 | * Text Domain: blackbar |
16 | 16 | * Domain Path: languages |
17 | 17 | */ |
18 | -defined('WPINC') || die; |
|
18 | +defined( 'WPINC' ) || die; |
|
19 | 19 | |
20 | -if (!class_exists('GL_Plugin_Check_v3')) { |
|
21 | - require_once __DIR__.'/activate.php'; |
|
20 | +if( !class_exists( 'GL_Plugin_Check_v3' ) ) { |
|
21 | + require_once __DIR__ . '/activate.php'; |
|
22 | 22 | } |
23 | -if (!(new GL_Plugin_Check_v3(__FILE__, array('php' => '5.6', 'wordpress' => '5.2.0')))->canProceed()) { |
|
23 | +if( !( new GL_Plugin_Check_v3( __FILE__, array( 'php' => '5.6', 'wordpress' => '5.2.0' ) ) )->canProceed() ) { |
|
24 | 24 | return; |
25 | 25 | } |
26 | -require_once __DIR__.'/autoload.php'; |
|
27 | -require_once __DIR__.'/compatibility.php'; |
|
26 | +require_once __DIR__ . '/autoload.php'; |
|
27 | +require_once __DIR__ . '/compatibility.php'; |
|
28 | 28 | |
29 | -if (!defined('SAVEQUERIES')) { |
|
30 | - define('SAVEQUERIES', 1); |
|
29 | +if( !defined( 'SAVEQUERIES' ) ) { |
|
30 | + define( 'SAVEQUERIES', 1 ); |
|
31 | 31 | } |
32 | -(new GeminiLabs\BlackBar\Application())->init(); |
|
32 | +( new GeminiLabs\BlackBar\Application() )->init(); |
@@ -8,137 +8,137 @@ |
||
8 | 8 | */ |
9 | 9 | class GL_Plugin_Check_v3 |
10 | 10 | { |
11 | - const MIN_PHP_VERSION = '5.6.0'; |
|
12 | - const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
11 | + const MIN_PHP_VERSION = '5.6.0'; |
|
12 | + const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $file; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $file; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $versions; |
|
19 | + /** |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $versions; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param string $file |
|
26 | - */ |
|
27 | - public function __construct($file, array $versions = array()) |
|
28 | - { |
|
29 | - $this->file = realpath($file); |
|
30 | - $this->versions = wp_parse_args($versions, array( |
|
31 | - 'php' => static::MIN_PHP_VERSION, |
|
32 | - 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
33 | - )); |
|
34 | - } |
|
24 | + /** |
|
25 | + * @param string $file |
|
26 | + */ |
|
27 | + public function __construct($file, array $versions = array()) |
|
28 | + { |
|
29 | + $this->file = realpath($file); |
|
30 | + $this->versions = wp_parse_args($versions, array( |
|
31 | + 'php' => static::MIN_PHP_VERSION, |
|
32 | + 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
33 | + )); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function canProceed() |
|
40 | - { |
|
41 | - if ($this->isValid()) { |
|
42 | - return true; |
|
43 | - } |
|
44 | - add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | - add_action('admin_notices', array($this, 'deactivate')); |
|
46 | - return false; |
|
47 | - } |
|
36 | + /** |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function canProceed() |
|
40 | + { |
|
41 | + if ($this->isValid()) { |
|
42 | + return true; |
|
43 | + } |
|
44 | + add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | + add_action('admin_notices', array($this, 'deactivate')); |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public function isPhpValid() |
|
53 | - { |
|
54 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public function isPhpValid() |
|
53 | + { |
|
54 | + return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function isValid() |
|
61 | - { |
|
62 | - return $this->isPhpValid() && $this->isWpValid(); |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function isValid() |
|
61 | + { |
|
62 | + return $this->isPhpValid() && $this->isWpValid(); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function isWpValid() |
|
69 | - { |
|
70 | - global $wp_version; |
|
71 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
72 | - } |
|
65 | + /** |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function isWpValid() |
|
69 | + { |
|
70 | + global $wp_version; |
|
71 | + return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $plugin |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function deactivate($plugin) |
|
79 | - { |
|
80 | - if ($this->isValid()) { |
|
81 | - return; |
|
82 | - } |
|
83 | - $pluginSlug = plugin_basename($this->file); |
|
84 | - if ($plugin == $pluginSlug) { |
|
85 | - $this->redirect(); //exit |
|
86 | - } |
|
87 | - $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | - deactivate_plugins($pluginSlug); |
|
89 | - $this->printNotice($pluginData['name']); |
|
90 | - } |
|
74 | + /** |
|
75 | + * @param string $plugin |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function deactivate($plugin) |
|
79 | + { |
|
80 | + if ($this->isValid()) { |
|
81 | + return; |
|
82 | + } |
|
83 | + $pluginSlug = plugin_basename($this->file); |
|
84 | + if ($plugin == $pluginSlug) { |
|
85 | + $this->redirect(); //exit |
|
86 | + } |
|
87 | + $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | + deactivate_plugins($pluginSlug); |
|
89 | + $this->printNotice($pluginData['name']); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getMessages() |
|
96 | - { |
|
97 | - return array( |
|
98 | - __('The %s plugin was deactivated.', 'blackbar'), |
|
99 | - __('This plugin requires %s or greater in order to work properly.', 'blackbar'), |
|
100 | - __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'blackbar'), |
|
101 | - __('PHP version', 'blackbar'), |
|
102 | - __('WordPress version', 'blackbar'), |
|
103 | - __('Update WordPress', 'blackbar'), |
|
104 | - __('You can use the %s plugin to restore %s to the previous version.', 'blackbar'), |
|
105 | - ); |
|
106 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getMessages() |
|
96 | + { |
|
97 | + return array( |
|
98 | + __('The %s plugin was deactivated.', 'blackbar'), |
|
99 | + __('This plugin requires %s or greater in order to work properly.', 'blackbar'), |
|
100 | + __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'blackbar'), |
|
101 | + __('PHP version', 'blackbar'), |
|
102 | + __('WordPress version', 'blackbar'), |
|
103 | + __('Update WordPress', 'blackbar'), |
|
104 | + __('You can use the %s plugin to restore %s to the previous version.', 'blackbar'), |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @param string $pluginName |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - protected function printNotice($pluginName) |
|
113 | - { |
|
114 | - $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
115 | - $messages = $this->getMessages(); |
|
116 | - $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | - if (!$this->isPhpValid()) { |
|
118 | - printf($noticeTemplate, |
|
119 | - sprintf($messages[0], $pluginName), |
|
120 | - sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | - sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
122 | - ); |
|
123 | - } elseif (!$this->isWpValid()) { |
|
124 | - printf($noticeTemplate, |
|
125 | - sprintf($messages[0], $pluginName), |
|
126 | - sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
128 | - ); |
|
129 | - } |
|
130 | - } |
|
108 | + /** |
|
109 | + * @param string $pluginName |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + protected function printNotice($pluginName) |
|
113 | + { |
|
114 | + $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
115 | + $messages = $this->getMessages(); |
|
116 | + $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | + if (!$this->isPhpValid()) { |
|
118 | + printf($noticeTemplate, |
|
119 | + sprintf($messages[0], $pluginName), |
|
120 | + sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | + sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
122 | + ); |
|
123 | + } elseif (!$this->isWpValid()) { |
|
124 | + printf($noticeTemplate, |
|
125 | + sprintf($messages[0], $pluginName), |
|
126 | + sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | + $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
128 | + ); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - protected function redirect() |
|
136 | - { |
|
137 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | - filter_input(INPUT_GET, 'plugin_status'), |
|
139 | - filter_input(INPUT_GET, 'paged'), |
|
140 | - filter_input(INPUT_GET, 's') |
|
141 | - ))); |
|
142 | - exit; |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + protected function redirect() |
|
136 | + { |
|
137 | + wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | + filter_input(INPUT_GET, 'plugin_status'), |
|
139 | + filter_input(INPUT_GET, 'paged'), |
|
140 | + filter_input(INPUT_GET, 's') |
|
141 | + ))); |
|
142 | + exit; |
|
143 | + } |
|
144 | 144 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Check for minimum system requirments on plugin activation. |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @param string $file |
26 | 26 | */ |
27 | - public function __construct($file, array $versions = array()) |
|
27 | + public function __construct( $file, array $versions = array() ) |
|
28 | 28 | { |
29 | - $this->file = realpath($file); |
|
30 | - $this->versions = wp_parse_args($versions, array( |
|
29 | + $this->file = realpath( $file ); |
|
30 | + $this->versions = wp_parse_args( $versions, array( |
|
31 | 31 | 'php' => static::MIN_PHP_VERSION, |
32 | 32 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
33 | - )); |
|
33 | + ) ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function canProceed() |
40 | 40 | { |
41 | - if ($this->isValid()) { |
|
41 | + if( $this->isValid() ) { |
|
42 | 42 | return true; |
43 | 43 | } |
44 | - add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | - add_action('admin_notices', array($this, 'deactivate')); |
|
44 | + add_action( 'activated_plugin', array( $this, 'deactivate' ) ); |
|
45 | + add_action( 'admin_notices', array( $this, 'deactivate' ) ); |
|
46 | 46 | return false; |
47 | 47 | } |
48 | 48 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function isPhpValid() |
53 | 53 | { |
54 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
54 | + return !version_compare( PHP_VERSION, $this->versions[ 'php' ], '<' ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -68,25 +68,25 @@ discard block |
||
68 | 68 | public function isWpValid() |
69 | 69 | { |
70 | 70 | global $wp_version; |
71 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
71 | + return !version_compare( $wp_version, $this->versions[ 'wordpress' ], '<' ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @param string $plugin |
76 | 76 | * @return void |
77 | 77 | */ |
78 | - public function deactivate($plugin) |
|
78 | + public function deactivate( $plugin ) |
|
79 | 79 | { |
80 | - if ($this->isValid()) { |
|
80 | + if( $this->isValid() ) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | - $pluginSlug = plugin_basename($this->file); |
|
84 | - if ($plugin == $pluginSlug) { |
|
83 | + $pluginSlug = plugin_basename( $this->file ); |
|
84 | + if( $plugin == $pluginSlug ) { |
|
85 | 85 | $this->redirect(); //exit |
86 | 86 | } |
87 | - $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | - deactivate_plugins($pluginSlug); |
|
89 | - $this->printNotice($pluginData['name']); |
|
87 | + $pluginData = get_file_data( $this->file, array( 'name' => 'Plugin Name' ), 'plugin' ); |
|
88 | + deactivate_plugins( $pluginSlug ); |
|
89 | + $this->printNotice( $pluginData[ 'name' ] ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | protected function getMessages() |
96 | 96 | { |
97 | 97 | return array( |
98 | - __('The %s plugin was deactivated.', 'blackbar'), |
|
99 | - __('This plugin requires %s or greater in order to work properly.', 'blackbar'), |
|
100 | - __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'blackbar'), |
|
101 | - __('PHP version', 'blackbar'), |
|
102 | - __('WordPress version', 'blackbar'), |
|
103 | - __('Update WordPress', 'blackbar'), |
|
104 | - __('You can use the %s plugin to restore %s to the previous version.', 'blackbar'), |
|
98 | + __( 'The %s plugin was deactivated.', 'blackbar' ), |
|
99 | + __( 'This plugin requires %s or greater in order to work properly.', 'blackbar' ), |
|
100 | + __( 'Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'blackbar' ), |
|
101 | + __( 'PHP version', 'blackbar' ), |
|
102 | + __( 'WordPress version', 'blackbar' ), |
|
103 | + __( 'Update WordPress', 'blackbar' ), |
|
104 | + __( 'You can use the %s plugin to restore %s to the previous version.', 'blackbar' ), |
|
105 | 105 | ); |
106 | 106 | } |
107 | 107 | |
@@ -109,22 +109,22 @@ discard block |
||
109 | 109 | * @param string $pluginName |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - protected function printNotice($pluginName) |
|
112 | + protected function printNotice( $pluginName ) |
|
113 | 113 | { |
114 | 114 | $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
115 | 115 | $messages = $this->getMessages(); |
116 | - $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | - if (!$this->isPhpValid()) { |
|
118 | - printf($noticeTemplate, |
|
119 | - sprintf($messages[0], $pluginName), |
|
120 | - sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | - sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
116 | + $rollbackMessage = sprintf( '<strong>' . $messages[ 6 ] . '</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName ); |
|
117 | + if( !$this->isPhpValid() ) { |
|
118 | + printf( $noticeTemplate, |
|
119 | + sprintf( $messages[ 0 ], $pluginName ), |
|
120 | + sprintf( $messages[ 1 ], $messages[ 3 ] . ' ' . $this->versions[ 'php' ] ), |
|
121 | + sprintf( $messages[ 2 ], PHP_VERSION ) . '</p><p>' . $rollbackMessage |
|
122 | 122 | ); |
123 | - } elseif (!$this->isWpValid()) { |
|
124 | - printf($noticeTemplate, |
|
125 | - sprintf($messages[0], $pluginName), |
|
126 | - sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
123 | + } elseif( !$this->isWpValid() ) { |
|
124 | + printf( $noticeTemplate, |
|
125 | + sprintf( $messages[ 0 ], $pluginName ), |
|
126 | + sprintf( $messages[ 1 ], $messages[ 4 ] . ' ' . $this->versions[ 'wordpress' ] ), |
|
127 | + $rollbackMessage . '</p><p>' . sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages[ 5 ] ) |
|
128 | 128 | ); |
129 | 129 | } |
130 | 130 | } |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function redirect() |
136 | 136 | { |
137 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | - filter_input(INPUT_GET, 'plugin_status'), |
|
139 | - filter_input(INPUT_GET, 'paged'), |
|
140 | - filter_input(INPUT_GET, 's') |
|
141 | - ))); |
|
137 | + wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | + filter_input( INPUT_GET, 'plugin_status' ), |
|
139 | + filter_input( INPUT_GET, 'paged' ), |
|
140 | + filter_input( INPUT_GET, 's' ) |
|
141 | + ) ) ); |
|
142 | 142 | exit; |
143 | 143 | } |
144 | 144 | } |
@@ -120,7 +120,8 @@ |
||
120 | 120 | sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
121 | 121 | sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
122 | 122 | ); |
123 | - } elseif (!$this->isWpValid()) { |
|
123 | + } |
|
124 | + elseif (!$this->isWpValid()) { |
|
124 | 125 | printf($noticeTemplate, |
125 | 126 | sprintf($messages[0], $pluginName), |
126 | 127 | sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |