PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.6
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 +71 -46 1.51.6 View file →
@@ -10,9 +10,9 @@
10 10 | (c) Jerome Bruandet ~ https://code-profiler.com/ |
11 11 +=====================================================================+
12 12 */
13 13
14 -if (! defined( 'ABSPATH' ) ) { die( 'Forbidden' ); }
14 +if (! defined('ABSPATH') ) { die('Forbidden'); }
15 15
16 16 // =====================================================================
17 17 // Display Summary tab.
18 18
@@ -38,15 +38,20 @@
38 38 printf( CODE_PROFILER_ERROR_NOTICE, sprintf(
39 39 esc_html__('The following folder is not writable: %s. Please change its permissions or ownership so that Code Profiler can write to it.', 'code-profiler'), CODE_PROFILER_UPLOAD_DIR )
40 40 );
41 41 }
42 -$home = home_url( '/' );
42 +
43 +// Clear the log if it's too big
44 +code_profiler_clearlog();
45 +
46 +$home = home_url('/'); // Frontend
47 +$site = site_url('/'); // Backend
43 48 // Get user login name
44 49 $current_user = wp_get_current_user();
45 50 // Profile's name
46 51 $profile = code_profiler_profile_name();
47 52
48 -$cp_options = get_option( 'code-profiler' );
53 +$cp_options = get_option('code-profiler');
49 54 // Memorized options
50 55 if ( empty( $cp_options['mem_where'] ) ) {
51 56 $cp_options['mem_where'] = 'frontend';
52 57 }
@@ -55,9 +60,9 @@
55 60 }
56 61 if ( empty( $cp_options['mem_user'] ) ) {
57 62 $cp_options['mem_user'] = 'unauthenticated';
58 63 }
59 -if ( $cp_options['mem_where'] == 'backend' ) {
64 +if ( $cp_options['mem_where'] == 'backend') {
60 65 $cp_options['mem_user'] = 'authenticated';
61 66 }
62 67 if ( empty( $cp_options['mem_method'] ) ) {
63 68 $cp_options['mem_method'] = 'get';
@@ -75,19 +80,19 @@
75 80 }
76 81 ?>
77 82 <table class="form-table">
78 83 <tr>
79 - <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>
84 + <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>
80 85 <td>
81 - <p><label><input type="radio" name="where" value="frontend" onclick="cpjs_front_or_backend(1);"<?php checked( $cp_options['mem_where'], 'frontend' ) ?> /> <?php esc_html_e('Website frontend', 'code-profiler') ?></label>
86 + <p><label><input type="radio" name="where" value="frontend" onclick="cpjs_front_or_backend(1);"<?php checked( $cp_options['mem_where'], 'frontend') ?> /> <?php esc_html_e('Website frontend', 'code-profiler') ?></label>
82 87 &nbsp;&nbsp;&nbsp;&nbsp;
83 - <label><input type="radio" name="where" value="custom" onclick="cpjs_front_or_backend(3);"<?php checked( $cp_options['mem_where'], 'custom' ) ?> /> <?php esc_html_e('Custom post/URL', 'code-profiler') ?></label>
88 + <label><input type="radio" name="where" value="custom" onclick="cpjs_front_or_backend(3);"<?php checked( $cp_options['mem_where'], 'custom') ?> /> <?php esc_html_e('Custom post/URL', 'code-profiler') ?></label>
84 89 &nbsp;&nbsp;&nbsp;&nbsp;
85 - <label><input type="radio" name="where" value="backend" onclick="cpjs_front_or_backend(2);"<?php checked( $cp_options['mem_where'], 'backend' ) ?> /> <?php esc_html_e('Admin backend', 'code-profiler') ?></label>
90 + <label><input type="radio" name="where" value="backend" onclick="cpjs_front_or_backend(2);"<?php checked( $cp_options['mem_where'], 'backend') ?> /> <?php esc_html_e('Admin backend', 'code-profiler') ?></label>
86 91 </p>
87 92 <br />
88 93 <?php
89 - if ( $cp_options['mem_where'] == 'frontend' ) {
94 + if ( $cp_options['mem_where'] == 'frontend') {
90 95 echo '<p id="p-frontend">';
91 96 } else {
92 97 echo '<p id="p-frontend" style="display:none">';
93 98 }
@@ -97,9 +102,9 @@
97 102 <?php echo code_profiler_fetch_pages( $home, $cp_options ); ?>
98 103 </select>
99 104 </p>
100 105 <?php
101 - if ( $cp_options['mem_where'] == 'custom' ) {
106 + if ( $cp_options['mem_where'] == 'custom') {
102 107 $value = $cp_options['mem_post'];
103 108 echo '<p id="p-custom">';
104 109 } else {
105 110 $value = '';
@@ -114,9 +119,9 @@
114 119 )
115 120 ) ?>" />
116 121 </p>
117 122 <?php
118 - if ( $cp_options['mem_where'] == 'backend' ) {
123 + if ( $cp_options['mem_where'] == 'backend') {
119 124 echo '<p id="p-backend">';
120 125 } else {
121 126 echo '<p id="p-backend" style="display:none">';
122 127 }
@@ -126,14 +131,14 @@
126 131 $username = $current_user->user_login;
127 132 }
128 133 ?>
129 134 <?php esc_html_e('Select a page:', 'code-profiler') ?>
130 - <select name="backend" id="id-backend"><?php echo code_profiler_fetch_admin_pages( $home, $cp_options ) ?></select>
135 + <select name="backend" id="id-backend"><?php echo code_profiler_fetch_admin_pages( $site, $cp_options ) ?></select>
131 136 </p>
132 137 </td>
133 138 </tr>
134 139 <tr>
135 - <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>
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>
136 141 <td>
137 142 <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>
138 143 <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>
139 144 <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>
@@ -139,9 +144,9 @@
139 144 <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>
140 145 </td>
141 146 </tr>
142 147 <tr>
143 - <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>
148 + <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>
144 149 <td>
145 150 <select name="ua" id="ua-id">
146 151 <?php
147 152 foreach( CODE_PROFILER_UA as $types => $types_array ) {
@@ -155,9 +160,9 @@
155 160 </select>
156 161 </td>
157 162 </tr>
158 163 <tr>
159 - <th scope="row"><?php esc_html_e('Name of the profile', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Enter the name for this profile. It will be saved to the "Profiles List" page, with all other profiles.', 'code-profiler' ) ?>"></span></th>
164 + <th scope="row"><?php esc_html_e('Name of the profile', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Enter the name for this profile. It will be saved to the "Profiles List" page, with all other profiles.', 'code-profiler') ?>"></span></th>
160 165 <td>
161 166 <p><label><input type="text" class="regular-text" name="profile" maxlength="100" value="<?php echo esc_attr( $profile ) ?>" id="profile-name" /></label></p>
162 167 <p class="description"><?php esc_html_e('Max 100 characters', 'code-profiler') ?></p>
163 168 </td>
@@ -163,9 +168,9 @@
163 168 </td>
164 169 </tr>
165 170 </table>
166 171 <?php
167 -if (! empty( $cookies ) || $cp_options['mem_method'] == 'post' ) {
172 +if (! empty( $cookies ) || $cp_options['mem_method'] == 'post') {
168 173 echo '<div id="cp-advanced-settings">';
169 174 $disabled_button = ' disabled';
170 175 } else {
171 176 echo '<div id="cp-advanced-settings" style="display:none">';
@@ -173,21 +178,21 @@
173 178 }
174 179 ?>
175 180 <table class="form-table">
176 181 <tr>
177 - <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>
182 + <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>
178 183 <td>
179 - <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>
180 - <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>
181 - <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>
182 - <p class="description"><?php printf( esc_html__('Optional POST payload in %s format, one item per line.', 'code-profiler'), '<code>key=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>
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>
183 188 </td>
184 189 </tr>
185 190 <tr>
186 - <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>
191 + <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>
187 192 <td>
188 193 <p><textarea name="cp-cookies" id="cp-cookies" class="regular-text code" maxlength="4000" rows="6"><?php echo esc_textarea( $cookies ) ?></textarea></p>
189 - <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>
194 + <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>
190 195 </td>
191 196 </tr>
192 197 </table>
193 198 </div>
@@ -200,9 +205,9 @@
200 205 </div>
201 206 <div id="cp-progress-div" style="display:none">
202 207 <br />
203 208 <div class="cp-progress-bar"><span id="cp-span-progress" style="width:0%"></span></div>
204 - <img style="vertical-align:middle;display:none" id="progress-gif" src="<?php echo plugins_url('/static/progress.gif', dirname (__FILE__ ) ) ?>" />&nbsp;&nbsp;<font id="progress-text" style="display:none"><?php esc_html_e('Starting profiler...', 'code-profiler') ?></font>
209 + <img style="vertical-align:middle;display:none" id="progress-gif" src="<?php echo plugins_url('/static/progress.gif', dirname (__FILE__ ) ) ?>" />&nbsp;&nbsp;<font id="progress-text" style="display:none"><?php esc_html_e('Starting the profiler...', 'code-profiler') ?></font>
205 210 </div>
206 211
207 212 <?php
208 213
@@ -217,21 +222,27 @@
217 222 $cp_options['mem_post'] = $home;
218 223 }
219 224
220 225 if ( $cp_options['mem_post'] == $home ) {
221 - $pages = '<option value="'. esc_attr( $home ) .'" title="'. esc_attr( $home ) .'" selected>'.
222 - esc_html__('Homepage', 'code-profiler') .'</option>';
226 + $pages = sprintf(
227 + '<option value="%1$s" title="%1$s" selected>%2$s</option>',
228 + esc_attr( $home ),
229 + esc_html__('Homepage', 'code-profiler')
230 + );
223 231 } else {
224 - $pages = '<option value="'. esc_attr( $home ) .'" title="'. esc_attr( $home ) .'">'.
225 - esc_html__('Homepage', 'code-profiler') .'</option>';
232 + $pages = sprintf(
233 + '<option value="%1$s" title="%1$s">%2$s</option>',
234 + esc_attr( $home ),
235 + esc_html__('Homepage', 'code-profiler')
236 + );
226 237 }
227 - $args = array(
238 + $args = [
228 239 'posts_per_page' => -1,
229 - 'post_type' => array( 'page' ),
240 + 'post_type' => ['page'],
230 241 'post_status' => 'publish',
231 242 'orderby' => 'post_name',
232 243 'order' => 'ASC'
233 - );
244 + ];
234 245 $query = new WP_Query( $args );
235 246
236 247 if ( $query ) {
237 248 $items = $query->posts;
@@ -241,18 +252,24 @@
241 252 }
242 253 $permalink = get_permalink( $item->ID );
243 254
244 255 if ( $cp_options['mem_post'] == $permalink ) {
245 - $pages .= '<option value="'. esc_attr( $permalink ).'" title="'.
246 - esc_attr( $permalink ) .'" selected>'. esc_html( $item->post_title ) .'</option>';
256 + $pages .= sprintf(
257 + '<option value="%1$s" title="%1$s" selected>%2$s</option>',
258 + esc_attr( $permalink ),
259 + esc_html( $item->post_title )
260 + );
247 261 } else {
248 - $pages .= '<option value="'. esc_attr( $permalink ).'" title="'.
249 - esc_attr( $permalink ) .'">'. esc_html( $item->post_title ) .'</option>';
262 + $pages .= sprintf(
263 + '<option value="%1$s" title="%1$s">%2$s</option>',
264 + esc_attr( $permalink ),
265 + esc_html( $item->post_title )
266 + );
250 267 }
251 268 }
252 269 }
253 270
254 - return sprintf( '<optgroup label="%s">%s</optgroup>',
271 + return sprintf('<optgroup label="%s">%s</optgroup>',
255 272 esc_attr__('Pages', 'code-profiler'),
256 273 $pages
257 274 );
258 275 }
@@ -269,27 +286,35 @@
269 286 }
270 287
271 288 if (! empty( $GLOBALS[ 'menu' ] ) ) {
272 289 foreach( $GLOBALS[ 'menu' ] as $menu => $value ) {
273 - if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php' ) {
290 + if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php') {
274 291 // E.g., "Comments", "Plugins" etc
275 - $value[0] = trim( preg_replace( '/\s+<.+$/', '', $value[0] ) );
292 + $value[0] = trim( preg_replace('/\s+<.+$/', '', $value[0] ) );
276 293
277 294 if ( $cp_options['mem_post'] == "{$home}wp-admin/{$value[2]}" ) {
278 - $backend .= '<option value="'. esc_attr( "{$home}wp-admin/{$value[2]}" ) .'" title="'.
279 - esc_attr( "{$home}wp-admin/{$value[2]}" ) .'" selected>'.
280 - esc_html( $value[0] ) .'</option>';
295 + $backend .= sprintf(
296 + '<option value="%1$s" title="%1$s" selected>%2$s</option>',
297 + esc_attr("{$home}wp-admin/{$value[2]}"),
298 + esc_html( $value[0] )
299 + );
281 300 } else {
282 - $backend .= '<option value="'. esc_attr( "{$home}wp-admin/{$value[2]}" ) .'" title="'.
283 - esc_attr( "{$home}wp-admin/{$value[2]}" ) .'">'.
284 - esc_html( $value[0] ) .'</option>';
301 + $backend .= sprintf(
302 + '<option value="%1$s" title="%1$s">%2$s</option>',
303 + esc_attr("{$home}wp-admin/{$value[2]}"),
304 + esc_html( $value[0] )
305 + );
285 306 }
286 307 }
287 308 }
288 309 }
289 310 if ( empty( $backend ) ) {
290 - $backend = '<option value="'. esc_attr( $home ) .'wp-admin/" title="'. esc_attr( $home ) .'wp-admin/">'.
291 - esc_html__( 'Dashboard', 'code-profiler' ) .'</option>';
311 + $backend = sprintf(
312 + '<option value="%1$swp-admin/" title="%1$swp-admin/">%2$s</option>',
313 + esc_attr( $home ),
314 + esc_html__('Dashboard', 'code-profiler')
315 + );
316 +
292 317 }
293 318
294 319 return $backend;
295 320 }