PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.7.4
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.7.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
← All changes | lib/menu_profiler.php +96 -16 1.61.7.4 View file →
@@ -6,9 +6,9 @@
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 14 if (! defined('ABSPATH') ) { die('Forbidden'); }
@@ -42,8 +42,11 @@
42 42
43 43 // Clear the log if it's too big
44 44 code_profiler_clearlog();
45 45
46 +// Clean-up temp files left in the profiles folder
47 +code_profiler_cleantmpfiles();
48 +
46 49 $home = home_url('/'); // Frontend
47 50 $site = site_url('/'); // Backend
48 51 // Get user login name
49 52 $current_user = wp_get_current_user();
@@ -66,19 +69,38 @@
66 69 }
67 70 if ( empty( $cp_options['mem_method'] ) ) {
68 71 $cp_options['mem_method'] = 'get';
69 72 }
73 +$default_theme = get_option('stylesheet');
74 +if ( empty( $cp_options['mem_theme'] ) ) {
75 + $cp_options['mem_theme'] = $default_theme;
76 +}
70 77 if ( empty( $cp_options['ua'] ) ) {
71 78 $cp_options['ua'] = 'Firefox';
72 79 }
73 -$cookies = '';
74 -$payload = '';
80 +$cookies = '';
81 +$payload = '';
82 +$custom_headers = '';
83 +$exclusions = [];
84 +
75 85 if ( isset( $cp_options['cookies'] ) ) {
76 - $cookies = trim( json_decode( $cp_options['cookies'] ) );
86 + // stripslashes is only needed for cookies
87 + $cookies = trim( stripslashes( json_decode( $cp_options['cookies'] ) ) );
77 88 }
89 +if ( empty( $cp_options['mem_content_type'] ) ||
90 + ! in_array( $cp_options['mem_content_type'], [ 1, 2 ] ) ) {
91 +
92 + $cp_options['mem_content_type'] = 1;
93 +}
78 94 if ( isset( $cp_options['payload'] ) ) {
79 - $payload = trim( json_decode( $cp_options['payload'] ) );
95 + $payload = trim( json_decode( $cp_options['payload'] ) );
80 96 }
97 +if ( isset( $cp_options['custom_headers'] ) ) {
98 + $custom_headers = trim( json_decode( $cp_options['custom_headers'] ) );
99 +}
100 +if ( isset( $cp_options['exclusions'] ) ) {
101 + $exclusions = json_decode( $cp_options['exclusions'] );
102 +}
81 103 ?>
82 104 <table class="form-table">
83 105 <tr>
84 106 <th scope="row"><?php esc_html_e('Page to profile', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Select the page you want the profiler to analyze. It can be in the frontend of the site, in the admin backend or a custom URL.', 'code-profiler') ?>"></span></th>
@@ -136,9 +158,9 @@
136 158 </p>
137 159 </td>
138 160 </tr>
139 161 <tr>
140 - <th scope="row"><?php esc_html_e('Run profiler as', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('The profiler can access the requested page as an unauthenticated user (frontend only) or as an authenticated user (frontend and backend). You can enter the login name of any registered user, but make sure that the user has the required capability to access the page you are going to profile (e.g. an admin page in the backend), otherwise Code Profiler will return an error if the user isn\'t allowed to access it.', 'code-profiler') ?>"></span></th>
162 + <th scope="row"><?php esc_html_e('Run profiler as', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('The profiler can access the requested page as an unauthenticated user (frontend only) or as an authenticated user (frontend and backend). You can enter the login name of any registered user, but make sure that the user has the required capability to access the page you are going to profile, otherwise Code Profiler will return an error if the user isn\'t allowed to access it.', 'code-profiler') ?>"></span></th>
141 163 <td>
142 164 <p><label><input type="radio" onclick="cpjs_authenticated(0);" name="user" value="unauthenticated" id="user-unauthenticated"<?php checked( $cp_options['mem_user'], 'unauthenticated'); disabled( $cp_options['mem_where'], 'backend'); ?> /> <?php esc_html_e('Unauthenticated user', 'code-profiler') ?></label></p>
143 165 <p><label><input type="radio" onclick="cpjs_authenticated(1);" name="user" value="authenticated" id="user-authenticated"<?php checked( $cp_options['mem_user'], 'authenticated') ?> /> <?php esc_html_e('Authenticated user', 'code-profiler') ?></label></p>
144 166 <p><label><?php esc_html_e('User:', 'code-profiler') ?> <input type="text" name="username" id="user-name" value ="<?php esc_attr_e( $username ) ?>"<?php disabled( $cp_options['mem_user'], 'unauthenticated') ?> /></label></p>
@@ -144,8 +166,27 @@
144 166 <p><label><?php esc_html_e('User:', 'code-profiler') ?> <input type="text" name="username" id="user-name" value ="<?php esc_attr_e( $username ) ?>"<?php disabled( $cp_options['mem_user'], 'unauthenticated') ?> /></label></p>
145 167 </td>
146 168 </tr>
147 169 <tr>
170 + <th scope="row"><?php esc_html_e('Theme', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('If you want to profile different themes, you can use this option so that you don\'t need to modify your WordPress settings. The change will not affect your visitors, but only the profiler when it is running.', 'code-profiler') ?>"></span></th>
171 + <td>
172 + <select name="theme" id="id-theme">
173 + <?php
174 + $themes = code_profiler_get_themes();
175 + foreach( $themes as $slug => $name ) {
176 + if ( $slug == $default_theme ) {
177 + echo '<option value=""'. selected( $cp_options['mem_theme'], $slug, false ) .'>'.
178 + esc_html( $name['n'] ) .' '. __('(active theme)', 'code-profiler') .'</option>';
179 + } else {
180 + echo '<option value="'. esc_attr( $slug ) .'"'. selected( $cp_options['mem_theme'], $slug, false ) .'>'.
181 + esc_html( $name['n'] ) .'</option>';
182 + }
183 + }
184 + ?>
185 + </select>
186 + </td>
187 + </tr>
188 + <tr>
148 189 <th scope="row"><?php esc_html_e('User agent', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Some themes and plugins may execute different code depending on the type of device used to visit the website (e.g., a desktop computer, a mobile phone, a search engine bot etc). This option lets you change the User-Agent request header used by Code Profiler.', 'code-profiler') ?>"></span></th>
149 190 <td>
150 191 <select name="ua" id="ua-id">
151 192 <?php
@@ -151,9 +192,9 @@
151 192 <?php
152 193 foreach( CODE_PROFILER_UA as $types => $types_array ) {
153 194 echo '<optgroup label="'. esc_attr( $types ) .'">';
154 195 foreach( $types_array as $name => $value ) {
155 - echo '<option value="'. esc_attr( $name ) .'"'. selected( $cp_options['ua'], $name ) .'>'. esc_html( $name ) .'</option>';
196 + echo '<option value="'. esc_attr( $name ) .'"'. selected( $cp_options['ua'], $name, false ) .'>'. esc_html( $name ) .'</option>';
156 197 }
157 198 echo '</optgroup>';
158 199 }
159 200 ?>
@@ -168,9 +209,9 @@
168 209 </td>
169 210 </tr>
170 211 </table>
171 212 <?php
172 -if (! empty( $cookies ) || $cp_options['mem_method'] == 'post') {
213 +if (! empty( $cookies ) || ! empty( $custom_headers ) || $cp_options['mem_method'] == 'post' || ! empty( $exclusions ) ) {
173 214 echo '<div id="cp-advanced-settings">';
174 215 $disabled_button = ' disabled';
175 216 } else {
176 217 echo '<div id="cp-advanced-settings" style="display:none">';
@@ -180,12 +221,34 @@
180 221 <table class="form-table">
181 222 <tr>
182 223 <th scope="row"><?php esc_html_e('HTTP Method', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('You can select which HTTP method will be used by the profiler: GET or POST. If you select POST, you can also send an optional payload.', 'code-profiler') ?>"></span></th>
183 224 <td>
184 - <p><label><input onclick="cpjs_get_post(0);" type="radio" name="method" value="get" id="get-method"<?php checked( $cp_options['mem_method'], 'get') ?> /> <?php esc_html_e('GET (default)', 'code-profiler') ?></label></p>
185 - <p><label><input onclick="cpjs_get_post(1);" type="radio" name="method" value="post" id="post-method"<?php checked( $cp_options['mem_method'], 'post') ?> /> POST</label></p>
186 - <p><textarea name="post-value" id="post-value" class="regular-text code"<?php disabled( $cp_options['mem_method'], 'get') ?> maxlength="4000" rows="6"><?php echo esc_textarea( $payload ) ?></textarea></p>
187 - <p class="description"><?php printf( esc_html__('Optional POST payload in %s format, one item per line.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/http_method.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?> </p>
225 + <p>
226 + <label>
227 + <input onclick="cpjs_get_post(0);" type="radio" name="method" value="get" id="get-method"<?php checked( $cp_options['mem_method'], 'get') ?> /> GET(<?php esc_html_e('default', 'code-profiler') ?>)
228 + </label>
229 + </p>
230 + <p>
231 + <label>
232 + <input onclick="cpjs_get_post(1);" type="radio" name="method" value="post" id="post-method"<?php checked( $cp_options['mem_method'], 'post') ?> /> POST
233 + </label>
234 + </p>
235 + <p>
236 + <?php esc_html_e('Content-type:', 'code-profiler') ?>
237 + <select name="cp-content-type" id="id-content-type"<?php disabled( $cp_options['mem_method'], 'get') ?> onChange="cpjs_content_type(this.value);">
238 + <option value="1"<?php selected( $cp_options['mem_content_type'], 1 )?>>application/x-www-form-urlencoded (<?php esc_html_e('default', 'code-profiler') ?>)</option>
239 + <option value="2"<?php selected( $cp_options['mem_content_type'], 2 )?>>application/json</option>
240 + </select>
241 + </p>
242 + <p>
243 + <textarea name="post-value" id="post-value" class="regular-text code"<?php disabled( $cp_options['mem_method'], 'get') ?> maxlength="4000" rows="6"><?php echo esc_textarea( $payload ) ?></textarea>
244 + </p>
245 + <p class="description" id="ct-1"<?php echo code_profiler_hide( $cp_options['mem_content_type'], 2) ?>>
246 + <?php printf( esc_html__('Optional POST payload in %s format, one item per line.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/http_method-1.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?>
247 + </p>
248 + <p class="description" id="ct-2"<?php echo code_profiler_hide( $cp_options['mem_content_type'], 1) ?>>
249 + <?php printf( esc_html__('Optional JSON-encoded payload.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/http_method-2.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?>
250 + </p>
188 251 </td>
189 252 </tr>
190 253 <tr>
191 254 <th scope="row"><?php esc_html_e('Cookie', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Some websites may execute different code if the user has one or more specific cookies. You can use this field for that purpose.', 'code-profiler') ?>"></span></th>
@@ -193,16 +256,34 @@
193 256 <p><textarea name="cp-cookies" id="cp-cookies" class="regular-text code" maxlength="4000" rows="6"><?php echo esc_textarea( $cookies ) ?></textarea></p>
194 257 <p class="description"><?php printf( esc_html__('Optional cookie in %s format, one item per line.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/cookies.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?></p>
195 258 </td>
196 259 </tr>
260 + <tr>
261 + <th scope="row" class="row-med"><?php esc_html_e('HTTP headers', 'code-profiler'); ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('You can use this field to add custom HTTP headers or even override existing ones (e.g., host, user-agent, accept-language etc). HTTP header names are case-insensitive and Code Profiler will automatically convert them to lowercase. HTTP header values are case-sensitive and only ASCII printable characters are allowed.', 'code-profiler') ?>"></span></th>
262 + <td>
263 + <textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" id="custom-headers" name="custom_headers" class="regular-text code" rows="6"><?php echo esc_textarea( $custom_headers ) ?></textarea>
264 + <p class="description"><?php printf( esc_html__('Optional HTTP header in %s format, one item per line.', 'code-profiler'), '<code>name: value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/custom_headers.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?></p>
265 + </td>
266 + </tr>
267 + <tr>
268 + <th scope="row" class="row-med"><?php esc_html_e('File and folder exclusions', 'code-profiler'); ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('This option lets you exclude files and folders from the profiling process. It can be a full path, a file or a folder name, or any part of them (substring). Values are case-sensitive and only ASCII printable characters are allowed.', 'code-profiler') ?>"></span></th>
269 + <td>
270 + <textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" id="exclusions" name="exclusions" class="regular-text code" rows="6"><?php
271 + foreach( $exclusions as $item ) {
272 + echo esc_textarea( $item ) ."\n";
273 + }
274 + ?></textarea>
275 + <p class="description"><?php esc_html_e('One item per line.', 'code-profiler') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/exclusions.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?></p>
276 + </td>
277 + </tr>
197 278 </table>
198 279 </div>
199 280 <?php wp_nonce_field('start_profiler_nonce', 'cp_nonce', 0); ?>
200 281 <br />
201 282 <div>
202 - <input type="button" class="button-secondary" id="button-adv-settings" name="adv-settings" value="<?php esc_attr_e('Advanced Options', 'code-profiler') ?>" onclick="cpjs_show_adv_settings();"<?php echo $disabled_button ?> />
283 + <input type="button" class="button button-secondary" id="button-adv-settings" name="adv-settings" value="<?php esc_attr_e('Advanced Options', 'code-profiler') ?>" onclick="cpjs_show_adv_settings();"<?php echo $disabled_button ?> />
203 284 &nbsp;&nbsp;&nbsp;
204 - <input type="button" class="button-primary" id="start-profile" name="start-profile" onClick="cpjs_start_profiler();" value="<?php esc_attr_e('Start Profiling', 'code-profiler') ?> »" title="<?php esc_attr_e('Click to start profiling your code.', 'code-profiler') ?>" />
285 + <input type="button" class="button button-primary" id="start-profile" name="start-profile" onClick="cpjs_start_profiler();" value="<?php esc_attr_e('Start Profiling', 'code-profiler') ?> »" title="<?php esc_attr_e('Click to start profiling your code.', 'code-profiler') ?>" />
205 286 </div>
206 287 <div id="cp-progress-div" style="display:none">
207 288 <br />
208 289 <div class="cp-progress-bar"><span id="cp-span-progress" style="width:0%"></span></div>
@@ -288,9 +369,9 @@
288 369 if (! empty( $GLOBALS[ 'menu' ] ) ) {
289 370 foreach( $GLOBALS[ 'menu' ] as $menu => $value ) {
290 371 if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php') {
291 372 // E.g., "Comments", "Plugins" etc
292 - $value[0] = trim( preg_replace('/\s+<.+$/', '', $value[0] ) );
373 + $value[0] = trim( preg_replace('/\s*<.+$/', '', $value[0] ) );
293 374
294 375 if ( $cp_options['mem_post'] == "{$home}wp-admin/{$value[2]}" ) {
295 376 $backend .= sprintf(
296 377 '<option value="%1$s" title="%1$s" selected>%2$s</option>',
@@ -314,9 +395,8 @@
314 395 esc_html__('Dashboard', 'code-profiler')
315 396 );
316 397
317 398 }
318 -
319 399 return $backend;
320 400 }
321 401
322 402 // =====================================================================