PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.6
1.9.5 1.9.4 1.9.3 trunk 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 All 40 releases
← All changes | lib/class-cli.php +32 -29 1.51.6 View file →
@@ -10,9 +10,9 @@
10 10 | (c) Jerome Bruandet ~ https://code-profiler.com/ |
11 11 +=====================================================================+
12 12 */
13 13
14 -if (! defined( 'ABSPATH' ) ) { die( 'Forbidden' ); }
14 +if (! defined('ABSPATH') ) { die('Forbidden'); }
15 15
16 16 // =====================================================================
17 17
18 18 class CodeProfiler_CLI extends WP_CLI_Command {
@@ -20,9 +20,9 @@
20 20 private $file;
21 21 private $cmd_view = 'wp code-profiler view';
22 22 private $cmd_run = 'wp code-profiler run';
23 23
24 - /*
24 + /**
25 25 * Run the profiler.
26 26 *
27 27 */
28 28 public function run( $args, $assoc_args ) {
@@ -28,9 +28,9 @@
28 28 public function run( $args, $assoc_args ) {
29 29
30 30 $this->is_enabled();
31 31
32 - $_POST['cp_nonce'] = wp_create_nonce( 'start_profiler_nonce' );
32 + $_POST['cp_nonce'] = wp_create_nonce('start_profiler_nonce');
33 33 $_POST['post'] = home_url( '/' );
34 34 $_POST['where'] = 'frontend';
35 35 // Detect if we're authenticated or not
36 36 if ( is_user_logged_in() === true ) {
@@ -51,9 +51,9 @@
51 51 }
52 52
53 53 // HTTP basic authentication
54 54 if (! empty( $assoc_args['u'] ) ) {
55 - _e('Enter your HTTP basic authentication password:', 'code-profiler' );
55 + _e('Enter your HTTP basic authentication password:', 'code-profiler');
56 56 echo ' ';
57 57 echo "\033[30;40m";
58 58 $password = trim( stream_get_line( STDIN, 255, PHP_EOL) );
59 59 echo "\033[0m";
@@ -60,9 +60,9 @@
60 60 $_POST['Authorization'] = 'Basic '. base64_encode( "{$assoc_args['u']}:{$password}" );
61 61 }
62 62
63 63 WP_CLI::log( sprintf(
64 - __('Starting Code Profiler v%s (profile: %s)', 'code-profiler' ),
64 + __('Starting Code Profiler v%s (profile: %s)', 'code-profiler'),
65 65 CODE_PROFILER_VERSION, $_POST['profile'] ) . "\n"
66 66 );
67 67
68 68 $progress = \WP_CLI\Utils\make_progress_bar( '', 3 );
@@ -70,9 +70,9 @@
70 70
71 71 // Run the profiler
72 72 $response = json_decode( codeprofiler_start_profiler(), true );
73 73 if ( $response === false ) {
74 - $message = __('Unknown error returned by AJAX', 'code-profiler' );
74 + $message = __('Unknown error returned by AJAX', 'code-profiler');
75 75 WP_CLI::error( $message );
76 76 exit;
77 77 }
78 78 if ( $response['status'] == 'error' ) {
@@ -85,9 +85,9 @@
85 85 // All good, run the parser
86 86 $_POST['microtime'] = $response['microtime'];
87 87 $response = json_decode( codeprofiler_prepare_report(), true );
88 88 if ( $response === false ) {
89 - $message = __('Unknown error returned by AJAX', 'code-profiler' );
89 + $message = __('Unknown error returned by AJAX', 'code-profiler');
90 90 WP_CLI::error( $message );
91 91 exit;
92 92 }
93 93 if ( $response['status'] == 'error' ) {
@@ -104,13 +104,13 @@
104 104 exit;
105 105 }
106 106
107 107
108 - /*
108 + /**
109 109 * Display last created profile.
110 110 *
111 111 */
112 - public function view( $profile = '' ) {
112 + public function view( $profile = '') {
113 113
114 114 $this->is_enabled();
115 115
116 116 // The profile was just created (`wp code-profiler run`)...
@@ -116,9 +116,9 @@
116 116 // The profile was just created (`wp code-profiler run`)...
117 117 if (! empty( $profile ) ) {
118 118 $this->file = code_profiler_get_profile_path( $profile );
119 119 if ( $this->file === false ) {
120 - $message = __('Cannot find the profile file', 'code-profiler' );
120 + $message = __('Cannot find the profile file', 'code-profiler');
121 121 WP_CLI::error( $message );
122 122 exit;
123 123 }
124 124 $this->file .= '.slugs.profile';
@@ -127,9 +127,9 @@
127 127 } else {
128 128 $this->file = $this->find_last_profile();
129 129 if ( $this->file === false ) {
130 130 $message = sprintf(
131 - __('No profile found. Run the profiler at least once to create a profile: %s', 'code-profiler' ),
131 + __('No profile found. Run the profiler at least once to create a profile: %s', 'code-profiler'),
132 132 $this->cmd_run
133 133 );
134 134 WP_CLI::error( $message );
135 135 exit;
@@ -146,14 +146,14 @@
146 146 $date = date('Y/m/d \@ H:i:s', filemtime( $this->file ) );
147 147 echo WP_CLI::colorize("\n%Y$message ~ $date%n\n\n");
148 148
149 149 // Display stats
150 - $summary_file = str_replace( '.slugs.profile', '', $this->file );
151 - echo code_profiler_getsummarystats( $summary_file, 'text' );
150 + $summary_file = str_replace('.slugs.profile', '', $this->file );
151 + echo code_profiler_getsummarystats( $summary_file, 'text');
152 152
153 153 $slugs = $this->read_profile();
154 154
155 - $cp_options = get_option( 'code-profiler' );
155 + $cp_options = get_option('code-profiler');
156 156
157 157 // Get the total time and the slowest item
158 158 $total_time = 0;
159 159 foreach( $slugs as $k => $v ) {
@@ -170,11 +170,11 @@
170 170 } else {
171 171 $name = $v[2];
172 172 }
173 173 // Inform if it's the theme or a mu-plugin
174 - if ( $v[3] == 'theme' ) {
174 + if ( $v[3] == 'theme') {
175 175 $name .= ' (theme)';
176 - } elseif ( $v[3] == 'mu-plugin' ) {
176 + } elseif ( $v[3] == 'mu-plugin') {
177 177 $name .= ' (mu-plugin)';
178 178 }
179 179
180 180 $time = number_format( $v[1], 3 );
@@ -196,18 +196,19 @@
196 196 }
197 197 exit;
198 198 }
199 199
200 - /*
200 +
201 + /**
201 202 * Retrieve the full path/name to the last created profile
202 203 *
203 204 */
204 205 private function find_last_profile() {
205 206
206 - $profiles = glob( CODE_PROFILER_UPLOAD_DIR .'/*.slugs.profile' );
207 + $profiles = glob( CODE_PROFILER_UPLOAD_DIR .'/*.slugs.profile');
207 208
208 209 array_multisort(
209 - array_map( 'filectime', $profiles ),
210 + array_map('filectime', $profiles ),
210 211 SORT_NUMERIC,
211 212 SORT_DESC,
212 213 $profiles
213 214 );
@@ -219,15 +220,15 @@
219 220 return false;
220 221 }
221 222
222 223
223 - /*
224 + /**
224 225 * Parse and return the profile's data
225 226 *
226 227 */
227 228 private function read_profile() {
228 229
229 - $profile = str_replace( '.slugs.profile', '', $this->file );
230 + $profile = str_replace('.slugs.profile', '', $this->file );
230 231
231 232 $res = code_profiler_get_profile_data( $profile );
232 233 if ( isset( $res['error'] ) ) {
233 234 WP_CLI::error( $res['error'] );
@@ -241,15 +242,16 @@
241 242
242 243 return $res;
243 244 }
244 245
245 - /*
246 +
247 + /**
246 248 * Verify wether WP CLI integration is enabled or not
247 249 *
248 250 */
249 251 private function is_enabled() {
250 252
251 - $cp_options = get_option( 'code-profiler' );
253 + $cp_options = get_option('code-profiler');
252 254 if ( empty( $cp_options['enable_wpcli'] ) ) {
253 255 $message = __('WP-CLI integration is disabled. To enable it, log in to your admin dashboard and go to the Code Profiler settings page.', 'code-profiler');
254 256 WP_CLI::error( $message );
255 257 exit;
@@ -255,9 +257,10 @@
255 257 exit;
256 258 }
257 259 }
258 260
259 - /*
261 +
262 + /**
260 263 * Display help screen and quit.
261 264 *
262 265 */
263 266 public function help() {
@@ -263,24 +266,24 @@
263 266 public function help() {
264 267
265 268 $this->is_enabled();
266 269
267 - WP_CLI::log( "\nCode Profiler v". CODE_PROFILER_VERSION .
270 + WP_CLI::log("\nCode Profiler v". CODE_PROFILER_VERSION .
268 271 " (c)". date('Y') ." Jerome Bruandet & NinTechNet Limited ~ https://code-profiler.com/\n\n".
269 272 " {$this->cmd_view} ". __('View last created profile', 'code-profiler') ."\n".
270 - " {$this->cmd_run} ". __('Run the profiler on the frontend', 'code-profiler') ."\n\n".
273 + " {$this->cmd_run} ". __('Run the profiler in the frontend', 'code-profiler') ."\n\n".
271 274 __('GLOBAL PARAMETERS', 'code-profiler') ."\n\n".
272 275 " --dest=<URL to profile> **". __('Pro version only', 'code-profiler') ."**\n".
273 - " ". __('Path to the WordPress page or post to profile. If missing, profile the frontend.', 'code-profiler-pro') ."\n\n".
276 + " ". __('Path to the WordPress page or post to profile. If missing, profile the frontend.', 'code-profiler') ."\n\n".
274 277 " --user=<id|login|email>\n".
275 278 " ". __('Run the profiler as the corresponding WordPress user. If missing, run as an unauthenticated user.', 'code-profiler') ."\n\n".
276 279 " --u=<username>\n".
277 - " ". __('HTTP Basic authentication username. You will be prompted to enter your password.', 'code-profiler') ."\n\n" );
280 + " ". __('HTTP Basic authentication username. You will be prompted to enter your password.', 'code-profiler') ."\n\n");
278 281 exit;
279 282 }
280 283
281 284 }
282 285
283 -WP_CLI::add_command( 'code-profiler', 'CodeProfiler_CLI', ['shortdesc' => __('Profile your blog with Code Profiler.', 'code-profiler') ] );
286 +WP_CLI::add_command('code-profiler', 'CodeProfiler_CLI', ['shortdesc' => __('Profile your blog with Code Profiler.', 'code-profiler') ] );
284 287
285 288 // =====================================================================
286 289 // EOF