PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.5
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.5
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.5, at lib/menu_settings.php

319 lines 13.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-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 <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)$/', $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 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>
203 <td>
204 <p><label><?php esc_html_e('Select the accuracy and precision level of the profiler:', 'code-profiler') ?> &nbsp;<select name="cp_options[accuracy]">
205 <?php
206 foreach( CODE_PROFILER_ACCURACY as $key => $value ) {
207 echo '<option value="'. esc_attr( $key ) .'"'. selected( $cp_options['accuracy'], $key ) .'>'. esc_html( $value ) .'</option>';
208 }
209 ?></select></label></p>
210 </td>
211 </tr>
212 </table>
213
214 <p><input type="submit" name="save-settings" class="button-primary" value="<?php esc_attr_e('Save Settings', 'code-profiler') ?>" /></p>
215
216 </form>
217 <?php
218
219 // =====================================================================
220 // Save and validate the settings.
221
222 function code_profiler_save_settings() {
223
224 $cp_options = get_option('code-profiler');
225
226 // Paths
227 if ( empty( $_POST['cp_options']['show_paths'] ) || ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) {
228 $cp_options['show_paths'] = 'relative';
229 } else {
230 $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] );
231 }
232
233 // Name vs slug
234 if ( empty( $_POST['cp_options']['display_name'] ) || ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) {
235 $cp_options['display_name'] = 'full';
236 } else {
237 $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] );
238 }
239
240 // Truncate names
241 if ( empty( $_POST['cp_options']['truncate_name'] ) || ! preg_match('/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) {
242 $cp_options['truncate_name'] = 30;
243 } else {
244 $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name'];
245 }
246
247 // chart type
248 if ( empty( $_POST['cp_options']['chart_type'] ) || ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) {
249 $cp_options['chart_type'] = 'x';
250 } else {
251 $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] );
252 }
253
254 // Max plugins to display
255 if ( empty( $_POST['cp_options']['chart_max_plugins'] ) || ! preg_match('/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) {
256 $cp_options['chart_max_plugins'] = 25;
257 } else {
258 $cp_options['chart_max_plugins'] = (int) $_POST['cp_options']['chart_max_plugins'];
259 }
260
261 // Empty values
262 if (! empty( $_POST['cp_options']['hide_empty_value'] ) ) {
263 $cp_options['hide_empty_value'] = 1;
264 } else {
265 $cp_options['hide_empty_value'] = 0;
266 }
267
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 // WP-CLI integration
276 if (! empty( $_POST['cp_options']['enable_wpcli'] ) ) {
277 $cp_options['enable_wpcli'] = 1;
278 } else {
279 $cp_options['enable_wpcli'] = 0;
280 }
281
282 // WP-Cron
283 if (! empty( $_POST['cp_options']['disable_wpcron'] ) ) {
284 $cp_options['disable_wpcron'] = 1;
285 } else {
286 $cp_options['disable_wpcron'] = 0;
287 }
288
289 // HTTP status code
290 $code = '';
291 $cp_options['http_response'] = '';
292 if (! empty( $_POST['cp_options']['http_response_300'] ) ) {
293 $code .= '3|';
294 }
295 if (! empty( $_POST['cp_options']['http_response_400'] ) ) {
296 $code .= '4|';
297 }
298 if (! empty( $_POST['cp_options']['http_response_500'] ) ) {
299 $code .= '5';
300 }
301 $code = rtrim( $code, '|');
302 if (! empty( $code ) ) {
303 $cp_options['http_response'] = "^(?:$code)\d{2}$";
304 }
305
306 // Accuracy
307 if ( empty( $_POST['cp_options']['accuracy'] ) || ! preg_match('/^(?:1|5|10|15|20)$/', $_POST['cp_options']['accuracy'] ) ) {
308 $cp_options['accuracy'] = 1;
309 } else {
310 $cp_options['accuracy'] = (int) $_POST['cp_options']['accuracy'];
311 }
312
313 return update_option('code-profiler', $cp_options );
314
315 }
316
317 // =====================================================================
318 // EOF
319