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

279 lines 11.4 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 // WP-CLI integration
128 if (! empty( $cp_options['enable_wpcli'] ) ) {
129 $cp_options['enable_wpcli'] = 1;
130 } else {
131 $cp_options['enable_wpcli'] = 0;
132 }
133 // Disable WP-CRON
134 if (! empty( $cp_options['disable_wpcron'] ) ) {
135 $cp_options['disable_wpcron'] = 1;
136 } else {
137 $cp_options['disable_wpcron'] = 0;
138 }
139
140 // HTTP code to reject
141 if (! empty( $cp_options['http_response'] ) ) {
142 if (! preg_match( "/{$cp_options['http_response']}/", '300' ) ) {
143 $http_response_300 = 0;
144 } else {
145 $http_response_300 = 1;
146 }
147 if (! preg_match( "/{$cp_options['http_response']}/", '400' ) ) {
148 $http_response_400 = 0;
149 } else {
150 $http_response_400 = 1;
151 }
152 if (! preg_match( "/{$cp_options['http_response']}/", '500' ) ) {
153 $http_response_500 = 0;
154 } else {
155 $http_response_500 = 1;
156 }
157 } else {
158 $http_response_300 = 0;
159 $http_response_400 = 0;
160 $http_response_500 = 0;
161 }
162 ?>
163 <tr>
164 <th scope="row"><?php esc_html_e('Various', 'code-profiler') ?></th>
165 <td>
166 <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>
167 <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>
168
169 <br />
170
171 <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>
172
173 <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>
174
175 <br />
176
177 <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>
178 <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>
179 <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>
180 <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>
181 </td>
182 </tr>
183 </table>
184
185 <p><input type="submit" name="save-settings" class="button-primary" value="<?php esc_attr_e('Save Settings', 'code-profiler') ?>" /></p>
186
187 </form>
188 <?php
189
190 // =====================================================================
191 // Save and validate the settings.
192
193 function code_profiler_save_settings() {
194
195 $cp_options = get_option( 'code-profiler' );
196
197 // Paths
198 if ( empty( $_POST['cp_options']['show_paths'] ) || ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) {
199 $cp_options['show_paths'] = 'relative';
200 } else {
201 $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] );
202 }
203
204 // Name vs slug
205 if ( empty( $_POST['cp_options']['display_name'] ) || ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) {
206 $cp_options['display_name'] = 'full';
207 } else {
208 $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] );
209 }
210
211 // Truncate names
212 if ( empty( $_POST['cp_options']['truncate_name'] ) || ! preg_match( '/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) {
213 $cp_options['truncate_name'] = 30;
214 } else {
215 $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name'];
216 }
217
218 // chart type
219 if ( empty( $_POST['cp_options']['chart_type'] ) || ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) {
220 $cp_options['chart_type'] = 'x';
221 } else {
222 $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] );
223 }
224
225 // Max plugins to display
226 if ( empty( $_POST['cp_options']['chart_max_plugins'] ) || ! preg_match( '/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) {
227 $cp_options['chart_max_plugins'] = 25;
228 } else {
229 $cp_options['chart_max_plugins'] = (int) $_POST['cp_options']['chart_max_plugins'];
230 }
231
232 // Empty values
233 if (! empty( $_POST['cp_options']['hide_empty_value'] ) ) {
234 $cp_options['hide_empty_value'] = 1;
235 } else {
236 $cp_options['hide_empty_value'] = 0;
237 }
238
239 // Composer warning
240 $cp_options['warn_composer'] = 1;
241
242 // WP-CLI integration
243 if (! empty( $_POST['cp_options']['enable_wpcli'] ) ) {
244 $cp_options['enable_wpcli'] = 1;
245 } else {
246 $cp_options['enable_wpcli'] = 0;
247 }
248
249 // WP-Cron
250 if (! empty( $_POST['cp_options']['disable_wpcron'] ) ) {
251 $cp_options['disable_wpcron'] = 1;
252 } else {
253 $cp_options['disable_wpcron'] = 0;
254 }
255
256 // HTTP status code
257 $code = '';
258 $cp_options['http_response'] = '';
259 if (! empty( $_POST['cp_options']['http_response_300'] ) ) {
260 $code .= '3|';
261 }
262 if (! empty( $_POST['cp_options']['http_response_400'] ) ) {
263 $code .= '4|';
264 }
265 if (! empty( $_POST['cp_options']['http_response_500'] ) ) {
266 $code .= '5';
267 }
268 $code = rtrim( $code, '|' );
269 if (! empty( $code ) ) {
270 $cp_options['http_response'] = "^(?:$code)\d{2}$";
271 }
272
273 return update_option( 'code-profiler', $cp_options );
274
275 }
276
277 // =====================================================================
278 // EOF
279