PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.6.4
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.6.4
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
code-profiler / lib / menu_settings.php

menu_settings.php in Code Profiler – WordPress Performance Profiling and Debugging Made Easy 1.6.4, at lib/menu_settings.php

388 lines 15.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +=====================================================================+
4 | ____ _ ____ __ _ _ |
5 | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ |
6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 | |
10 | (c) Jerome Bruandet ~ https://code-profiler.com/ |
11 +=====================================================================+
12 */
13
14 if (! defined('ABSPATH') ) { die('Forbidden'); }
15
16 // =====================================================================
17 // Display Summary tab.
18
19 echo code_profiler_display_tabs( 3 );
20
21 // Save settings?
22 if (! empty( $_POST['save-settings'] ) ) {
23 // Make sure we have security nonce
24 if ( empty( $_POST['cp-save-settings'] ) || ! wp_verify_nonce($_POST['cp-save-settings'], 'cp_settings') ) {
25 wp_nonce_ays('cp_settings');
26 }
27 $res = code_profiler_save_settings();
28 if ( $res === true ) {
29 printf( CODE_PROFILER_UPDATE_NOTICE, esc_html__('Your changes have been saved.', 'code-profiler') );
30 }
31 else {
32 printf( CODE_PROFILER_ERROR_NOTICE, esc_html__('No changes were detected.', 'code-profiler') );
33 }
34 }
35
36 // Fetch current options
37 $cp_options = get_option('code-profiler');
38
39 ?>
40 <form method="post">
41 <?php wp_nonce_field('cp_settings', 'cp-save-settings', 0); ?>
42 <table class="form-table">
43 <?php
44
45 // Paths
46 if ( empty( $cp_options['show_paths'] ) || ! in_array( $cp_options['show_paths'], ['absolute', 'relative' ] ) ) {
47 $cp_options['show_paths'] = 'relative';
48 }
49 ?>
50 <tr>
51 <th scope="row"><?php esc_html_e('Paths','code-profiler') ?></th>
52 <td>
53 <p><label><input type="radio" name="cp_options[show_paths]"<?php checked( $cp_options['show_paths'], 'absolute') ?> value="absolute" /><?php printf( esc_html__('Show absolute paths (e.g., %s)','code-profiler'), esc_html( ABSPATH ) .'wp-admin/index.php') ?></label></p>
54 <p><label><input type="radio" name="cp_options[show_paths]"<?php checked( $cp_options['show_paths'], 'relative') ?> value="relative" /><?php printf( esc_html__('Show relative paths (e.g., %s)','code-profiler'), 'wp-admin/index.php') ?></label></p>
55 </td>
56 </tr>
57
58 <?php
59 // Name vs slug
60 if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) {
61 $cp_options['display_name'] = 'full';
62 }
63 // Truncate names
64 if ( empty( $cp_options['truncate_name'] ) || ! preg_match('/^\d+$/', ( $cp_options['truncate_name'] ) ) ) {
65 $cp_options['truncate_name'] = 30;
66 }
67 ?>
68 <tr>
69 <th scope="row"><?php esc_html_e('Plugins & Themes','code-profiler') ?></th>
70 <td>
71 <p><label><input type="radio" name="cp_options[display_name]"<?php checked( $cp_options['display_name'], 'full') ?> value="full" /><?php printf( esc_html__('Show real names (e.g., %s)','code-profiler'), 'Super Plugin Pro for WordPress') ?></label></p>
72 <p><label><input type="radio" name="cp_options[display_name]"<?php checked( $cp_options['display_name'], 'slug') ?> value="slug" /><?php printf( esc_html__('Show slugs (e.g., %s)','code-profiler'), 'super-plugin-pro') ?></label></p>
73 <br />
74 <p><label><?php
75 printf(
76 esc_html__('Truncate names to %s characters', 'code-profiler'),
77 '<input class="small-text" type="number" size="4" min="0" maxlength="100" name="cp_options[truncate_name]" value="'. (int) $cp_options['truncate_name'] .'" />'
78 );
79 ?></label></p>
80 <p class="description"><?php esc_html_e('A name longer than 30 characters will be difficult to read on most charts.', 'code-profiler') ?></p>
81 </td>
82 </tr>
83
84 <?php
85 // chart type
86 if ( empty( $cp_options['chart_type'] ) || ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) {
87 $cp_options['chart_type'] = 'x';
88 }
89 // Max plugins to display
90 if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match('/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) {
91 $cp_options['chart_max_plugins'] = 25;
92 }
93 // Empty values
94 if (! empty( $cp_options['hide_empty_value'] ) ) {
95 $cp_options['hide_empty_value'] = 1;
96 } else {
97 $cp_options['hide_empty_value'] = 0;
98 }
99 ?>
100 <tr>
101 <th scope="row"><?php esc_html_e('Tables & Charts','code-profiler') ?></th>
102 <td>
103 <p><label><input type="radio" name="cp_options[chart_type]"<?php checked( $cp_options['chart_type'], 'x') ?> value="x" /><?php esc_html_e('Display horizontal charts by default','code-profiler') ?></label></p>
104 <p><label><input type="radio" name="cp_options[chart_type]"<?php checked( $cp_options['chart_type'], 'y') ?> value="y" /><?php esc_html_e('Display vertical charts by default','code-profiler') ?></label></p>
105 <p class="description"><?php esc_html_e('You can switch between vertical and horizontal by clicking the corresponding button located below each chart.', 'code-profiler') ?></p>
106
107 <br />
108
109 <p><label><?php
110 printf(
111 esc_html__('Do not display more than %s plugins on a chart', 'code-profiler'),
112 '<input class="small-text" type="number" size="3" min="1" maxlength="100" name="cp_options[chart_max_plugins]" value="'. (int) $cp_options['chart_max_plugins'] .'" />'
113 );
114 ?></label></p>
115 <p class="description"><?php esc_html_e('More than 30 plugins will be difficult to read on most charts. Note that only plugins that have a negligible impact on your website\'s performance will be hidden.', 'code-profiler') ?></p>
116
117 <br />
118
119 <p><label><input type="checkbox" name="cp_options[hide_empty_value]"<?php checked( $cp_options['hide_empty_value'], '1') ?> /><?php esc_html_e('Hide items that have an empty value.','code-profiler') ?></label></p>
120
121 <p class="description"><?php esc_html_e('This options will hide items that have an empty value on all graphs and tables.', 'code-profiler') ?></p>
122
123 </td>
124 </tr>
125
126 <?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 // WP-CLI integration
134 if (! empty( $cp_options['enable_wpcli'] ) ) {
135 $cp_options['enable_wpcli'] = 1;
136 } else {
137 $cp_options['enable_wpcli'] = 0;
138 }
139 // Disable WP-CRON
140 if (! empty( $cp_options['disable_wpcron'] ) ) {
141 $cp_options['disable_wpcron'] = 1;
142 } else {
143 $cp_options['disable_wpcron'] = 0;
144 }
145
146 // HTTP code to reject
147 if (! empty( $cp_options['http_response'] ) ) {
148 if (! preg_match( "/{$cp_options['http_response']}/", '300') ) {
149 $http_response_300 = 0;
150 } else {
151 $http_response_300 = 1;
152 }
153 if (! preg_match( "/{$cp_options['http_response']}/", '400') ) {
154 $http_response_400 = 0;
155 } else {
156 $http_response_400 = 1;
157 }
158 if (! preg_match( "/{$cp_options['http_response']}/", '500') ) {
159 $http_response_500 = 0;
160 } else {
161 $http_response_500 = 1;
162 }
163 } else {
164 $http_response_300 = 0;
165 $http_response_400 = 0;
166 $http_response_500 = 0;
167 }
168 ?>
169 <tr>
170 <th scope="row"><?php esc_html_e('General Options', 'code-profiler') ?></th>
171 <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') ?></label></p>
173
174 <p class="description"><?php esc_html_e('Consult the FAQ tab for more details about this option.', 'code-profiler') ?></p>
175
176 <br />
177
178 <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 <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
181 <br />
182
183 <p><label><input type="checkbox" name="cp_options[disable_wpcron]"<?php checked( $cp_options['disable_wpcron'], '1') ?> /><?php esc_html_e('Disable WP-Cron when running the profiler.','code-profiler') ?></label></p>
184
185 <p class="description"><?php esc_html_e('This option will prevent WP-Cron to run scheduled tasks in the background that could affect the results of the profiler.', 'code-profiler') ?></p>
186
187 <br />
188
189 <p><?php esc_html_e('Stop the profiler and throw an error if the server returns any of the following HTTP status codes:', 'code-profiler') ?></p>
190 <p><label><input type="checkbox" name="cp_options[http_response_300]" value="1"<?php checked( $http_response_300, '1') ?> /><?php esc_html_e('3xx redirection (301 Moved Permanently, 302 Found etc)','code-profiler') ?></label></p>
191 <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 <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 </td>
194 </tr>
195 <?php
196 // Accuracy
197 if ( empty( $cp_options['accuracy'] ) || ! preg_match('/^(?:1|5|10|15|20)$/D', $cp_options['accuracy'] ) ) {
198 $cp_options['accuracy'] = 1;
199 }
200 ?>
201 <tr>
202 <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 );
207 echo '<br />';
208 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 ?>"></span></th>
210 <td>
211 <p><label><?php esc_html_e('Select the accuracy and precision level of the profiler:', 'code-profiler') ?> &nbsp;<select name="cp_options[accuracy]">
212 <?php
213 foreach( CODE_PROFILER_ACCURACY as $key => $value ) {
214 echo '<option value="'. esc_attr( $key ) .'"'. selected( $cp_options['accuracy'], $key, false ) .'>'. esc_html( $value ) .'</option>';
215 }
216 ?></select></label></p>
217 </td>
218 </tr>
219 <?php
220 $recommended = code_profiler_suggested_memory();
221 // Buffer size
222 if ( empty( $cp_options['buffer'] ) ) {
223 $cp_options['buffer'] = 0;
224 } elseif (! preg_match('/^(?:[1-9]|10)$/', $cp_options['buffer'] ) ) {
225 $cp_options['buffer'] = (int) $recommended;
226 }
227 ?>
228 <tr>
229 <th scope="row"><?php esc_html_e('Buffer size', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php
230 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 throws a PHP memory error, you can try to lower that value.', 'code-profiler');
231 ?>"></span></th>
232 <td>
233 <p>
234 <label>
235 <select name="cp_options[buffer]">
236 <?php
237 echo '<option value="0"'. selected( $cp_options['buffer'], 0, false ) .'>'.
238 esc_html__('Automatic', 'code-profiler') .
239 '</option>';
240 for ( $i = 1; $i <= 10; $i++ ) {
241 echo '<option value="'. $i .'"'. selected( $cp_options['buffer'], $i, false ) .'>'.
242 sprintf(
243 /* Translators: 'MB' for MegaBytes */
244 esc_html__('%s MB', 'code-profiler')
245 , $i ) .
246 '</option>';
247 }
248 ?>
249 </select>
250 </label>
251 </p>
252 <p class="description"><?php
253 printf(
254 esc_html__('Recommended value based on your system configuration: %s MB', 'code-profiler'),
255 (int) $recommended
256 );
257 ?></p>
258 </td>
259 </tr>
260 </table>
261
262 <p><input type="submit" name="save-settings" class="button-primary" value="<?php esc_attr_e('Save Settings', 'code-profiler') ?>" /></p>
263
264 </form>
265 <?php
266
267 // ===================================================================== 2023-06-15
268 // Save and validate the settings.
269
270 function code_profiler_save_settings() {
271
272 $cp_options = get_option('code-profiler');
273
274 // Paths
275 if ( empty( $_POST['cp_options']['show_paths'] ) ||
276 ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) {
277
278 $cp_options['show_paths'] = 'relative';
279 } else {
280 $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] );
281 }
282
283 // Name vs slug
284 if ( empty( $_POST['cp_options']['display_name'] ) ||
285 ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) {
286
287 $cp_options['display_name'] = 'full';
288 } else {
289 $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] );
290 }
291
292 // Truncate names
293 if ( empty( $_POST['cp_options']['truncate_name'] ) ||
294 ! preg_match('/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) {
295
296 $cp_options['truncate_name'] = 30;
297 } else {
298 $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name'];
299 }
300
301 // chart type
302 if ( empty( $_POST['cp_options']['chart_type'] ) ||
303 ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) {
304
305 $cp_options['chart_type'] = 'x';
306 } else {
307 $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] );
308 }
309
310 // Max plugins to display
311 if ( empty( $_POST['cp_options']['chart_max_plugins'] ) ||
312 ! preg_match('/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) {
313
314 $cp_options['chart_max_plugins'] = 25;
315 } else {
316 $cp_options['chart_max_plugins'] = (int) $_POST['cp_options']['chart_max_plugins'];
317 }
318
319 // Empty values
320 if (! empty( $_POST['cp_options']['hide_empty_value'] ) ) {
321 $cp_options['hide_empty_value'] = 1;
322 } else {
323 $cp_options['hide_empty_value'] = 0;
324 }
325
326 // Composer warning
327 if (! empty( $_POST['cp_options']['warn_composer'] ) ) {
328 $cp_options['warn_composer'] = 1;
329 } else {
330 $cp_options['warn_composer'] = 0;
331 }
332
333 // WP-CLI integration
334 if (! empty( $_POST['cp_options']['enable_wpcli'] ) ) {
335 $cp_options['enable_wpcli'] = 1;
336 } else {
337 $cp_options['enable_wpcli'] = 0;
338 }
339
340 // WP-Cron
341 if (! empty( $_POST['cp_options']['disable_wpcron'] ) ) {
342 $cp_options['disable_wpcron'] = 1;
343 } else {
344 $cp_options['disable_wpcron'] = 0;
345 }
346
347 // HTTP status code
348 $code = '';
349 $cp_options['http_response'] = '';
350 if (! empty( $_POST['cp_options']['http_response_300'] ) ) {
351 $code .= '3|';
352 }
353 if (! empty( $_POST['cp_options']['http_response_400'] ) ) {
354 $code .= '4|';
355 }
356 if (! empty( $_POST['cp_options']['http_response_500'] ) ) {
357 $code .= '5';
358 }
359 $code = rtrim( $code, '|');
360 if (! empty( $code ) ) {
361 $cp_options['http_response'] = "^(?:$code)\d{2}$";
362 }
363
364 // Accuracy
365 if ( empty( $_POST['cp_options']['accuracy'] ) ||
366 ! preg_match('/^(?:1|5|10|15|20)$/D', $_POST['cp_options']['accuracy'] ) ) {
367
368 $cp_options['accuracy'] = 1;
369 } else {
370 $cp_options['accuracy'] = (int) $_POST['cp_options']['accuracy'];
371 }
372
373 // Buffer size
374 if ( empty( $_POST['cp_options']['buffer'] ) ) {
375 $cp_options['buffer'] = 0;
376 } elseif (! preg_match('/^(?:[1-9]|10)$/D', $_POST['cp_options']['buffer'] ) ) {
377 $cp_options['buffer'] = 10;
378 } else {
379 $cp_options['buffer'] = (int) $_POST['cp_options']['buffer'];
380 }
381
382 return update_option('code-profiler', $cp_options );
383
384 }
385
386 // =====================================================================
387 // EOF
388