PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.9.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.9.6
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/class-table-profiles.php +55 -20 1.6.61.9.6 View file →
@@ -6,9 +6,9 @@
6 6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 9 | |
10 - | (c) Jerome Bruandet ~ https://code-profiler.com/ |
10 + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
11 11 +=====================================================================+
12 12 */
13 13
14 14 if (! defined('ABSPATH') ) {
@@ -26,8 +26,12 @@
26 26 'slugs',
27 27 'summary',
28 28 'composer'
29 29 ];
30 + private $optional_files = [
31 + 'summary',
32 + 'composer'
33 + ];
30 34 private $abspath;
31 35 private $row_count = 0;
32 36
33 37
@@ -50,9 +54,8 @@
50 54 * Empty list
51 55 */
52 56 function no_items() {
53 57 esc_html_e('No profile found.', 'code-profiler');
54 - $this->is_empty = 1;
55 58 }
56 59
57 60
58 61 /**
@@ -111,15 +114,15 @@
111 114 */
112 115 function get_columns(){
113 116 return [
114 117 'cb' => '<input type="checkbox" />',
115 - 'profile' => esc_html__( 'Profile', 'code-profiler' ),
116 - 'date' => esc_html__( 'Date', 'code-profiler' ),
117 - 'items' => esc_html__( 'Items', 'code-profiler' ),
118 - 'time' => esc_html__( 'Time', 'code-profiler' ),
119 - 'mem' => esc_html__( 'Memory', 'code-profiler' ),
120 - 'io' => esc_html__( 'File I/O', 'code-profiler' ),
121 - 'queries' => esc_html__( 'SQL', 'code-profiler' )
118 + 'profile' => esc_html__('Profile', 'code-profiler'),
119 + 'date' => esc_html__('Date', 'code-profiler'),
120 + 'items' => esc_html__('Items', 'code-profiler'),
121 + 'time' => esc_html__('Time', 'code-profiler'),
122 + 'mem' => esc_html__('Memory', 'code-profiler'),
123 + 'io' => esc_html__('File I/O', 'code-profiler'),
124 + 'queries' => esc_html__('SQL', 'code-profiler')
122 125 ];
123 126 }
124 127
125 128
@@ -157,8 +160,25 @@
157 160 // Keep sorting order for the "delete" action link
158 161 $orderby = (! empty( $_GET['orderby'] ) ) ? sanitize_key( $_GET['orderby'] ) : 'ID';
159 162 $order = (! empty( $_GET['order'] ) ) ? sanitize_key( $_GET['order'] ) : 'asc';
160 163
164 + /**
165 + * The option to re-run a profile is only available with profiles created with v1.8.
166 + */
167 + if (! empty( $item['rerun'] ) ) {
168 + $rerun = sprintf(
169 + '<a href="?page=code-profiler&cptab=profiler&action=rerun&profiles[]=%1$s" title="'.
170 + esc_attr__('Re-run the profile with the same options and parameters.', 'code-profiler') .
171 + '">%2$s</a>',
172 + esc_attr( $item['ID'] ),
173 + esc_html__('Re-run', 'code-profiler')
174 + );
175 + } else {
176 + $rerun = '<font style="cursor:not-allowed" title="'.
177 + esc_attr__('This feature is only available with profiles created with Code Profiler v1.8+',
178 + 'code-profiler') .'">'. esc_html__('Re-run', 'code-profiler') .'</font>';
179 + }
180 +
161 181 $actions = array(
162 182 'view' => sprintf(
163 183 '<a href="?page=code-profiler&cptab=profiles_list&action=%s&id=%s&section=1">%s</a>',
164 184 'view_profile',
@@ -169,11 +189,12 @@
169 189 '<a style="cursor:pointer" onClick="cpjs_toggle_name(\'%s\')">%s</a>',
170 190 esc_attr( $this->row_count ),
171 191 esc_html__('Quick Edit')
172 192 ),
193 + 'rerun' => $rerun,
173 194 'delete' => sprintf(
174 - '<a href="?page=code-profiler&cptab=profiles_list&action=%s&profiles[]=%s&_wpnonce=%s&orderby=%s&order=%s" '.
175 - 'onclick="return cpjs_delete_profile();">%s</a>',
195 + '<a href="?page=code-profiler&cptab=profiles_list&action=%s&profiles[]=%s'.
196 + '&_wpnonce=%s&orderby=%s&order=%s" onclick="return cpjs_delete_profile();">%s</a>',
176 197 'delete_profiles',
177 198 esc_attr( $item['ID'] ),
178 199 wp_create_nonce('bulk-'. $this->_args['plural'] ),
179 200 $orderby,
@@ -264,9 +285,9 @@
264 285 */
265 286 function fetch_profiles() {
266 287
267 288 $profiles = [];
268 - $glob = glob( CODE_PROFILER_UPLOAD_DIR .'/*.slugs.profile');
289 + $glob = code_profiler_glob( CODE_PROFILER_UPLOAD_DIR, '\.slugs\.profile$', true );
269 290
270 291 if ( is_array( $glob ) ) {
271 292 $count = 0;
272 293 foreach( $glob as $path ) {
@@ -275,11 +296,15 @@
275 296
276 297 $error = 0; $fsize = 0;
277 298 // Make sure we have all profile files
278 299 foreach( $this->default_files as $pname ) {
279 - // Ignore these ones, there aren't mandatory
280 - if ( in_array( $pname, [ 'composer', 'summary' ] ) ) { continue; }
281 - if ( file_exists( CODE_PROFILER_UPLOAD_DIR ."/{$match[1]}.{$match[2]}.$pname.profile" ) ) {
300 + /**
301 + * Ignore these ones, there aren't mandatory.
302 + */
303 + if ( in_array( $pname, $this->optional_files ) ) {
304 + continue;
305 + }
306 + if ( is_file( CODE_PROFILER_UPLOAD_DIR ."/{$match[1]}.{$match[2]}.$pname.profile" ) ) {
282 307 $fsize += filesize( CODE_PROFILER_UPLOAD_DIR ."/{$match[1]}.{$match[2]}.$pname.profile" );
283 308 } else {
284 309 $error = 1;
285 310 break;
@@ -287,9 +312,9 @@
287 312 }
288 313 // Delete if incomplete
289 314 if ( $error ) {
290 315 foreach( $this->default_files as $pname ) {
291 - if ( file_exists( CODE_PROFILER_UPLOAD_DIR ."/{$match[1]}.{$match[2]}.$pname.profile" ) ) {
316 + if ( is_file( CODE_PROFILER_UPLOAD_DIR ."/{$match[1]}.{$match[2]}.$pname.profile" ) ) {
292 317 unlink( CODE_PROFILER_UPLOAD_DIR ."/{$match[1]}.{$match[2]}.$pname.profile" );
293 318 }
294 319 }
295 320 continue;
@@ -298,10 +323,14 @@
298 323 // Search query
299 324 $search = false;
300 325 if (! empty( $_REQUEST['s'] ) ) {
301 326 foreach( $this->default_files as $pname ) {
302 - // Ignore these ones, there aren't mandatory
303 - if ( in_array( $pname, [ 'composer', 'summary' ] ) ) { continue; }
327 + /**
328 + * Ignore these ones, there aren't mandatory.
329 + */
330 + if ( in_array( $pname, $this->optional_files ) ) {
331 + continue;
332 + }
304 333 $search = $this->search_profile_file(
305 334 CODE_PROFILER_UPLOAD_DIR ."/{$match[1]}.{$match[2]}.$pname.profile",
306 335 sanitize_text_field( $_REQUEST['s'] )
307 336 );
@@ -325,8 +354,14 @@
325 354 if ( empty( $summary['time'] ) ) { $summary['time'] = '-'; }
326 355 if ( empty( $summary['items'] ) ) { $summary['items'] = '-'; }
327 356 if ( empty( $summary['io'] ) ) { $summary['io'] = '-'; }
328 357
358 + /**
359 + * Check if we can re-run the profile (v1.8+).
360 + */
361 + if (! empty( $summary['rerun'] ) ) {
362 + $profiles[$count]['rerun'] = true;
363 + }
329 364 $fsize += filesize( $path );
330 365 $profiles[$count]['ID'] = $match[1];
331 366 $profiles[$count]['profile'] = esc_html( $match[2] );
332 367 $profiles[$count]['date'] = filemtime( $path );
@@ -384,10 +419,10 @@
384 419 $error = true;
385 420 continue;
386 421 }
387 422 foreach( $this->default_files as $pname ) {
388 - if ( file_exists( "$profile_name.$pname.profile" ) ) {
389 - unlink( "$profile_name.$pname.profile" );
423 + if ( is_file( "$profile_name.$pname.profile") ) {
424 + unlink( "$profile_name.$pname.profile");
390 425 }
391 426 }
392 427 }
393 428 return $error;