PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.4
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.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
code-profiler / lib / menu_view_plugins.php

menu_view_plugins.php in Code Profiler – WordPress Performance Profiling and Debugging Made Easy 1.4, at lib/menu_view_plugins.php

123 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +=====================================================================+
4 | ____ _ ____ __ _ _ |
5 | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ |
6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 | |
10 | (c) Jerome Bruandet ~ https://code-profiler.com/ |
11 +=====================================================================+
12 */
13
14 if (! defined( 'ABSPATH' ) ) { die( 'Forbidden' ); }
15
16 // =====================================================================
17 // Display Plugins & Theme stats.
18
19 $buffer = code_profiler_get_profile_data( $profile_path, 'slugs' );
20 if ( isset( $buffer['error'] ) ) {
21 return;
22 }
23
24 // Fetch options
25 $cp_options = get_option( 'code-profiler' );
26
27 // Name vs slug
28 if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) {
29 $cp_options['display_name'] = 'full';
30 }
31 // Truncate name
32 if ( empty( $cp_options['truncate_name'] ) || ! preg_match( '/^\d+$/', ( $cp_options['truncate_name'] ) ) ) {
33 $cp_options['truncate_name'] = 30;
34 }
35 // Horizontal vs vertical chart
36 if ( empty( $cp_options['chart_type'] ) || ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) {
37 $axis = 'x';
38 } else {
39 $axis = $cp_options['chart_type'];
40 }
41 // Max plugins to display
42 if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match( '/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) {
43 $chart_max_plugins = 25;
44 } else {
45 $chart_max_plugins = $cp_options['chart_max_plugins'];
46 }
47
48 $label = [];
49 $data = '';
50 $theme = esc_attr__('theme', 'code-profiler');
51 $total_time = 0;
52 $hidden = 0;
53 $count = 0;
54 // Sort by value
55 usort( $buffer, function( $a, $b ) {
56 return $b[1] <=> $a[1];
57 } );
58 foreach( $buffer as $k => $slugs ) {
59
60 if ( empty( $slugs[1] ) && ! empty( $cp_options['hide_empty_value'] ) ) {
61 $hidden++;
62 $hidden_empty = 1;
63 continue;
64 }
65
66 $count++;
67 if ( $count > $chart_max_plugins ) {
68 $hidden++;
69 $hidden_max_plugins = 1;
70 continue;
71 }
72
73 // Check whether we should use the name or the slug
74 if ( $cp_options['display_name'] == 'slug' ) {
75 $n = $slugs[0];
76 } else {
77 $n = $slugs[2];
78 }
79
80 // Truncate and sanitise the name
81 if ( strlen( $n ) > $cp_options['truncate_name'] ) {
82 $n = mb_substr( $n, 0, $cp_options['truncate_name'] , 'utf-8') .'...';
83 }
84
85 // Mark theme as such
86 if ( $slugs[3] == 'theme' ) {
87 $label[] = "{$n} ($theme)";
88 } else {
89 $label[] = $n;
90 }
91
92 $data .= "{$slugs[1]},";
93 $total_time += $slugs[1];
94 }
95 $data = rtrim( $data, ',' );
96 $count = count( $label ) - 1;
97 ?>
98 <div style="width:80vw;margin:auto">
99 <canvas id="myChart"></canvas>
100 </div>
101 <script>
102 jQuery(document).ready(function() {
103 'use strict';
104 cpjs_plugins_chart(
105 '<?php echo esc_js( $axis ) ?>', [<?php
106 for( $i = 0; $i < $count; $i++ ) {
107 echo "'". addslashes( $label[ $i ] ) ."',";
108 }
109 echo "'". esc_js( $label[ $i ] ) ."'";
110 ?>],
111 [<?php echo esc_js( $data ) ?>], <?php echo esc_js( number_format( $total_time, 4 ) ) ?>
112 );
113 });
114 </script>
115 <?php
116 // Actions below stats
117 $save_png = 1;
118 $rotate_img = 1;
119 $type = 'slugs';
120
121 // =====================================================================
122 // EOF
123