| @@ -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'] ) ) { |
| @@ -168,11 +188,11 @@ | ||
| 168 | 188 | ?> |
| 169 | 189 | <tr> |
| 170 | 190 | <th scope="row"><?php esc_html_e('General Options', 'code-profiler') ?></th> |
| 171 | 191 | <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> | |
| 192 | + <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') ?></label></p> | |
| 173 | 193 | |
| 174 | - <p class="description"><?php esc_html_e('Consult the FAQ tab for more details about this option.', 'code-profiler-pro') ?></p> | |
| 194 | + <p class="description"><?php esc_html_e('Consult the FAQ tab for more details about this option.', 'code-profiler') ?></p> | |
| 175 | 195 | |
| 176 | 196 | <br /> |
| 177 | 197 | |
| 178 | 198 | <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> |
| @@ -191,33 +211,84 @@ | ||
| 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)$/', $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 | - <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> | |
| 228 | + <th scope="row"><?php esc_html_e('Accuracy & Precision', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php | |
| 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'); | |
| 230 | + echo '<br />'; | |
| 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'); | |
| 232 | + ?>"></span></th> | |
| 203 | 233 | <td> |
| 204 | 234 | <p><label><?php esc_html_e('Select the accuracy and precision level of the profiler:', 'code-profiler') ?> <select name="cp_options[accuracy]"> |
| 205 | 235 | <?php |
| 206 | 236 | foreach( CODE_PROFILER_ACCURACY as $key => $value ) { |
| 207 | - 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>'; | |
| 208 | 238 | } |
| 209 | 239 | ?></select></label></p> |
| 210 | 240 | </td> |
| 211 | 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> | |
| 212 | 283 | </table> |
| 213 | 284 | |
| 214 | - <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> | |
| 215 | 286 | |
| 216 | 287 | </form> |
| 217 | 288 | <?php |
| 218 | 289 | |
| 219 | -// ===================================================================== | |
| 290 | +// ===================================================================== 2023-06-15 | |
| 220 | 291 | // Save and validate the settings. |
| 221 | 292 | |
| 222 | 293 | function code_profiler_save_settings() { |
| 223 | 294 | |
| @@ -223,9 +294,11 @@ | ||
| 223 | 294 | |
| 224 | 295 | $cp_options = get_option('code-profiler'); |
| 225 | 296 | |
| 226 | 297 | // Paths |
| 227 | - 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 | + | |
| 228 | 301 | $cp_options['show_paths'] = 'relative'; |
| 229 | 302 | } else { |
| 230 | 303 | $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] ); |
| 231 | 304 | } |
| @@ -230,9 +303,11 @@ | ||
| 230 | 303 | $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] ); |
| 231 | 304 | } |
| 232 | 305 | |
| 233 | 306 | // Name vs slug |
| 234 | - 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 | + | |
| 235 | 310 | $cp_options['display_name'] = 'full'; |
| 236 | 311 | } else { |
| 237 | 312 | $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] ); |
| 238 | 313 | } |
| @@ -237,9 +312,11 @@ | ||
| 237 | 312 | $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] ); |
| 238 | 313 | } |
| 239 | 314 | |
| 240 | 315 | // Truncate names |
| 241 | - 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 | + | |
| 242 | 319 | $cp_options['truncate_name'] = 30; |
| 243 | 320 | } else { |
| 244 | 321 | $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name']; |
| 245 | 322 | } |
| @@ -244,9 +321,11 @@ | ||
| 244 | 321 | $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name']; |
| 245 | 322 | } |
| 246 | 323 | |
| 247 | 324 | // chart type |
| 248 | - 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 | + | |
| 249 | 328 | $cp_options['chart_type'] = 'x'; |
| 250 | 329 | } else { |
| 251 | 330 | $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] ); |
| 252 | 331 | } |
| @@ -251,9 +330,11 @@ | ||
| 251 | 330 | $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] ); |
| 252 | 331 | } |
| 253 | 332 | |
| 254 | 333 | // Max plugins to display |
| 255 | - 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 | + | |
| 256 | 337 | $cp_options['chart_max_plugins'] = 25; |
| 257 | 338 | } else { |
| 258 | 339 | $cp_options['chart_max_plugins'] = (int) $_POST['cp_options']['chart_max_plugins']; |
| 259 | 340 | } |
| @@ -303,12 +384,23 @@ | ||
| 303 | 384 | $cp_options['http_response'] = "^(?:$code)\d{2}$"; |
| 304 | 385 | } |
| 305 | 386 | |
| 306 | 387 | // Accuracy |
| 307 | - if ( empty( $_POST['cp_options']['accuracy'] ) || ! preg_match('/^(?:1|5|10|15|20)$/', $_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 | + | |
| 308 | 391 | $cp_options['accuracy'] = 1; |
| 309 | 392 | } else { |
| 310 | 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']; | |
| 311 | 403 | } |
| 312 | 404 | |
| 313 | 405 | return update_option('code-profiler', $cp_options ); |
| 314 | 406 | |