PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.9.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.9.6
1.9.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 All 41 releases
← All changes | lib/menu_settings.php +138 -40 1.51.9.6 View file →
@@ -6,13 +6,15 @@
6 6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 9 | |
10 - | (c) Jerome Bruandet ~ https://code-profiler.com/ |
10 + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
11 11 +=====================================================================+
12 12 */
13 13
14 -if (! defined('ABSPATH') ) { die('Forbidden'); }
14 +if (! defined('ABSPATH') ) {
15 + die('Forbidden');
16 +}
15 17
16 18 // =====================================================================
17 19 // Display Summary tab.
18 20
@@ -20,17 +22,25 @@
20 22
21 23 // Save settings?
22 24 if (! empty( $_POST['save-settings'] ) ) {
23 25 // Make sure we have security nonce
24 - if ( empty( $_POST['cp-save-settings'] ) || ! wp_verify_nonce($_POST['cp-save-settings'], 'cp_settings') ) {
26 + if ( empty( $_POST['cp-save-settings'] ) ||
27 + ! wp_verify_nonce($_POST['cp-save-settings'], 'cp_settings') ) {
28 +
25 29 wp_nonce_ays('cp_settings');
26 30 }
27 31 $res = code_profiler_save_settings();
28 32 if ( $res === true ) {
29 - printf( CODE_PROFILER_UPDATE_NOTICE, esc_html__('Your changes have been saved.', 'code-profiler') );
33 + printf(
34 + CODE_PROFILER_UPDATE_NOTICE,
35 + esc_html__('Your changes have been saved.', 'code-profiler')
36 + );
30 37 }
31 38 else {
32 - printf( CODE_PROFILER_ERROR_NOTICE, esc_html__('No changes were detected.', 'code-profiler') );
39 + printf(
40 + CODE_PROFILER_ERROR_NOTICE,
41 + esc_html__('No changes were detected.', 'code-profiler')
42 + );
33 43 }
34 44 }
35 45
36 46 // Fetch current options
@@ -42,9 +52,11 @@
42 52 <table class="form-table">
43 53 <?php
44 54
45 55 // Paths
46 - if ( empty( $cp_options['show_paths'] ) || ! in_array( $cp_options['show_paths'], ['absolute', 'relative' ] ) ) {
56 + if ( empty( $cp_options['show_paths'] ) ||
57 + ! in_array( $cp_options['show_paths'], ['absolute', 'relative' ] ) ) {
58 +
47 59 $cp_options['show_paths'] = 'relative';
48 60 }
49 61 ?>
50 62 <tr>
@@ -56,13 +68,17 @@
56 68 </tr>
57 69
58 70 <?php
59 71 // Name vs slug
60 - if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) {
72 + if ( empty( $cp_options['display_name'] ) ||
73 + ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) {
74 +
61 75 $cp_options['display_name'] = 'full';
62 76 }
63 77 // Truncate names
64 - if ( empty( $cp_options['truncate_name'] ) || ! preg_match('/^\d+$/', ( $cp_options['truncate_name'] ) ) ) {
78 + if ( empty( $cp_options['truncate_name'] ) ||
79 + ! preg_match('/^\d+$/', ( $cp_options['truncate_name'] ) ) ) {
80 +
65 81 $cp_options['truncate_name'] = 30;
66 82 }
67 83 ?>
68 84 <tr>
@@ -82,13 +98,17 @@
82 98 </tr>
83 99
84 100 <?php
85 101 // chart type
86 - if ( empty( $cp_options['chart_type'] ) || ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) {
102 + if ( empty( $cp_options['chart_type'] ) ||
103 + ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) {
104 +
87 105 $cp_options['chart_type'] = 'x';
88 106 }
89 107 // Max plugins to display
90 - if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match('/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) {
108 + if ( empty( $cp_options['chart_max_plugins'] ) ||
109 + ! preg_match('/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) {
110 +
91 111 $cp_options['chart_max_plugins'] = 25;
92 112 }
93 113 // Empty values
94 114 if (! empty( $cp_options['hide_empty_value'] ) ) {
@@ -123,14 +143,8 @@
123 143 </td>
124 144 </tr>
125 145
126 146 <?php
127 - // Composer warning
128 - if (! empty( $cp_options['warn_composer'] ) ) {
129 - $cp_options['warn_composer'] = 1;
130 - } else {
131 - $cp_options['warn_composer'] = 0;
132 - }
133 147 // WP-CLI integration
134 148 if (! empty( $cp_options['enable_wpcli'] ) ) {
135 149 $cp_options['enable_wpcli'] = 1;
136 150 } else {
@@ -168,14 +182,8 @@
168 182 ?>
169 183 <tr>
170 184 <th scope="row"><?php esc_html_e('General Options', 'code-profiler') ?></th>
171 185 <td>
172 - <p><label><input type="checkbox" name="cp_options[warn_composer]"<?php checked( $cp_options['warn_composer'], '1') ?> /><?php esc_html_e('Show a notice when several plugins are using Composer dependency manager.','code-profiler-pro') ?></label></p>
173 -
174 - <p class="description"><?php esc_html_e('Consult the FAQ tab for more details about this option.', 'code-profiler-pro') ?></p>
175 -
176 - <br />
177 -
178 186 <p><label><input type="checkbox" name="cp_options[enable_wpcli]"<?php checked( $cp_options['enable_wpcli'], '1') ?> /><?php esc_html_e('Enable WP-CLI integration.','code-profiler') ?></label></p>
179 187 <p class="description"><?php printf( esc_html__('Enter %s to display the available command line options.', 'code-profiler'), '<code>wp code-profiler help</code>') ?></p>
180 188
181 189 <br />
@@ -191,33 +199,100 @@
191 199 <p><label><input type="checkbox" name="cp_options[http_response_400]" value="1"<?php checked( $http_response_400, '1') ?> /><?php esc_html_e('4xx client errors (400 Bad Request, 403 Forbidden, 404 Not Found etc)','code-profiler') ?></label></p>
192 200 <p><label><input type="checkbox" name="cp_options[http_response_500]" value="1"<?php checked( $http_response_500, '1') ?> /><?php esc_html_e('5xx server errors (500 Internal Server Error, 503 Service Unavailable etc)','code-profiler') ?></label></p>
193 201 </td>
194 202 </tr>
203 + </table>
204 +
205 + <h3><?php esc_html_e('Profiler','code-profiler') ?></h3>
206 + <table class="form-table">
195 207 <?php
196 208 // Accuracy
197 - if ( empty( $cp_options['accuracy'] ) || ! preg_match('/^(?:1|5|10|15|20)$/', $cp_options['accuracy'] ) ) {
209 + if ( empty( $cp_options['accuracy'] ) ||
210 + ! preg_match('/^(?:1|5|10|15|20)$/D', $cp_options['accuracy'] ) ) {
211 +
198 212 $cp_options['accuracy'] = 1;
199 213 }
200 214 ?>
201 215 <tr>
202 - <th scope="row"><?php esc_html_e('Accuracy & Precision', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Selecting a high accuracy level is preferred and will work on most sites, but the profiling process will take longer to execute as opposed to choosing a lower accuracy level. If you have a slow WordPress site with a lot of plugins installed and your server or reverse proxy is timing out when Code Profiler is running (e.g., "503 Service Unavailable" or "504 Gateway Timeout" error), try to lower the accuracy level in order to speed up the profiling process and avoid the server timeout.', 'code-profiler') ?>"></span></th>
216 + <th scope="row"><?php esc_html_e('Accuracy & Precision', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php
217 + esc_attr_e('When accuracy is set to the highest level, Code Profiler runs as a "tracing profiler", and when accuracy is set to a lower level, it runs as a "sampling profiler".', 'code-profiler');
218 + echo '<br />';
219 + esc_attr_e('Selecting a high accuracy level is preferred and will work on most sites, but the profiling process will take longer to execute as opposed to choosing a lower accuracy level. If you have a slow WordPress site with a lot of plugins installed and your server or reverse proxy is timing out when Code Profiler is running (e.g., "503 Service Unavailable" or "504 Gateway Timeout" error), try to lower the accuracy level in order to speed up the profiling process and avoid the server timeout.', 'code-profiler');
220 + ?>"></span></th>
203 221 <td>
204 222 <p><label><?php esc_html_e('Select the accuracy and precision level of the profiler:', 'code-profiler') ?> &nbsp;<select name="cp_options[accuracy]">
205 223 <?php
206 224 foreach( CODE_PROFILER_ACCURACY as $key => $value ) {
207 - echo '<option value="'. esc_attr( $key ) .'"'. selected( $cp_options['accuracy'], $key ) .'>'. esc_html( $value ) .'</option>';
225 + echo '<option value="'. esc_attr( $key ) .'"'. selected( $cp_options['accuracy'], $key, false ) .'>'. esc_html( $value ) .'</option>';
208 226 }
209 227 ?></select></label></p>
210 228 </td>
211 229 </tr>
230 + <?php
231 + $recommended = code_profiler_suggested_memory();
232 + // Buffer size
233 + if ( empty( $cp_options['buffer'] ) ) {
234 + $cp_options['buffer'] = 0;
235 + } elseif (! preg_match('/^(?:[1-9]|10)$/', $cp_options['buffer'] ) ) {
236 + $cp_options['buffer'] = (int) $recommended;
237 + }
238 + ?>
239 + <tr>
240 + <th scope="row"><?php esc_html_e('Buffer size', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php
241 + esc_attr_e('When running, the profiler collects data and saves it to a memory buffer. When the buffer is full, the data is written to disk. If your site uses too much memory and PHP throws a memory error, you can try to lower that value.', 'code-profiler');
242 + ?>"></span></th>
243 + <td>
244 + <p>
245 + <label>
246 + <select name="cp_options[buffer]">
247 + <?php
248 + echo '<option value="0"'. selected( $cp_options['buffer'], 0, false ) .'>'.
249 + esc_html__('Automatic', 'code-profiler') .
250 + '</option>';
251 + for ( $i = 1; $i <= 10; $i++ ) {
252 + echo '<option value="'. $i .'"'. selected( $cp_options['buffer'], $i, false ) .'>'.
253 + sprintf(
254 + /* Translators: 'MB' for MegaBytes */
255 + esc_html__('%s MB', 'code-profiler')
256 + , $i ) .
257 + '</option>';
258 + }
259 + ?>
260 + </select>
261 + </label>
262 + </p>
263 + <p class="description"><?php
264 + printf(
265 + esc_html__('Recommended value based on your system configuration: %s MB', 'code-profiler'),
266 + (int) $recommended
267 + );
268 + ?></p>
269 + </td>
270 + </tr>
271 + <?php
272 + if ( empty( $cp_options['php_error'] ) ) {
273 + $cp_options['php_error'] = 0;
274 + } else {
275 + $cp_options['php_error'] = 1;
276 + }
277 + ?>
278 + <tr>
279 + <th scope="row"><?php esc_html_e('PHP Error Logging', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php
280 + esc_attr_e('This option will enable PHP error logging when the profiler is running. The log will be saved by default to "/wp-content/debug.log", unless you configured PHP or WordPress to use a different path.', 'code-profiler');
281 + ?>"></span>
282 + </th>
283 + <td>
284 + <p><label><input type="checkbox" name="cp_options[php_error]"<?php checked( $cp_options['php_error'], '1') ?> /><?php esc_html_e('Enable PHP error logging.','code-profiler') ?></label></p>
285 + </td>
286 + </tr>
212 287 </table>
213 288
214 - <p><input type="submit" name="save-settings" class="button-primary" value="<?php esc_attr_e('Save Settings', 'code-profiler') ?>" /></p>
289 + <p><input type="submit" name="save-settings" class="button button-primary" value="<?php esc_attr_e('Save Settings', 'code-profiler') ?>" /></p>
215 290
216 291 </form>
217 292 <?php
218 293
219 -// =====================================================================
294 +// ===================================================================== 2023-06-15
220 295 // Save and validate the settings.
221 296
222 297 function code_profiler_save_settings() {
223 298
@@ -223,9 +298,11 @@
223 298
224 299 $cp_options = get_option('code-profiler');
225 300
226 301 // Paths
227 - if ( empty( $_POST['cp_options']['show_paths'] ) || ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) {
302 + if ( empty( $_POST['cp_options']['show_paths'] ) ||
303 + ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) {
304 +
228 305 $cp_options['show_paths'] = 'relative';
229 306 } else {
230 307 $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] );
231 308 }
@@ -230,9 +307,11 @@
230 307 $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] );
231 308 }
232 309
233 310 // Name vs slug
234 - if ( empty( $_POST['cp_options']['display_name'] ) || ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) {
311 + if ( empty( $_POST['cp_options']['display_name'] ) ||
312 + ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) {
313 +
235 314 $cp_options['display_name'] = 'full';
236 315 } else {
237 316 $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] );
238 317 }
@@ -237,9 +316,11 @@
237 316 $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] );
238 317 }
239 318
240 319 // Truncate names
241 - if ( empty( $_POST['cp_options']['truncate_name'] ) || ! preg_match('/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) {
320 + if ( empty( $_POST['cp_options']['truncate_name'] ) ||
321 + ! preg_match('/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) {
322 +
242 323 $cp_options['truncate_name'] = 30;
243 324 } else {
244 325 $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name'];
245 326 }
@@ -244,9 +325,11 @@
244 325 $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name'];
245 326 }
246 327
247 328 // chart type
248 - if ( empty( $_POST['cp_options']['chart_type'] ) || ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) {
329 + if ( empty( $_POST['cp_options']['chart_type'] ) ||
330 + ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) {
331 +
249 332 $cp_options['chart_type'] = 'x';
250 333 } else {
251 334 $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] );
252 335 }
@@ -251,9 +334,11 @@
251 334 $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] );
252 335 }
253 336
254 337 // Max plugins to display
255 - if ( empty( $_POST['cp_options']['chart_max_plugins'] ) || ! preg_match('/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) {
338 + if ( empty( $_POST['cp_options']['chart_max_plugins'] ) ||
339 + ! preg_match('/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) {
340 +
256 341 $cp_options['chart_max_plugins'] = 25;
257 342 } else {
258 343 $cp_options['chart_max_plugins'] = (int) $_POST['cp_options']['chart_max_plugins'];
259 344 }
@@ -264,15 +349,8 @@
264 349 } else {
265 350 $cp_options['hide_empty_value'] = 0;
266 351 }
267 352
268 - // Composer warning
269 - if (! empty( $_POST['cp_options']['warn_composer'] ) ) {
270 - $cp_options['warn_composer'] = 1;
271 - } else {
272 - $cp_options['warn_composer'] = 0;
273 - }
274 -
275 353 // WP-CLI integration
276 354 if (! empty( $_POST['cp_options']['enable_wpcli'] ) ) {
277 355 $cp_options['enable_wpcli'] = 1;
278 356 } else {
@@ -303,12 +381,32 @@
303 381 $cp_options['http_response'] = "^(?:$code)\d{2}$";
304 382 }
305 383
306 384 // Accuracy
307 - if ( empty( $_POST['cp_options']['accuracy'] ) || ! preg_match('/^(?:1|5|10|15|20)$/', $_POST['cp_options']['accuracy'] ) ) {
385 + if ( empty( $_POST['cp_options']['accuracy'] ) ||
386 + ! preg_match('/^(?:1|5|10|15|20)$/D', $_POST['cp_options']['accuracy'] ) ) {
387 +
308 388 $cp_options['accuracy'] = 1;
309 389 } else {
310 390 $cp_options['accuracy'] = (int) $_POST['cp_options']['accuracy'];
391 + }
392 +
393 + // Buffer size
394 + if ( empty( $_POST['cp_options']['buffer'] ) ) {
395 + $cp_options['buffer'] = 0;
396 + } elseif (! preg_match('/^(?:[1-9]|10)$/D', $_POST['cp_options']['buffer'] ) ) {
397 + $cp_options['buffer'] = 10;
398 + } else {
399 + $cp_options['buffer'] = (int) $_POST['cp_options']['buffer'];
400 + }
401 +
402 + /**
403 + * PHP error logging.
404 + */
405 + if (! empty( $_POST['cp_options']['php_error'] ) ) {
406 + $cp_options['php_error'] = 1;
407 + } else {
408 + $cp_options['php_error'] = 0;
311 409 }
312 410
313 411 return update_option('code-profiler', $cp_options );
314 412