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.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 All 41 releases
← All changes | lib/menu_profiler.php +153 -281 1.9.31.7.4 View file →
@@ -39,17 +39,8 @@
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 42
43 -/**
44 - * Check and warn if the Xdebug extension is loaded.
45 - */
46 -if ( extension_loaded('xdebug') ) {
47 - printf( CODE_PROFILER_WARNING_NOTICE,
48 - esc_html__('Warning: the PHP Xdebug extension is loaded. Consider disabling it as it can drastically impact the performance and results of Code Profiler.', 'code-profiler')
49 - );
50 -}
51 -
52 43 // Clear the log if it's too big
53 44 code_profiler_clearlog();
54 45
55 46 // Clean-up temp files left in the profiles folder
@@ -54,246 +45,173 @@
54 45
55 46 // Clean-up temp files left in the profiles folder
56 47 code_profiler_cleantmpfiles();
57 48
58 -/**
59 - * Create temporary folder and file used to profile cron events.
60 - */
61 -$error = code_profiler_create_tmpfile();
62 -if ( $error ) {
63 - printf( CODE_PROFILER_ERROR_NOTICE, esc_html( $error ) );
64 -}
65 -
66 49 $home = home_url('/'); // Frontend
67 50 $site = site_url('/'); // Backend
68 -
69 51 // Get user login name
70 52 $current_user = wp_get_current_user();
53 +// Profile's name
54 +$profile = code_profiler_profile_name();
71 55
72 56 $cp_options = get_option('code-profiler');
73 -/**
74 - * Check if we've been asked to re-run a profile.
75 - */
76 -if (! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'rerun' &&
77 - ! empty( $_REQUEST['profiles'][0] ) ) {
78 - /**
79 - * Make sure the profile exists and get its full path.
80 - */
81 - $profile_path = code_profiler_get_profile_path( $_REQUEST['profiles'][0] );
82 - if ( $profile_path !== false ) {
83 -
84 - $cp_data = json_decode( file_get_contents("$profile_path.summary.profile"), true );
85 - if (! empty( $cp_data['rerun'] ) ) {
86 - $cp_options['mem'] = $cp_data['rerun'];
87 - $rerun = true;
88 - }
89 - }
57 +// Memorized options
58 +if ( empty( $cp_options['mem_where'] ) ) {
59 + $cp_options['mem_where'] = 'frontend';
90 60 }
91 -// Profile's name
92 -if (! empty( $cp_options['mem']['profile'] ) ) {
93 - $profile = $cp_options['mem']['profile'];
94 -} else {
95 - $profile = code_profiler_profile_name();
61 +if ( empty( $cp_options['mem_post'] ) ) {
62 + $cp_options['mem_post'] = '';
96 63 }
97 -/**
98 - * Memorized options from last run.
99 - */
100 -if ( empty( $cp_options['mem']['x_end'] ) ) {
101 - $cp_options['mem']['x_end'] = 'frontend';
64 +if ( empty( $cp_options['mem_user'] ) ) {
65 + $cp_options['mem_user'] = 'unauthenticated';
102 66 }
103 -if ( empty( $cp_options['mem']['post'] ) ) {
104 - $cp_options['mem']['post'] = '';
67 +if ( $cp_options['mem_where'] == 'backend') {
68 + $cp_options['mem_user'] = 'authenticated';
105 69 }
106 -if ( empty( $cp_options['mem']['x_auth'] ) ) {
107 - $cp_options['mem']['x_auth'] = 'unauthenticated';
70 +if ( empty( $cp_options['mem_method'] ) ) {
71 + $cp_options['mem_method'] = 'get';
108 72 }
109 -if ( $cp_options['mem']['x_end'] == 'backend') {
110 - $cp_options['mem']['x_auth'] = 'authenticated';
111 -}
112 -if ( empty( $cp_options['mem']['method'] ) ) {
113 - $cp_options['mem']['method'] = 'get';
114 -}
115 73 $default_theme = get_option('stylesheet');
116 -if ( empty( $cp_options['mem']['theme'] ) ) {
117 - $cp_options['mem']['theme'] = $default_theme;
74 +if ( empty( $cp_options['mem_theme'] ) ) {
75 + $cp_options['mem_theme'] = $default_theme;
118 76 }
119 -if ( empty( $cp_options['mem']['user_agent'] ) ) {
120 - $cp_options['mem']['user_agent'] = 'Firefox';
77 +if ( empty( $cp_options['ua'] ) ) {
78 + $cp_options['ua'] = 'Firefox';
121 79 }
122 -if ( isset( $cp_options['mem']['cookies'] ) ) {
80 +$cookies = '';
81 +$payload = '';
82 +$custom_headers = '';
83 +$exclusions = [];
84 +
85 +if ( isset( $cp_options['cookies'] ) ) {
123 86 // stripslashes is only needed for cookies
124 - $cookies = trim( stripslashes( json_decode( $cp_options['mem']['cookies'] ) ) );
125 -} else {
126 - $cookies = '';
87 + $cookies = trim( stripslashes( json_decode( $cp_options['cookies'] ) ) );
127 88 }
128 -if ( empty( $cp_options['mem']['content_type'] ) ||
129 - ! in_array( $cp_options['mem']['content_type'], [ 1, 2, 3 ] ) ) {
89 +if ( empty( $cp_options['mem_content_type'] ) ||
90 + ! in_array( $cp_options['mem_content_type'], [ 1, 2 ] ) ) {
130 91
131 - $cp_options['mem']['content_type'] = 1;
92 + $cp_options['mem_content_type'] = 1;
132 93 }
133 -if ( isset( $cp_options['mem']['payload'] ) ) {
134 - $payload = trim( json_decode( $cp_options['mem']['payload'] ) );
135 -} else {
136 - $payload = '';
94 +if ( isset( $cp_options['payload'] ) ) {
95 + $payload = trim( json_decode( $cp_options['payload'] ) );
137 96 }
138 -if ( isset( $cp_options['mem']['custom_headers'] ) ) {
139 - $custom_headers = trim( json_decode( $cp_options['mem']['custom_headers'] ) );
140 -} else {
141 - $custom_headers = '';
97 +if ( isset( $cp_options['custom_headers'] ) ) {
98 + $custom_headers = trim( json_decode( $cp_options['custom_headers'] ) );
142 99 }
143 -if ( isset( $cp_options['mem']['exclusions'] ) ) {
144 - $exclusions = json_decode( $cp_options['mem']['exclusions'] );
145 -} else {
146 - $exclusions = [];
100 +if ( isset( $cp_options['exclusions'] ) ) {
101 + $exclusions = json_decode( $cp_options['exclusions'] );
147 102 }
148 -
149 103 ?>
150 -
151 -<table style="width:100%">
104 +<table class="form-table">
152 105 <tr>
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>
153 107 <td>
154 - <table class="form-table">
155 - <tr>
156 - <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, a custom URL or a cron event. Note that in case of a cron event, the "HTTP Method" option will be ignored by Code Profiler as it will always send a POST request with an empty payload.', 'code-profiler') ?>"></span></th>
157 - <td>
158 - <p><label><input type="radio" name="x_end" value="frontend" onclick="cpjs_front_or_backend(this.value);"<?php checked( $cp_options['mem']['x_end'], 'frontend') ?> /> <?php esc_html_e('Website frontend', 'code-profiler') ?></label>
159 - &nbsp;&nbsp;&nbsp;&nbsp;
160 - <label><input type="radio" name="x_end" value="custom" onclick="cpjs_front_or_backend(this.value);"<?php checked( $cp_options['mem']['x_end'], 'custom') ?> /> <?php esc_html_e('Custom post/URL', 'code-profiler') ?></label>
161 - &nbsp;&nbsp;&nbsp;&nbsp;
162 - <label><input type="radio" name="x_end" value="backend" onclick="cpjs_front_or_backend(this.value);"<?php checked( $cp_options['mem']['x_end'], 'backend') ?> /> <?php esc_html_e('Admin backend', 'code-profiler') ?></label>
163 - &nbsp;&nbsp;&nbsp;&nbsp;
164 - <label><input type="radio" name="x_end" value="wpcron" onclick="cpjs_front_or_backend(this.value);"<?php checked( $cp_options['mem']['x_end'], 'wpcron') ?> /> <?php esc_html_e('WP-Cron', 'code-profiler') ?></label>
165 - </p>
166 - <br />
167 - <?php
168 - if ( $cp_options['mem']['x_end'] == 'frontend') {
169 - echo '<p id="p-frontend">';
170 - } else {
171 - echo '<p id="p-frontend" style="display:none">';
172 - }
173 - ?>
174 - <?php esc_html_e('Select a page:', 'code-profiler') ?>
175 - <select name="frontend" id="id-frontend">
176 - <?php echo code_profiler_fetch_pages( $home, $cp_options ); ?>
177 - </select>
178 - </p>
179 - <?php
180 - if ( $cp_options['mem']['x_end'] == 'custom') {
181 - $value = $cp_options['mem']['post'];
182 - echo '<p id="p-custom">';
183 - } else {
184 - $value = '';
185 - echo '<p id="p-custom" style="display:none">';
186 - }
187 - ?>
188 - <input name="custom" id="id-custom" type="text" value="<?php echo esc_attr( $value ) ?>" size="70" placeholder="<?php
189 - echo esc_attr(
190 - sprintf(
191 - __('e.g., %s', 'code-profiler'),
192 - "{$home}foo/bar/"
193 - )
194 - ) ?>" />
195 - </p>
196 - <?php
197 - if ( $cp_options['mem']['x_end'] == 'backend') {
198 - echo '<p id="p-backend">';
199 - } else {
200 - echo '<p id="p-backend" style="display:none">';
201 - }
202 - if (! empty( $cp_options['mem']['username'] ) ) {
203 - $username = $cp_options['mem']['username'];
204 - } else {
205 - $username = $current_user->user_login;
206 - }
207 - ?>
208 - <?php esc_html_e('Select a page:', 'code-profiler') ?>
209 - <select name="backend" id="id-backend"><?php echo code_profiler_fetch_admin_pages( $site, $cp_options ) ?></select>
210 - </p>
211 - <?php
212 - /**
213 - * Cron tasks.
214 - */
215 - if ( $cp_options['mem']['x_end'] == 'wpcron') {
216 - echo '<p id="p-wpcron">';
217 - } else {
218 - echo '<p id="p-wpcron" style="display:none">';
219 - }
220 - ?>
221 - <?php esc_html_e('Select a cron event:', 'code-profiler') ?>
222 - <select name="wpcron" id="id-wpcron">
223 - <?php echo code_profiler_fetch_crontasks( $cp_options['mem']['post'] ); ?>
224 - </select>
225 - </p>
226 - </td>
227 - </tr>
228 - <tr>
229 - <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>
230 - <td>
231 - <p><label><input type="radio" onclick="cpjs_authenticated(0);" name="x_auth" value="unauthenticated" id="user-unauthenticated"<?php checked( $cp_options['mem']['x_auth'], 'unauthenticated'); disabled( $cp_options['mem']['x_end'], 'backend'); ?> /> <?php esc_html_e('Unauthenticated user', 'code-profiler') ?></label></p>
232 - <p><label><input type="radio" onclick="cpjs_authenticated(1);" name="x_auth" value="authenticated" id="user-authenticated"<?php checked( $cp_options['mem']['x_auth'], 'authenticated') ?> /> <?php esc_html_e('Authenticated user', 'code-profiler') ?></label></p>
233 - <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']['x_auth'], 'unauthenticated') ?> /></label></p>
234 - </td>
235 - </tr>
236 - <tr>
237 - <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>
238 - <td>
239 - <select name="theme" id="id-theme">
240 - <?php
241 - $themes = code_profiler_get_themes();
242 - foreach( $themes as $slug => $name ) {
243 - if ( $slug == $default_theme ) {
244 - echo '<option value=""'. selected( $cp_options['mem']['theme'], $slug, false ) .'>'.
245 - esc_html( $name['n'] ) .' '. __('(active theme)', 'code-profiler') .'</option>';
246 - } else {
247 - echo '<option value="'. esc_attr( $slug ) .'"'. selected( $cp_options['mem']['theme'], $slug, false ) .'>'.
248 - esc_html( $name['n'] ) .'</option>';
249 - }
250 - }
251 - ?>
252 - </select>
253 - </td>
254 - </tr>
255 - <tr>
256 - <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>
257 - <td>
258 - <select name="user_agent" id="ua-id">
259 - <?php
260 - foreach( CODE_PROFILER_UA as $types => $types_array ) {
261 - echo '<optgroup label="'. esc_attr( $types ) .'">';
262 - foreach( $types_array as $name => $value ) {
263 - echo '<option value="'. esc_attr( $name ) .'"'. selected( $cp_options['mem']['user_agent'], $name, false ) .'>'. esc_html( $name ) .'</option>';
264 - }
265 - echo '</optgroup>';
266 - }
267 - ?>
268 - </select>
269 - </td>
270 - </tr>
271 - <tr>
272 - <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>
273 - <td>
274 - <p><label><input type="text" class="regular-text" name="profile" maxlength="100" value="<?php echo esc_attr( $profile ) ?>" id="profile-name" /></label></p>
275 - <p class="description"><?php esc_html_e('Max 100 characters', 'code-profiler') ?></p>
276 - </td>
277 - </tr>
278 - </table>
108 + <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>
109 + &nbsp;&nbsp;&nbsp;&nbsp;
110 + <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>
111 + &nbsp;&nbsp;&nbsp;&nbsp;
112 + <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>
113 + </p>
114 + <br />
115 + <?php
116 + if ( $cp_options['mem_where'] == 'frontend') {
117 + echo '<p id="p-frontend">';
118 + } else {
119 + echo '<p id="p-frontend" style="display:none">';
120 + }
121 + ?>
122 + <?php esc_html_e('Select a page:', 'code-profiler') ?>
123 + <select name="frontend" id="id-frontend">
124 + <?php echo code_profiler_fetch_pages( $home, $cp_options ); ?>
125 + </select>
126 + </p>
127 + <?php
128 + if ( $cp_options['mem_where'] == 'custom') {
129 + $value = $cp_options['mem_post'];
130 + echo '<p id="p-custom">';
131 + } else {
132 + $value = '';
133 + echo '<p id="p-custom" style="display:none">';
134 + }
135 + ?>
136 + <input name="custom" id="id-custom" type="text" value="<?php echo esc_attr( $value ) ?>" size="70" placeholder="<?php
137 + echo esc_attr(
138 + sprintf(
139 + __('e.g., %s', 'code-profiler'),
140 + "{$home}foo/bar/"
141 + )
142 + ) ?>" />
143 + </p>
144 + <?php
145 + if ( $cp_options['mem_where'] == 'backend') {
146 + echo '<p id="p-backend">';
147 + } else {
148 + echo '<p id="p-backend" style="display:none">';
149 + }
150 + if (! empty( $cp_options['mem_username'] ) ) {
151 + $username = $cp_options['mem_username'];
152 + } else {
153 + $username = $current_user->user_login;
154 + }
155 + ?>
156 + <?php esc_html_e('Select a page:', 'code-profiler') ?>
157 + <select name="backend" id="id-backend"><?php echo code_profiler_fetch_admin_pages( $site, $cp_options ) ?></select>
158 + </p>
279 159 </td>
280 - <td style="vertical-align:top;text-align: center">
281 - <?php
282 - /**
283 - * Display any available discount coupon.
284 - */
285 - CodeProfiler_WPCron::display_coupon();
286 - ?>
160 + </tr>
161 + <tr>
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>
163 + <td>
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>
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>
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>
287 167 </td>
288 168 </tr>
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>
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>
190 + <td>
191 + <select name="ua" id="ua-id">
192 + <?php
193 + foreach( CODE_PROFILER_UA as $types => $types_array ) {
194 + echo '<optgroup label="'. esc_attr( $types ) .'">';
195 + foreach( $types_array as $name => $value ) {
196 + echo '<option value="'. esc_attr( $name ) .'"'. selected( $cp_options['ua'], $name, false ) .'>'. esc_html( $name ) .'</option>';
197 + }
198 + echo '</optgroup>';
199 + }
200 + ?>
201 + </select>
202 + </td>
203 + </tr>
204 + <tr>
205 + <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>
206 + <td>
207 + <p><label><input type="text" class="regular-text" name="profile" maxlength="100" value="<?php echo esc_attr( $profile ) ?>" id="profile-name" /></label></p>
208 + <p class="description"><?php esc_html_e('Max 100 characters', 'code-profiler') ?></p>
209 + </td>
210 + </tr>
289 211 </table>
290 212 <?php
291 -if ( (! empty( $cookies ) || ! empty( $custom_headers ) ||
292 - $cp_options['mem']['method'] == 'post' || ! empty( $exclusions ) ) &&
293 - // We don't display the advanced section if the last profile was a cron event.
294 - $cp_options['mem']['x_end'] != 'wpcron' ) {
295 -
213 +if (! empty( $cookies ) || ! empty( $custom_headers ) || $cp_options['mem_method'] == 'post' || ! empty( $exclusions ) ) {
296 214 echo '<div id="cp-advanced-settings">';
297 215 $disabled_button = ' disabled';
298 216 } else {
299 217 echo '<div id="cp-advanced-settings" style="display:none">';
@@ -305,36 +223,32 @@
305 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>
306 224 <td>
307 225 <p>
308 226 <label>
309 - <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') ?>)
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') ?>)
310 228 </label>
311 229 </p>
312 230 <p>
313 231 <label>
314 - <input onclick="cpjs_get_post(1);" type="radio" name="method" value="post" id="post-method"<?php checked( $cp_options['mem']['method'], 'post') ?> /> POST
232 + <input onclick="cpjs_get_post(1);" type="radio" name="method" value="post" id="post-method"<?php checked( $cp_options['mem_method'], 'post') ?> /> POST
315 233 </label>
316 234 </p>
317 235 <p>
318 236 <?php esc_html_e('Content-type:', 'code-profiler') ?>
319 - <select name="cp-content-type" id="id-content-type"<?php disabled( $cp_options['mem']['method'], 'get') ?> onChange="cpjs_content_type(this.value);">
320 - <option value="1"<?php selected( $cp_options['mem']['content_type'], 1 )?>>application/x-www-form-urlencoded (<?php esc_html_e('formatted', 'code-profiler') ?>)</option>
321 - <option value="3"<?php selected( $cp_options['mem']['content_type'], 3 )?>>application/x-www-form-urlencoded (<?php esc_html_e('raw', 'code-profiler') ?>)</option>
322 - <option value="2"<?php selected( $cp_options['mem']['content_type'], 2 )?>>application/json</option>
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>
323 240 </select>
324 241 </p>
325 242 <p>
326 - <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>
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>
327 244 </p>
328 - <p class="description" id="ct-1"<?php echo code_profiler_showhide( $cp_options['mem']['content_type'], 1 ) ?>>
245 + <p class="description" id="ct-1"<?php echo code_profiler_hide( $cp_options['mem_content_type'], 2) ?>>
329 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>') ?>
330 247 </p>
331 - <p class="description" id="ct-3"<?php echo code_profiler_showhide( $cp_options['mem']['content_type'], 3 ) ?>>
332 - <?php printf( esc_html__('Optional raw POST payload, on a single line.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/http_method-3.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?>
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>') ?>
333 250 </p>
334 - <p class="description" id="ct-2"<?php echo code_profiler_showhide( $cp_options['mem']['content_type'], 2 ) ?>>
335 - <?php printf( esc_html__('Optional JSON-encoded payload, on a single line.', '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>') ?>
336 - </p>
337 251 </td>
338 252 </tr>
339 253 <tr>
340 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>
@@ -374,17 +288,11 @@
374 288 <br />
375 289 <div class="cp-progress-bar"><span id="cp-span-progress" style="width:0%"></span></div>
376 290 <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>
377 291 </div>
292 +
378 293 <?php
379 294
380 -/**
381 - * Re-run a profile.
382 - */
383 -if (! empty( $rerun ) ) {
384 - echo '<script>window.addEventListener("load", cpjs_start_profiler);</script>';
385 -}
386 -
387 295 // =====================================================================
388 296 // Fetch pages and posts.
389 297
390 298 function code_profiler_fetch_pages( $home, $cp_options ) {
@@ -390,13 +298,13 @@
390 298 function code_profiler_fetch_pages( $home, $cp_options ) {
391 299
392 300 $posts = '';
393 301
394 - if ( empty( $cp_options['mem']['post'] ) ) {
395 - $cp_options['mem']['post'] = $home;
302 + if ( empty( $cp_options['mem_post'] ) ) {
303 + $cp_options['mem_post'] = $home;
396 304 }
397 305
398 - if ( $cp_options['mem']['post'] == $home ) {
306 + if ( $cp_options['mem_post'] == $home ) {
399 307 $pages = sprintf(
400 308 '<option value="%1$s" title="%1$s" selected>%2$s</option>',
401 309 esc_attr( $home ),
402 310 esc_html__('Homepage', 'code-profiler')
@@ -424,9 +332,9 @@
424 332 $item->post_title = __('Untitled');
425 333 }
426 334 $permalink = get_permalink( $item->ID );
427 335
428 - if ( $cp_options['mem']['post'] == $permalink ) {
336 + if ( $cp_options['mem_post'] == $permalink ) {
429 337 $pages .= sprintf(
430 338 '<option value="%1$s" title="%1$s" selected>%2$s</option>',
431 339 esc_attr( $permalink ),
432 340 esc_html( $item->post_title )
@@ -453,10 +361,10 @@
453 361 function code_profiler_fetch_admin_pages( $home, $cp_options ) {
454 362
455 363 $backend = '';
456 364
457 - if ( empty( $cp_options['mem']['post'] ) ) {
458 - $cp_options['mem']['post'] = $home;
365 + if ( empty( $cp_options['mem_post'] ) ) {
366 + $cp_options['mem_post'] = $home;
459 367 }
460 368
461 369 if (! empty( $GLOBALS[ 'menu' ] ) ) {
462 370 foreach( $GLOBALS[ 'menu' ] as $menu => $value ) {
@@ -463,9 +371,9 @@
463 371 if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php') {
464 372 // E.g., "Comments", "Plugins" etc
465 373 $value[0] = trim( preg_replace('/\s*<.+$/', '', $value[0] ) );
466 374
467 - if ( $cp_options['mem']['post'] == "{$home}wp-admin/{$value[2]}" ) {
375 + if ( $cp_options['mem_post'] == "{$home}wp-admin/{$value[2]}" ) {
468 376 $backend .= sprintf(
469 377 '<option value="%1$s" title="%1$s" selected>%2$s</option>',
470 378 esc_attr("{$home}wp-admin/{$value[2]}"),
471 379 esc_html( $value[0] )
@@ -488,44 +396,8 @@
488 396 );
489 397
490 398 }
491 399 return $backend;
492 -}
493 -
494 -// =====================================================================
495 -// Fetch scheduled tasks.
496 -
497 -function code_profiler_fetch_crontasks( $mem ) {
498 -
499 - $cron_list = '';
500 -
501 - $wp_crons = code_profiler_get_crons();
502 -
503 - if ( empty( $wp_crons ) ) {
504 - $cron_list = sprintf(
505 - '<option value="0">%s</option>',
506 - esc_html__('No cron tasks found.', 'code-profiler')
507 - );
508 - return $cron_list;
509 - }
510 -
511 - foreach( $wp_crons as $cron ) {
512 -
513 - if ( $mem == $cron ) {
514 - $selected = ' selected';
515 - } else {
516 - $selected = '';
517 - }
518 -
519 - $cron_list .= sprintf(
520 - "<option value='%s'%s>%s</option>",
521 - esc_attr( $cron ),
522 - $selected,
523 - esc_html( $cron )
524 - );
525 - }
526 -
527 - return $cron_list;
528 400 }
529 401
530 402 // =====================================================================
531 403 // EOF