| @@ -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,249 +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 | - }else { | |
| 90 | - // Display why we don't want to run. | |
| 91 | - wp_die( esc_html__('Missing profile ID.', 'code-profiler') ); | |
| 92 | - } | |
| 57 | +// Memorized options | |
| 58 | +if ( empty( $cp_options['mem_where'] ) ) { | |
| 59 | + $cp_options['mem_where'] = 'frontend'; | |
| 93 | 60 | } |
| 94 | -// Profile's name | |
| 95 | -if (! empty( $cp_options['mem']['profile'] ) ) { | |
| 96 | - $profile = $cp_options['mem']['profile']; | |
| 97 | -} else { | |
| 98 | - $profile = code_profiler_profile_name(); | |
| 61 | +if ( empty( $cp_options['mem_post'] ) ) { | |
| 62 | + $cp_options['mem_post'] = ''; | |
| 99 | 63 | } |
| 100 | -/** | |
| 101 | - * Memorized options from last run. | |
| 102 | - */ | |
| 103 | -if ( empty( $cp_options['mem']['x_end'] ) ) { | |
| 104 | - $cp_options['mem']['x_end'] = 'frontend'; | |
| 64 | +if ( empty( $cp_options['mem_user'] ) ) { | |
| 65 | + $cp_options['mem_user'] = 'unauthenticated'; | |
| 105 | 66 | } |
| 106 | -if ( empty( $cp_options['mem']['post'] ) ) { | |
| 107 | - $cp_options['mem']['post'] = ''; | |
| 67 | +if ( $cp_options['mem_where'] == 'backend') { | |
| 68 | + $cp_options['mem_user'] = 'authenticated'; | |
| 108 | 69 | } |
| 109 | -if ( empty( $cp_options['mem']['x_auth'] ) ) { | |
| 110 | - $cp_options['mem']['x_auth'] = 'unauthenticated'; | |
| 70 | +if ( empty( $cp_options['mem_method'] ) ) { | |
| 71 | + $cp_options['mem_method'] = 'get'; | |
| 111 | 72 | } |
| 112 | -if ( $cp_options['mem']['x_end'] == 'backend') { | |
| 113 | - $cp_options['mem']['x_auth'] = 'authenticated'; | |
| 114 | -} | |
| 115 | -if ( empty( $cp_options['mem']['method'] ) ) { | |
| 116 | - $cp_options['mem']['method'] = 'get'; | |
| 117 | -} | |
| 118 | 73 | $default_theme = get_option('stylesheet'); |
| 119 | -if ( empty( $cp_options['mem']['theme'] ) ) { | |
| 120 | - $cp_options['mem']['theme'] = $default_theme; | |
| 74 | +if ( empty( $cp_options['mem_theme'] ) ) { | |
| 75 | + $cp_options['mem_theme'] = $default_theme; | |
| 121 | 76 | } |
| 122 | -if ( empty( $cp_options['mem']['user_agent'] ) ) { | |
| 123 | - $cp_options['mem']['user_agent'] = 'Firefox'; | |
| 77 | +if ( empty( $cp_options['ua'] ) ) { | |
| 78 | + $cp_options['ua'] = 'Firefox'; | |
| 124 | 79 | } |
| 125 | -if ( isset( $cp_options['mem']['cookies'] ) ) { | |
| 80 | +$cookies = ''; | |
| 81 | +$payload = ''; | |
| 82 | +$custom_headers = ''; | |
| 83 | +$exclusions = []; | |
| 84 | + | |
| 85 | +if ( isset( $cp_options['cookies'] ) ) { | |
| 126 | 86 | // stripslashes is only needed for cookies |
| 127 | - $cookies = trim( stripslashes( json_decode( $cp_options['mem']['cookies'] ) ) ); | |
| 128 | -} else { | |
| 129 | - $cookies = ''; | |
| 87 | + $cookies = trim( stripslashes( json_decode( $cp_options['cookies'] ) ) ); | |
| 130 | 88 | } |
| 131 | -if ( empty( $cp_options['mem']['content_type'] ) || | |
| 132 | - ! 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 ] ) ) { | |
| 133 | 91 | |
| 134 | - $cp_options['mem']['content_type'] = 1; | |
| 92 | + $cp_options['mem_content_type'] = 1; | |
| 135 | 93 | } |
| 136 | -if ( isset( $cp_options['mem']['payload'] ) ) { | |
| 137 | - $payload = trim( json_decode( $cp_options['mem']['payload'] ) ); | |
| 138 | -} else { | |
| 139 | - $payload = ''; | |
| 94 | +if ( isset( $cp_options['payload'] ) ) { | |
| 95 | + $payload = trim( json_decode( $cp_options['payload'] ) ); | |
| 140 | 96 | } |
| 141 | -if ( isset( $cp_options['mem']['custom_headers'] ) ) { | |
| 142 | - $custom_headers = trim( json_decode( $cp_options['mem']['custom_headers'] ) ); | |
| 143 | -} else { | |
| 144 | - $custom_headers = ''; | |
| 97 | +if ( isset( $cp_options['custom_headers'] ) ) { | |
| 98 | + $custom_headers = trim( json_decode( $cp_options['custom_headers'] ) ); | |
| 145 | 99 | } |
| 146 | -if ( isset( $cp_options['mem']['exclusions'] ) ) { | |
| 147 | - $exclusions = json_decode( $cp_options['mem']['exclusions'] ); | |
| 148 | -} else { | |
| 149 | - $exclusions = []; | |
| 100 | +if ( isset( $cp_options['exclusions'] ) ) { | |
| 101 | + $exclusions = json_decode( $cp_options['exclusions'] ); | |
| 150 | 102 | } |
| 151 | - | |
| 152 | 103 | ?> |
| 153 | - | |
| 154 | -<table style="width:100%"> | |
| 104 | +<table class="form-table"> | |
| 155 | 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> | |
| 156 | 107 | <td> |
| 157 | - <table class="form-table"> | |
| 158 | - <tr> | |
| 159 | - <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> | |
| 160 | - <td> | |
| 161 | - <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> | |
| 162 | - | |
| 163 | - <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> | |
| 164 | - | |
| 165 | - <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> | |
| 166 | - | |
| 167 | - <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> | |
| 168 | - </p> | |
| 169 | - <br /> | |
| 170 | - <?php | |
| 171 | - if ( $cp_options['mem']['x_end'] == 'frontend') { | |
| 172 | - echo '<p id="p-frontend">'; | |
| 173 | - } else { | |
| 174 | - echo '<p id="p-frontend" style="display:none">'; | |
| 175 | - } | |
| 176 | - ?> | |
| 177 | - <?php esc_html_e('Select a page:', 'code-profiler') ?> | |
| 178 | - <select name="frontend" id="id-frontend"> | |
| 179 | - <?php echo code_profiler_fetch_pages( $home, $cp_options ); ?> | |
| 180 | - </select> | |
| 181 | - </p> | |
| 182 | - <?php | |
| 183 | - if ( $cp_options['mem']['x_end'] == 'custom') { | |
| 184 | - $value = $cp_options['mem']['post']; | |
| 185 | - echo '<p id="p-custom">'; | |
| 186 | - } else { | |
| 187 | - $value = ''; | |
| 188 | - echo '<p id="p-custom" style="display:none">'; | |
| 189 | - } | |
| 190 | - ?> | |
| 191 | - <input name="custom" id="id-custom" type="text" value="<?php echo esc_attr( $value ) ?>" size="70" placeholder="<?php | |
| 192 | - echo esc_attr( | |
| 193 | - sprintf( | |
| 194 | - __('e.g., %s', 'code-profiler'), | |
| 195 | - "{$home}foo/bar/" | |
| 196 | - ) | |
| 197 | - ) ?>" /> | |
| 198 | - </p> | |
| 199 | - <?php | |
| 200 | - if ( $cp_options['mem']['x_end'] == 'backend') { | |
| 201 | - echo '<p id="p-backend">'; | |
| 202 | - } else { | |
| 203 | - echo '<p id="p-backend" style="display:none">'; | |
| 204 | - } | |
| 205 | - if (! empty( $cp_options['mem']['username'] ) ) { | |
| 206 | - $username = $cp_options['mem']['username']; | |
| 207 | - } else { | |
| 208 | - $username = $current_user->user_login; | |
| 209 | - } | |
| 210 | - ?> | |
| 211 | - <?php esc_html_e('Select a page:', 'code-profiler') ?> | |
| 212 | - <select name="backend" id="id-backend"><?php echo code_profiler_fetch_admin_pages( $site, $cp_options ) ?></select> | |
| 213 | - </p> | |
| 214 | - <?php | |
| 215 | - /** | |
| 216 | - * Cron tasks. | |
| 217 | - */ | |
| 218 | - if ( $cp_options['mem']['x_end'] == 'wpcron') { | |
| 219 | - echo '<p id="p-wpcron">'; | |
| 220 | - } else { | |
| 221 | - echo '<p id="p-wpcron" style="display:none">'; | |
| 222 | - } | |
| 223 | - ?> | |
| 224 | - <?php esc_html_e('Select a cron event:', 'code-profiler') ?> | |
| 225 | - <select name="wpcron" id="id-wpcron"> | |
| 226 | - <?php echo code_profiler_fetch_crontasks( $cp_options['mem']['post'] ); ?> | |
| 227 | - </select> | |
| 228 | - </p> | |
| 229 | - </td> | |
| 230 | - </tr> | |
| 231 | - <tr> | |
| 232 | - <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> | |
| 233 | - <td> | |
| 234 | - <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> | |
| 235 | - <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> | |
| 236 | - <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> | |
| 237 | - </td> | |
| 238 | - </tr> | |
| 239 | - <tr> | |
| 240 | - <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> | |
| 241 | - <td> | |
| 242 | - <select name="theme" id="id-theme"> | |
| 243 | - <?php | |
| 244 | - $themes = code_profiler_get_themes(); | |
| 245 | - foreach( $themes as $slug => $name ) { | |
| 246 | - if ( $slug == $default_theme ) { | |
| 247 | - echo '<option value=""'. selected( $cp_options['mem']['theme'], $slug, false ) .'>'. | |
| 248 | - esc_html( $name['n'] ) .' '. __('(active theme)', 'code-profiler') .'</option>'; | |
| 249 | - } else { | |
| 250 | - echo '<option value="'. esc_attr( $slug ) .'"'. selected( $cp_options['mem']['theme'], $slug, false ) .'>'. | |
| 251 | - esc_html( $name['n'] ) .'</option>'; | |
| 252 | - } | |
| 253 | - } | |
| 254 | - ?> | |
| 255 | - </select> | |
| 256 | - </td> | |
| 257 | - </tr> | |
| 258 | - <tr> | |
| 259 | - <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> | |
| 260 | - <td> | |
| 261 | - <select name="user_agent" id="ua-id"> | |
| 262 | - <?php | |
| 263 | - foreach( CODE_PROFILER_UA as $types => $types_array ) { | |
| 264 | - echo '<optgroup label="'. esc_attr( $types ) .'">'; | |
| 265 | - foreach( $types_array as $name => $value ) { | |
| 266 | - echo '<option value="'. esc_attr( $name ) .'"'. selected( $cp_options['mem']['user_agent'], $name, false ) .'>'. esc_html( $name ) .'</option>'; | |
| 267 | - } | |
| 268 | - echo '</optgroup>'; | |
| 269 | - } | |
| 270 | - ?> | |
| 271 | - </select> | |
| 272 | - </td> | |
| 273 | - </tr> | |
| 274 | - <tr> | |
| 275 | - <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> | |
| 276 | - <td> | |
| 277 | - <p><label><input type="text" class="regular-text" name="profile" maxlength="100" value="<?php echo esc_attr( $profile ) ?>" id="profile-name" /></label></p> | |
| 278 | - <p class="description"><?php esc_html_e('Max 100 characters', 'code-profiler') ?></p> | |
| 279 | - </td> | |
| 280 | - </tr> | |
| 281 | - </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 | + | |
| 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 | + | |
| 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> | |
| 282 | 159 | </td> |
| 283 | - <td style="vertical-align:top;text-align: center"> | |
| 284 | - <?php | |
| 285 | - /** | |
| 286 | - * Display any available discount coupon. | |
| 287 | - */ | |
| 288 | - CodeProfiler_WPCron::display_coupon(); | |
| 289 | - ?> | |
| 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> | |
| 290 | 167 | </td> |
| 291 | 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> | |
| 292 | 211 | </table> |
| 293 | 212 | <?php |
| 294 | -if ( (! empty( $cookies ) || ! empty( $custom_headers ) || | |
| 295 | - $cp_options['mem']['method'] == 'post' || ! empty( $exclusions ) ) && | |
| 296 | - // We don't display the advanced section if the last profile was a cron event. | |
| 297 | - $cp_options['mem']['x_end'] != 'wpcron' ) { | |
| 298 | - | |
| 213 | +if (! empty( $cookies ) || ! empty( $custom_headers ) || $cp_options['mem_method'] == 'post' || ! empty( $exclusions ) ) { | |
| 299 | 214 | echo '<div id="cp-advanced-settings">'; |
| 300 | 215 | $disabled_button = ' disabled'; |
| 301 | 216 | } else { |
| 302 | 217 | echo '<div id="cp-advanced-settings" style="display:none">'; |
| @@ -308,36 +223,32 @@ | ||
| 308 | 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> |
| 309 | 224 | <td> |
| 310 | 225 | <p> |
| 311 | 226 | <label> |
| 312 | - <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') ?>) | |
| 313 | 228 | </label> |
| 314 | 229 | </p> |
| 315 | 230 | <p> |
| 316 | 231 | <label> |
| 317 | - <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 | |
| 318 | 233 | </label> |
| 319 | 234 | </p> |
| 320 | 235 | <p> |
| 321 | 236 | <?php esc_html_e('Content-type:', 'code-profiler') ?> |
| 322 | - <select name="cp-content-type" id="id-content-type"<?php disabled( $cp_options['mem']['method'], 'get') ?> onChange="cpjs_content_type(this.value);"> | |
| 323 | - <option value="1"<?php selected( $cp_options['mem']['content_type'], 1 )?>>application/x-www-form-urlencoded (<?php esc_html_e('formatted', 'code-profiler') ?>)</option> | |
| 324 | - <option value="3"<?php selected( $cp_options['mem']['content_type'], 3 )?>>application/x-www-form-urlencoded (<?php esc_html_e('raw', 'code-profiler') ?>)</option> | |
| 325 | - <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> | |
| 326 | 240 | </select> |
| 327 | 241 | </p> |
| 328 | 242 | <p> |
| 329 | - <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> | |
| 330 | 244 | </p> |
| 331 | - <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) ?>> | |
| 332 | 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>') ?> |
| 333 | 247 | </p> |
| 334 | - <p class="description" id="ct-3"<?php echo code_profiler_showhide( $cp_options['mem']['content_type'], 3 ) ?>> | |
| 335 | - <?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>') ?> | |
| 336 | 250 | </p> |
| 337 | - <p class="description" id="ct-2"<?php echo code_profiler_showhide( $cp_options['mem']['content_type'], 2 ) ?>> | |
| 338 | - <?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>') ?> | |
| 339 | - </p> | |
| 340 | 251 | </td> |
| 341 | 252 | </tr> |
| 342 | 253 | <tr> |
| 343 | 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> |
| @@ -377,17 +288,11 @@ | ||
| 377 | 288 | <br /> |
| 378 | 289 | <div class="cp-progress-bar"><span id="cp-span-progress" style="width:0%"></span></div> |
| 379 | 290 | <img style="vertical-align:middle;display:none" id="progress-gif" src="<?php echo plugins_url('/static/progress.gif', dirname (__FILE__ ) ) ?>" /> <font id="progress-text" style="display:none"><?php esc_html_e('Starting the profiler...', 'code-profiler') ?></font> |
| 380 | 291 | </div> |
| 292 | + | |
| 381 | 293 | <?php |
| 382 | 294 | |
| 383 | -/** | |
| 384 | - * Re-run a profile. | |
| 385 | - */ | |
| 386 | -if (! empty( $rerun ) ) { | |
| 387 | - echo '<script>window.addEventListener("load", cpjs_start_profiler);</script>'; | |
| 388 | -} | |
| 389 | - | |
| 390 | 295 | // ===================================================================== |
| 391 | 296 | // Fetch pages and posts. |
| 392 | 297 | |
| 393 | 298 | function code_profiler_fetch_pages( $home, $cp_options ) { |
| @@ -393,13 +298,13 @@ | ||
| 393 | 298 | function code_profiler_fetch_pages( $home, $cp_options ) { |
| 394 | 299 | |
| 395 | 300 | $posts = ''; |
| 396 | 301 | |
| 397 | - if ( empty( $cp_options['mem']['post'] ) ) { | |
| 398 | - $cp_options['mem']['post'] = $home; | |
| 302 | + if ( empty( $cp_options['mem_post'] ) ) { | |
| 303 | + $cp_options['mem_post'] = $home; | |
| 399 | 304 | } |
| 400 | 305 | |
| 401 | - if ( $cp_options['mem']['post'] == $home ) { | |
| 306 | + if ( $cp_options['mem_post'] == $home ) { | |
| 402 | 307 | $pages = sprintf( |
| 403 | 308 | '<option value="%1$s" title="%1$s" selected>%2$s</option>', |
| 404 | 309 | esc_attr( $home ), |
| 405 | 310 | esc_html__('Homepage', 'code-profiler') |
| @@ -427,9 +332,9 @@ | ||
| 427 | 332 | $item->post_title = __('Untitled'); |
| 428 | 333 | } |
| 429 | 334 | $permalink = get_permalink( $item->ID ); |
| 430 | 335 | |
| 431 | - if ( $cp_options['mem']['post'] == $permalink ) { | |
| 336 | + if ( $cp_options['mem_post'] == $permalink ) { | |
| 432 | 337 | $pages .= sprintf( |
| 433 | 338 | '<option value="%1$s" title="%1$s" selected>%2$s</option>', |
| 434 | 339 | esc_attr( $permalink ), |
| 435 | 340 | esc_html( $item->post_title ) |
| @@ -456,10 +361,10 @@ | ||
| 456 | 361 | function code_profiler_fetch_admin_pages( $home, $cp_options ) { |
| 457 | 362 | |
| 458 | 363 | $backend = ''; |
| 459 | 364 | |
| 460 | - if ( empty( $cp_options['mem']['post'] ) ) { | |
| 461 | - $cp_options['mem']['post'] = $home; | |
| 365 | + if ( empty( $cp_options['mem_post'] ) ) { | |
| 366 | + $cp_options['mem_post'] = $home; | |
| 462 | 367 | } |
| 463 | 368 | |
| 464 | 369 | if (! empty( $GLOBALS[ 'menu' ] ) ) { |
| 465 | 370 | foreach( $GLOBALS[ 'menu' ] as $menu => $value ) { |
| @@ -466,9 +371,9 @@ | ||
| 466 | 371 | if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php') { |
| 467 | 372 | // E.g., "Comments", "Plugins" etc |
| 468 | 373 | $value[0] = trim( preg_replace('/\s*<.+$/', '', $value[0] ) ); |
| 469 | 374 | |
| 470 | - if ( $cp_options['mem']['post'] == "{$home}wp-admin/{$value[2]}" ) { | |
| 375 | + if ( $cp_options['mem_post'] == "{$home}wp-admin/{$value[2]}" ) { | |
| 471 | 376 | $backend .= sprintf( |
| 472 | 377 | '<option value="%1$s" title="%1$s" selected>%2$s</option>', |
| 473 | 378 | esc_attr("{$home}wp-admin/{$value[2]}"), |
| 474 | 379 | esc_html( $value[0] ) |
| @@ -491,44 +396,8 @@ | ||
| 491 | 396 | ); |
| 492 | 397 | |
| 493 | 398 | } |
| 494 | 399 | return $backend; |
| 495 | -} | |
| 496 | - | |
| 497 | -// ===================================================================== | |
| 498 | -// Fetch scheduled tasks. | |
| 499 | - | |
| 500 | -function code_profiler_fetch_crontasks( $mem ) { | |
| 501 | - | |
| 502 | - $cron_list = ''; | |
| 503 | - | |
| 504 | - $wp_crons = code_profiler_get_crons(); | |
| 505 | - | |
| 506 | - if ( empty( $wp_crons ) ) { | |
| 507 | - $cron_list = sprintf( | |
| 508 | - '<option value="0">%s</option>', | |
| 509 | - esc_html__('No cron tasks found.', 'code-profiler') | |
| 510 | - ); | |
| 511 | - return $cron_list; | |
| 512 | - } | |
| 513 | - | |
| 514 | - foreach( $wp_crons as $cron ) { | |
| 515 | - | |
| 516 | - if ( $mem == $cron ) { | |
| 517 | - $selected = ' selected'; | |
| 518 | - } else { | |
| 519 | - $selected = ''; | |
| 520 | - } | |
| 521 | - | |
| 522 | - $cron_list .= sprintf( | |
| 523 | - "<option value='%s'%s>%s</option>", | |
| 524 | - esc_attr( $cron ), | |
| 525 | - $selected, | |
| 526 | - esc_html( $cron ) | |
| 527 | - ); | |
| 528 | - } | |
| 529 | - | |
| 530 | - return $cron_list; | |
| 531 | 400 | } |
| 532 | 401 | |
| 533 | 402 | // ===================================================================== |
| 534 | 403 | // EOF |