| @@ -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'] ) ) { |
| @@ -191,20 +211,23 @@ | ||
| 191 | 211 | <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 | 212 | <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 | 213 | </td> |
| 194 | 214 | </tr> |
| 215 | + </table> | |
| 216 | + | |
| 217 | + <h3><?php esc_html_e('Profiler','code-profiler') ?></h3> | |
| 218 | + <table class="form-table"> | |
| 195 | 219 | <?php |
| 196 | 220 | // Accuracy |
| 197 | - if ( empty( $cp_options['accuracy'] ) || ! preg_match('/^(?:1|5|10|15|20)$/D', $cp_options['accuracy'] ) ) { | |
| 221 | + if ( empty( $cp_options['accuracy'] ) || | |
| 222 | + ! preg_match('/^(?:1|5|10|15|20)$/D', $cp_options['accuracy'] ) ) { | |
| 223 | + | |
| 198 | 224 | $cp_options['accuracy'] = 1; |
| 199 | 225 | } |
| 200 | 226 | ?> |
| 201 | 227 | <tr> |
| 202 | 228 | <th scope="row"><?php esc_html_e('Accuracy & Precision', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php |
| 203 | - printf( | |
| 204 | - esc_attr__('When accuracy is set to the highest level, Code Profiler runs as a %s Tracing profiler %s, and when accuracy is set to a lower level, it runs as a %s Sampling profiler %s.', 'code-profiler'), | |
| 205 | - '<em>', '</em>','<em>', '</em>' | |
| 206 | - ); | |
| 229 | + 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'); | |
| 207 | 230 | echo '<br />'; |
| 208 | 231 | 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'); |
| 209 | 232 | ?>"></span></th> |
| 210 | 233 | <td> |
| @@ -210,21 +233,62 @@ | ||
| 210 | 233 | <td> |
| 211 | 234 | <p><label><?php esc_html_e('Select the accuracy and precision level of the profiler:', 'code-profiler') ?> <select name="cp_options[accuracy]"> |
| 212 | 235 | <?php |
| 213 | 236 | foreach( CODE_PROFILER_ACCURACY as $key => $value ) { |
| 214 | - echo '<option value="'. esc_attr( $key ) .'"'. selected( $cp_options['accuracy'], $key ) .'>'. esc_html( $value ) .'</option>'; | |
| 237 | + echo '<option value="'. esc_attr( $key ) .'"'. selected( $cp_options['accuracy'], $key, false ) .'>'. esc_html( $value ) .'</option>'; | |
| 215 | 238 | } |
| 216 | 239 | ?></select></label></p> |
| 217 | 240 | </td> |
| 218 | 241 | </tr> |
| 242 | + <?php | |
| 243 | + $recommended = code_profiler_suggested_memory(); | |
| 244 | + // Buffer size | |
| 245 | + if ( empty( $cp_options['buffer'] ) ) { | |
| 246 | + $cp_options['buffer'] = 0; | |
| 247 | + } elseif (! preg_match('/^(?:[1-9]|10)$/', $cp_options['buffer'] ) ) { | |
| 248 | + $cp_options['buffer'] = (int) $recommended; | |
| 249 | + } | |
| 250 | + ?> | |
| 251 | + <tr> | |
| 252 | + <th scope="row"><?php esc_html_e('Buffer size', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php | |
| 253 | + 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'); | |
| 254 | + ?>"></span></th> | |
| 255 | + <td> | |
| 256 | + <p> | |
| 257 | + <label> | |
| 258 | + <select name="cp_options[buffer]"> | |
| 259 | + <?php | |
| 260 | + echo '<option value="0"'. selected( $cp_options['buffer'], 0, false ) .'>'. | |
| 261 | + esc_html__('Automatic', 'code-profiler') . | |
| 262 | + '</option>'; | |
| 263 | + for ( $i = 1; $i <= 10; $i++ ) { | |
| 264 | + echo '<option value="'. $i .'"'. selected( $cp_options['buffer'], $i, false ) .'>'. | |
| 265 | + sprintf( | |
| 266 | + /* Translators: 'MB' for MegaBytes */ | |
| 267 | + esc_html__('%s MB', 'code-profiler') | |
| 268 | + , $i ) . | |
| 269 | + '</option>'; | |
| 270 | + } | |
| 271 | + ?> | |
| 272 | + </select> | |
| 273 | + </label> | |
| 274 | + </p> | |
| 275 | + <p class="description"><?php | |
| 276 | + printf( | |
| 277 | + esc_html__('Recommended value based on your system configuration: %s MB', 'code-profiler'), | |
| 278 | + (int) $recommended | |
| 279 | + ); | |
| 280 | + ?></p> | |
| 281 | + </td> | |
| 282 | + </tr> | |
| 219 | 283 | </table> |
| 220 | 284 | |
| 221 | - <p><input type="submit" name="save-settings" class="button-primary" value="<?php esc_attr_e('Save Settings', 'code-profiler') ?>" /></p> | |
| 285 | + <p><input type="submit" name="save-settings" class="button button-primary" value="<?php esc_attr_e('Save Settings', 'code-profiler') ?>" /></p> | |
| 222 | 286 | |
| 223 | 287 | </form> |
| 224 | 288 | <?php |
| 225 | 289 | |
| 226 | -// ===================================================================== | |
| 290 | +// ===================================================================== 2023-06-15 | |
| 227 | 291 | // Save and validate the settings. |
| 228 | 292 | |
| 229 | 293 | function code_profiler_save_settings() { |
| 230 | 294 | |
| @@ -230,9 +294,11 @@ | ||
| 230 | 294 | |
| 231 | 295 | $cp_options = get_option('code-profiler'); |
| 232 | 296 | |
| 233 | 297 | // Paths |
| 234 | - if ( empty( $_POST['cp_options']['show_paths'] ) || ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) { | |
| 298 | + if ( empty( $_POST['cp_options']['show_paths'] ) || | |
| 299 | + ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) { | |
| 300 | + | |
| 235 | 301 | $cp_options['show_paths'] = 'relative'; |
| 236 | 302 | } else { |
| 237 | 303 | $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] ); |
| 238 | 304 | } |
| @@ -237,9 +303,11 @@ | ||
| 237 | 303 | $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] ); |
| 238 | 304 | } |
| 239 | 305 | |
| 240 | 306 | // Name vs slug |
| 241 | - if ( empty( $_POST['cp_options']['display_name'] ) || ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) { | |
| 307 | + if ( empty( $_POST['cp_options']['display_name'] ) || | |
| 308 | + ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) { | |
| 309 | + | |
| 242 | 310 | $cp_options['display_name'] = 'full'; |
| 243 | 311 | } else { |
| 244 | 312 | $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] ); |
| 245 | 313 | } |
| @@ -244,9 +312,11 @@ | ||
| 244 | 312 | $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] ); |
| 245 | 313 | } |
| 246 | 314 | |
| 247 | 315 | // Truncate names |
| 248 | - if ( empty( $_POST['cp_options']['truncate_name'] ) || ! preg_match('/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) { | |
| 316 | + if ( empty( $_POST['cp_options']['truncate_name'] ) || | |
| 317 | + ! preg_match('/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) { | |
| 318 | + | |
| 249 | 319 | $cp_options['truncate_name'] = 30; |
| 250 | 320 | } else { |
| 251 | 321 | $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name']; |
| 252 | 322 | } |
| @@ -251,9 +321,11 @@ | ||
| 251 | 321 | $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name']; |
| 252 | 322 | } |
| 253 | 323 | |
| 254 | 324 | // chart type |
| 255 | - if ( empty( $_POST['cp_options']['chart_type'] ) || ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) { | |
| 325 | + if ( empty( $_POST['cp_options']['chart_type'] ) || | |
| 326 | + ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) { | |
| 327 | + | |
| 256 | 328 | $cp_options['chart_type'] = 'x'; |
| 257 | 329 | } else { |
| 258 | 330 | $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] ); |
| 259 | 331 | } |
| @@ -258,9 +330,11 @@ | ||
| 258 | 330 | $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] ); |
| 259 | 331 | } |
| 260 | 332 | |
| 261 | 333 | // Max plugins to display |
| 262 | - if ( empty( $_POST['cp_options']['chart_max_plugins'] ) || ! preg_match('/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) { | |
| 334 | + if ( empty( $_POST['cp_options']['chart_max_plugins'] ) || | |
| 335 | + ! preg_match('/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) { | |
| 336 | + | |
| 263 | 337 | $cp_options['chart_max_plugins'] = 25; |
| 264 | 338 | } else { |
| 265 | 339 | $cp_options['chart_max_plugins'] = (int) $_POST['cp_options']['chart_max_plugins']; |
| 266 | 340 | } |
| @@ -310,12 +384,23 @@ | ||
| 310 | 384 | $cp_options['http_response'] = "^(?:$code)\d{2}$"; |
| 311 | 385 | } |
| 312 | 386 | |
| 313 | 387 | // Accuracy |
| 314 | - if ( empty( $_POST['cp_options']['accuracy'] ) || ! preg_match('/^(?:1|5|10|15|20)$/D', $_POST['cp_options']['accuracy'] ) ) { | |
| 388 | + if ( empty( $_POST['cp_options']['accuracy'] ) || | |
| 389 | + ! preg_match('/^(?:1|5|10|15|20)$/D', $_POST['cp_options']['accuracy'] ) ) { | |
| 390 | + | |
| 315 | 391 | $cp_options['accuracy'] = 1; |
| 316 | 392 | } else { |
| 317 | 393 | $cp_options['accuracy'] = (int) $_POST['cp_options']['accuracy']; |
| 394 | + } | |
| 395 | + | |
| 396 | + // Buffer size | |
| 397 | + if ( empty( $_POST['cp_options']['buffer'] ) ) { | |
| 398 | + $cp_options['buffer'] = 0; | |
| 399 | + } elseif (! preg_match('/^(?:[1-9]|10)$/D', $_POST['cp_options']['buffer'] ) ) { | |
| 400 | + $cp_options['buffer'] = 10; | |
| 401 | + } else { | |
| 402 | + $cp_options['buffer'] = (int) $_POST['cp_options']['buffer']; | |
| 318 | 403 | } |
| 319 | 404 | |
| 320 | 405 | return update_option('code-profiler', $cp_options ); |
| 321 | 406 | |