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 +273 -48 1.41.7.4 View file →
@@ -6,13 +6,13 @@
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 -if (! defined( 'ABSPATH' ) ) { die( 'Forbidden' ); }
14 +if (! defined('ABSPATH') ) { die('Forbidden'); }
15 15
16 16 // =====================================================================
17 17 // Display Summary tab.
18 18
@@ -33,30 +33,108 @@
33 33 printf( CODE_PROFILER_ERROR_NOTICE, sprintf(
34 34 esc_html__('Your PHP configuration is missing the "%s" function. Code Profiler cannot run without it. Please contact your server administrator about this error.', 'code-profiler'), $error )
35 35 );
36 36 }
37 +if (! is_writable( CODE_PROFILER_UPLOAD_DIR ) ) {
38 + printf( CODE_PROFILER_ERROR_NOTICE, sprintf(
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 + );
41 +}
37 42
38 -$home = home_url( '/' );
43 +// Clear the log if it's too big
44 +code_profiler_clearlog();
45 +
46 +// Clean-up temp files left in the profiles folder
47 +code_profiler_cleantmpfiles();
48 +
49 +$home = home_url('/'); // Frontend
50 +$site = site_url('/'); // Backend
39 51 // Get user login name
40 52 $current_user = wp_get_current_user();
41 53 // Profile's name
42 54 $profile = code_profiler_profile_name();
55 +
56 +$cp_options = get_option('code-profiler');
57 +// Memorized options
58 +if ( empty( $cp_options['mem_where'] ) ) {
59 + $cp_options['mem_where'] = 'frontend';
60 +}
61 +if ( empty( $cp_options['mem_post'] ) ) {
62 + $cp_options['mem_post'] = '';
63 +}
64 +if ( empty( $cp_options['mem_user'] ) ) {
65 + $cp_options['mem_user'] = 'unauthenticated';
66 +}
67 +if ( $cp_options['mem_where'] == 'backend') {
68 + $cp_options['mem_user'] = 'authenticated';
69 +}
70 +if ( empty( $cp_options['mem_method'] ) ) {
71 + $cp_options['mem_method'] = 'get';
72 +}
73 +$default_theme = get_option('stylesheet');
74 +if ( empty( $cp_options['mem_theme'] ) ) {
75 + $cp_options['mem_theme'] = $default_theme;
76 +}
77 +if ( empty( $cp_options['ua'] ) ) {
78 + $cp_options['ua'] = 'Firefox';
79 +}
80 +$cookies = '';
81 +$payload = '';
82 +$custom_headers = '';
83 +$exclusions = [];
84 +
85 +if ( isset( $cp_options['cookies'] ) ) {
86 + // stripslashes is only needed for cookies
87 + $cookies = trim( stripslashes( json_decode( $cp_options['cookies'] ) ) );
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 +}
94 +if ( isset( $cp_options['payload'] ) ) {
95 + $payload = trim( json_decode( $cp_options['payload'] ) );
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 +}
43 103 ?>
44 104 <table class="form-table">
45 105 <tr>
46 - <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>
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>
47 107 <td>
48 - <p><label><input type="radio" name="where" value="frontend" onclick="cpjs_front_or_backend(1);" checked /> <?php esc_html_e('Website frontend', 'code-profiler') ?></label></p>
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>
49 114 <br />
50 - <?php esc_html_e('Select a page:', 'code-profiler') ?>
51 - <select name="frontend" id="id-frontend">
52 - <?php echo code_profiler_fetch_pages( $home ); ?>
53 - </select>
54 - <br />
55 - <br />
56 - <p><label><input type="radio" name="where" value="custom" onclick="cpjs_front_or_backend(3);" /> <?php esc_html_e('Custom post/URL', 'code-profiler') ?></label></p>
57 - <br />
58 - <input name="custom" id="id-custom" disabled type="text" value="" size="70" placeholder="<?php
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
59 137 echo esc_attr(
60 138 sprintf(
61 139 __('e.g., %s', 'code-profiler'),
62 140 "{$home}foo/bar/"
@@ -61,32 +139,62 @@
61 139 __('e.g., %s', 'code-profiler'),
62 140 "{$home}foo/bar/"
63 141 )
64 142 ) ?>" />
65 - <br />
66 - <br />
67 - <p><label><input type="radio" name="where" value="backend" onclick="cpjs_front_or_backend(2);" /> <?php esc_html_e('Admin backend', 'code-profiler') ?></label></p>
68 - <br />
69 - <?php esc_html_e('Select a page:', 'code-profiler') ?>
70 - <select name="backend" id="id-backend" disabled><?php echo code_profiler_fetch_admin_pages( $home ) ?></select>
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>
71 159 </td>
72 160 </tr>
73 161 <tr>
74 - <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 you, the authenticated user.', '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>
75 163 <td>
76 - <p><label><input type="radio" name="user" value="unauthenticated" id="user-unauthenticated" checked /> <?php esc_html_e('Unauthenticated user', 'code-profiler') ?></label></p>
77 - <p><label><input type="radio" name="user" value="authenticated" id="user-authenticated" /> <?php printf( esc_html__('Authenticated user (%s)', 'code-profiler'), esc_html( $current_user->user_login ) ) ?></label></p>
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>
78 167 </td>
79 168 </tr>
80 169 <tr>
81 - <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>
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>
82 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>
83 191 <select name="ua" id="ua-id">
84 192 <?php
85 193 foreach( CODE_PROFILER_UA as $types => $types_array ) {
86 194 echo '<optgroup label="'. esc_attr( $types ) .'">';
87 195 foreach( $types_array as $name => $value ) {
88 - echo '<option value="'. esc_attr( $name ) .'">'. esc_html( $name ) .'</option>';
196 + echo '<option value="'. esc_attr( $name ) .'"'. selected( $cp_options['ua'], $name, false ) .'>'. esc_html( $name ) .'</option>';
89 197 }
90 198 echo '</optgroup>';
91 199 }
92 200 ?>
@@ -93,24 +201,94 @@
93 201 </select>
94 202 </td>
95 203 </tr>
96 204 <tr>
97 - <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>
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>
98 206 <td>
99 - <p><label><input type="text" size="70" name="profile" maxlength="100" value="<?php echo esc_attr( $profile ) ?>" id="profile-name" /></label></p>
207 + <p><label><input type="text" class="regular-text" name="profile" maxlength="100" value="<?php echo esc_attr( $profile ) ?>" id="profile-name" /></label></p>
100 208 <p class="description"><?php esc_html_e('Max 100 characters', 'code-profiler') ?></p>
101 209 </td>
102 210 </tr>
103 211 </table>
212 +<?php
213 +if (! empty( $cookies ) || ! empty( $custom_headers ) || $cp_options['mem_method'] == 'post' || ! empty( $exclusions ) ) {
214 + echo '<div id="cp-advanced-settings">';
215 + $disabled_button = ' disabled';
216 +} else {
217 + echo '<div id="cp-advanced-settings" style="display:none">';
218 + $disabled_button = '';
219 +}
220 +?>
221 + <table class="form-table">
222 + <tr>
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>
224 + <td>
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>
251 + </td>
252 + </tr>
253 + <tr>
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>
255 + <td>
256 + <p><textarea name="cp-cookies" id="cp-cookies" class="regular-text code" maxlength="4000" rows="6"><?php echo esc_textarea( $cookies ) ?></textarea></p>
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>
258 + </td>
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>
278 + </table>
279 +</div>
104 280 <?php wp_nonce_field('start_profiler_nonce', 'cp_nonce', 0); ?>
105 281 <br />
106 282 <div>
107 - <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') ?>" />
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 ?> />
284 + &nbsp;&nbsp;&nbsp;
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') ?>" />
108 286 </div>
109 287 <div id="cp-progress-div" style="display:none">
110 288 <br />
111 289 <div class="cp-progress-bar"><span id="cp-span-progress" style="width:0%"></span></div>
112 - <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>
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>
113 291 </div>
114 292
115 293 <?php
116 294
@@ -116,20 +294,36 @@
116 294
117 295 // =====================================================================
118 296 // Fetch pages and posts.
119 297
120 -function code_profiler_fetch_pages( $home ) {
298 +function code_profiler_fetch_pages( $home, $cp_options ) {
121 299
122 300 $posts = '';
123 - $pages = '<option value="'. esc_attr( $home ) .'" title="'. esc_attr( $home ) .'">'.
124 - esc_html__('Homepage', 'code-profiler') .'</option>';
125 - $args = array(
301 +
302 + if ( empty( $cp_options['mem_post'] ) ) {
303 + $cp_options['mem_post'] = $home;
304 + }
305 +
306 + if ( $cp_options['mem_post'] == $home ) {
307 + $pages = sprintf(
308 + '<option value="%1$s" title="%1$s" selected>%2$s</option>',
309 + esc_attr( $home ),
310 + esc_html__('Homepage', 'code-profiler')
311 + );
312 + } else {
313 + $pages = sprintf(
314 + '<option value="%1$s" title="%1$s">%2$s</option>',
315 + esc_attr( $home ),
316 + esc_html__('Homepage', 'code-profiler')
317 + );
318 + }
319 + $args = [
126 320 'posts_per_page' => -1,
127 - 'post_type' => array( 'page' ),
321 + 'post_type' => ['page'],
128 322 'post_status' => 'publish',
129 323 'orderby' => 'post_name',
130 - 'order' => 'ASC',
131 - );
324 + 'order' => 'ASC'
325 + ];
132 326 $query = new WP_Query( $args );
133 327
134 328 if ( $query ) {
135 329 $items = $query->posts;
@@ -137,14 +331,26 @@
137 331 if ( empty( $item->post_title ) ) {
138 332 $item->post_title = __('Untitled');
139 333 }
140 334 $permalink = get_permalink( $item->ID );
141 - $pages .= '<option value="'. esc_attr( $permalink ).'" title="'.
142 - esc_attr( $permalink ) .'">'. esc_html( $item->post_title ) .'</option>';
335 +
336 + if ( $cp_options['mem_post'] == $permalink ) {
337 + $pages .= sprintf(
338 + '<option value="%1$s" title="%1$s" selected>%2$s</option>',
339 + esc_attr( $permalink ),
340 + esc_html( $item->post_title )
341 + );
342 + } else {
343 + $pages .= sprintf(
344 + '<option value="%1$s" title="%1$s">%2$s</option>',
345 + esc_attr( $permalink ),
346 + esc_html( $item->post_title )
347 + );
348 + }
143 349 }
144 350 }
145 351
146 - return sprintf( '<optgroup label="%s">%s</optgroup>',
352 + return sprintf('<optgroup label="%s">%s</optgroup>',
147 353 esc_attr__('Pages', 'code-profiler'),
148 354 $pages
149 355 );
150 356 }
@@ -151,27 +357,46 @@
151 357
152 358 // =====================================================================
153 359 // Fetch admin pages (backend)
154 360
155 -function code_profiler_fetch_admin_pages( $home ) {
361 +function code_profiler_fetch_admin_pages( $home, $cp_options ) {
156 362
157 363 $backend = '';
364 +
365 + if ( empty( $cp_options['mem_post'] ) ) {
366 + $cp_options['mem_post'] = $home;
367 + }
368 +
158 369 if (! empty( $GLOBALS[ 'menu' ] ) ) {
159 370 foreach( $GLOBALS[ 'menu' ] as $menu => $value ) {
160 - if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php' ) {
371 + if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php') {
161 372 // E.g., "Comments", "Plugins" etc
162 - $value[0] = trim( preg_replace( '/\s+<.+$/', '', $value[0] ) );
163 - $backend .= '<option value="'. esc_attr( "{$home}wp-admin/{$value[2]}" ) .'" title="'.
164 - esc_attr( "{$home}wp-admin/{$value[2]}" ) .'">'.
165 - esc_html( $value[0] ) .'</option>';
373 + $value[0] = trim( preg_replace('/\s*<.+$/', '', $value[0] ) );
374 +
375 + if ( $cp_options['mem_post'] == "{$home}wp-admin/{$value[2]}" ) {
376 + $backend .= sprintf(
377 + '<option value="%1$s" title="%1$s" selected>%2$s</option>',
378 + esc_attr("{$home}wp-admin/{$value[2]}"),
379 + esc_html( $value[0] )
380 + );
381 + } else {
382 + $backend .= sprintf(
383 + '<option value="%1$s" title="%1$s">%2$s</option>',
384 + esc_attr("{$home}wp-admin/{$value[2]}"),
385 + esc_html( $value[0] )
386 + );
387 + }
166 388 }
167 389 }
168 390 }
169 391 if ( empty( $backend ) ) {
170 - $backend = '<option value="'. esc_attr( $home ) .'wp-admin/" title="'. esc_attr( $home ) .'wp-admin/">'.
171 - esc_html__( 'Dashboard' ) .'</option>';
392 + $backend = sprintf(
393 + '<option value="%1$swp-admin/" title="%1$swp-admin/">%2$s</option>',
394 + esc_attr( $home ),
395 + esc_html__('Dashboard', 'code-profiler')
396 + );
397 +
172 398 }
173 -
174 399 return $backend;
175 400 }
176 401
177 402 // =====================================================================