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

282 lines 11.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 <h3><?php esc_html_e('General Settings', 'code-profiler') ?></h3>
41
42 <form method="post">
43 <?php wp_nonce_field('cp_settings', 'cp-save-settings', 0); ?>
44 <table class="form-table">
45 <?php
46
47 // Paths
48 if ( empty( $cp_options['show_paths'] ) || ! in_array( $cp_options['show_paths'], ['absolute', 'relative' ] ) ) {
49 $cp_options['show_paths'] = 'relative';
50 }
51 ?>
52 <tr>
53 <th scope="row"><?php esc_html_e('Paths','code-profiler') ?></th>
54 <td>
55 <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>
56 <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>
57 </td>
58 </tr>
59
60 <?php
61 // Name vs slug
62 if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) {
63 $cp_options['display_name'] = 'full';
64 }
65 // Truncate names
66 if ( empty( $cp_options['truncate_name'] ) || ! preg_match( '/^\d+$/', ( $cp_options['truncate_name'] ) ) ) {
67 $cp_options['truncate_name'] = 30;
68 }
69 ?>
70 <tr>
71 <th scope="row"><?php esc_html_e('Plugins & Themes','code-profiler') ?></th>
72 <td>
73 <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>
74 <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>
75 <br />
76 <p><label><?php
77 printf(
78 esc_html__('Truncate names to %s characters', 'code-profiler'),
79 '<input class="small-text" type="number" size="4" min="0" maxlength="100" name="cp_options[truncate_name]" value="'. (int) $cp_options['truncate_name'] .'" />'
80 );
81 ?></label></p>
82 <p class="description"><?php esc_html_e('A name longer than 30 characters will be difficult to read on most charts.', 'code-profiler') ?></p>
83 </td>
84 </tr>
85
86 <?php
87 // chart type
88 if ( empty( $cp_options['chart_type'] ) || ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) {
89 $cp_options['chart_type'] = 'x';
90 }
91 // Max plugins to display
92 if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match( '/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) {
93 $cp_options['chart_max_plugins'] = 25;
94 }
95 // Empty values
96 if (! empty( $cp_options['hide_empty_value'] ) ) {
97 $cp_options['hide_empty_value'] = 1;
98 } else {
99 $cp_options['hide_empty_value'] = 0;
100 }
101 ?>
102 <tr>
103 <th scope="row"><?php esc_html_e('Tables & Charts','code-profiler') ?></th>
104 <td>
105 <p><label><input type="radio" name="cp_options[chart_type]"<?php checked( $cp_options['chart_type'], 'x' ) ?> value="x" /><?php printf( esc_html__('Display horizontal charts by default','code-profiler'), 'Super Plugin Pro for WordPress' ) ?></label></p>
106 <p><label><input type="radio" name="cp_options[chart_type]"<?php checked( $cp_options['chart_type'], 'y' ) ?> value="y" /><?php printf( esc_html__('Display vertical charts by default','code-profiler'), 'super-plugin-pro' ) ?></label></p>
107 <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>
108
109 <br />
110
111 <p><label><?php
112 printf(
113 esc_html__('Do not display more than %s plugins on a chart', 'code-profiler'),
114 '<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'] .'" />'
115 );
116 ?></label></p>
117 <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>
118
119 <br />
120
121 <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>
122
123 <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>
124
125 </td>
126 </tr>
127
128 <?php
129 // WP-CLI integration
130 if (! empty( $cp_options['enable_wpcli'] ) ) {
131 $cp_options['enable_wpcli'] = 1;
132 } else {
133 $cp_options['enable_wpcli'] = 0;
134 }
135 // Disable WP-CRON
136 if (! empty( $cp_options['disable_wpcron'] ) ) {
137 $cp_options['disable_wpcron'] = 1;
138 } else {
139 $cp_options['disable_wpcron'] = 0;
140 }
141
142 // HTTP code to reject
143 if (! empty( $cp_options['http_response'] ) ) {
144 if (! preg_match( "/{$cp_options['http_response']}/", '300' ) ) {
145 $http_response_300 = 0;
146 } else {
147 $http_response_300 = 1;
148 }
149 if (! preg_match( "/{$cp_options['http_response']}/", '400' ) ) {
150 $http_response_400 = 0;
151 } else {
152 $http_response_400 = 1;
153 }
154 if (! preg_match( "/{$cp_options['http_response']}/", '500' ) ) {
155 $http_response_500 = 0;
156 } else {
157 $http_response_500 = 1;
158 }
159 } else {
160 $http_response_300 = 0;
161 $http_response_400 = 0;
162 $http_response_500 = 0;
163 }
164 ?>
165 <tr>
166 <th scope="row"><?php esc_html_e('Various', 'code-profiler') ?></th>
167 <td>
168 <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>
169 <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>
170
171 <br />
172
173 <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>
174
175 <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>
176
177 <br />
178
179 <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>
180 <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>
181 <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>
182 <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>
183 </td>
184 </tr>
185
186 </table>
187
188 <p><input type="submit" name="save-settings" class="button-primary" value="<?php esc_html_e('Save Settings', 'code-profiler') ?>" /></p>
189
190 </form>
191 <?php
192
193 // =====================================================================
194 // Save and validate the settings.
195
196 function code_profiler_save_settings() {
197
198 $cp_options = get_option( 'code-profiler' );
199
200 // Paths
201 if ( empty( $_POST['cp_options']['show_paths'] ) || ! in_array( $_POST['cp_options']['show_paths'], ['absolute', 'relative' ] ) ) {
202 $cp_options['show_paths'] = 'relative';
203 } else {
204 $cp_options['show_paths'] = sanitize_key( $_POST['cp_options']['show_paths'] );
205 }
206
207 // Name vs slug
208 if ( empty( $_POST['cp_options']['display_name'] ) || ! in_array( $_POST['cp_options']['display_name'], ['full', 'slug' ] ) ) {
209 $cp_options['display_name'] = 'full';
210 } else {
211 $cp_options['display_name'] = sanitize_key( $_POST['cp_options']['display_name'] );
212 }
213
214 // Truncate names
215 if ( empty( $_POST['cp_options']['truncate_name'] ) || ! preg_match( '/^\d+$/', ( $_POST['cp_options']['truncate_name'] ) ) ) {
216 $cp_options['truncate_name'] = 30;
217 } else {
218 $cp_options['truncate_name'] = (int) $_POST['cp_options']['truncate_name'];
219 }
220
221 // chart type
222 if ( empty( $_POST['cp_options']['chart_type'] ) || ! in_array( $_POST['cp_options']['chart_type'], ['x', 'y' ] ) ) {
223 $cp_options['chart_type'] = 'x';
224 } else {
225 $cp_options['chart_type'] = sanitize_key( $_POST['cp_options']['chart_type'] );
226 }
227
228 // Max plugins to display
229 if ( empty( $_POST['cp_options']['chart_max_plugins'] ) || ! preg_match( '/^\d+$/', ( $_POST['cp_options']['chart_max_plugins'] ) ) ) {
230 $cp_options['chart_max_plugins'] = 25;
231 } else {
232 $cp_options['chart_max_plugins'] = (int) $_POST['cp_options']['chart_max_plugins'];
233 }
234
235 // Empty values
236 if (! empty( $_POST['cp_options']['hide_empty_value'] ) ) {
237 $cp_options['hide_empty_value'] = 1;
238 } else {
239 $cp_options['hide_empty_value'] = 0;
240 }
241
242 // Composer warning
243 $cp_options['warn_composer'] = 1;
244
245 // WP-CLI integration
246 if (! empty( $_POST['cp_options']['enable_wpcli'] ) ) {
247 $cp_options['enable_wpcli'] = 1;
248 } else {
249 $cp_options['enable_wpcli'] = 0;
250 }
251
252 // WP-Cron
253 if (! empty( $_POST['cp_options']['disable_wpcron'] ) ) {
254 $cp_options['disable_wpcron'] = 1;
255 } else {
256 $cp_options['disable_wpcron'] = 0;
257 }
258
259 // HTTP status code
260 $code = '';
261 $cp_options['http_response'] = '';
262 if (! empty( $_POST['cp_options']['http_response_300'] ) ) {
263 $code .= '3|';
264 }
265 if (! empty( $_POST['cp_options']['http_response_400'] ) ) {
266 $code .= '4|';
267 }
268 if (! empty( $_POST['cp_options']['http_response_500'] ) ) {
269 $code .= '5';
270 }
271 $code = rtrim( $code, '|' );
272 if (! empty( $code ) ) {
273 $cp_options['http_response'] = "^(?:$code)\d{2}$";
274 }
275
276 return update_option( 'code-profiler', $cp_options );
277
278 }
279
280 // =====================================================================
281 // EOF
282