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_view_plugins.php +67 -25 1.51.7.4 View file →
@@ -6,41 +6,51 @@
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') ) {
15 + die('Forbidden');
16 +}
15 17
16 -// =====================================================================
18 +// ===================================================================== 2023-11-17
17 19 // Display Plugins & Theme stats.
18 20
19 -$buffer = code_profiler_get_profile_data( $profile_path, 'slugs' );
21 +$buffer = code_profiler_get_profile_data( $profile_path, 'slugs');
20 22 if ( isset( $buffer['error'] ) ) {
21 23 return;
22 24 }
23 25
24 26 // Fetch options
25 -$cp_options = get_option( 'code-profiler' );
27 +$cp_options = get_option('code-profiler');
26 28
27 29 // Name vs slug
28 -if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) {
30 +if ( empty( $cp_options['display_name'] ) ||
31 + ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) {
32 +
29 33 $cp_options['display_name'] = 'full';
30 34 }
31 35 // Truncate name
32 -if ( empty( $cp_options['truncate_name'] ) || ! preg_match( '/^\d+$/', ( $cp_options['truncate_name'] ) ) ) {
36 +if ( empty( $cp_options['truncate_name'] ) ||
37 + ! preg_match('/^\d+$/', ( $cp_options['truncate_name'] ) ) ) {
38 +
33 39 $cp_options['truncate_name'] = 30;
34 40 }
35 41 // Horizontal vs vertical chart
36 -if ( empty( $cp_options['chart_type'] ) || ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) {
42 +if ( empty( $cp_options['chart_type'] ) ||
43 + ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) {
44 +
37 45 $axis = 'x';
38 46 } else {
39 47 $axis = $cp_options['chart_type'];
40 48 }
41 49 // Max plugins to display
42 -if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match( '/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) {
50 +if ( empty( $cp_options['chart_max_plugins'] ) ||
51 + ! preg_match('/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) {
52 +
43 53 $chart_max_plugins = 25;
44 54 } else {
45 55 $chart_max_plugins = $cp_options['chart_max_plugins'];
46 56 }
@@ -75,9 +85,9 @@
75 85 continue;
76 86 }
77 87
78 88 // Check whether we should use the name or the slug
79 - if ( $cp_options['display_name'] == 'slug' ) {
89 + if ( $cp_options['display_name'] == 'slug') {
80 90 $n = $slugs[0];
81 91 } else {
82 92 $n = $slugs[2];
83 93 }
@@ -87,12 +97,12 @@
87 97 $n = mb_substr( $n, 0, $cp_options['truncate_name'] , 'utf-8') .'...';
88 98 }
89 99
90 100 // Mark theme as such
91 - if ( $slugs[3] == 'theme' ) {
101 + if ( $slugs[3] == 'theme') {
92 102 $label[] = "{$n} ($theme)";
93 103 // ...and MU plugins
94 - } elseif ( $slugs[3] == 'mu-plugin' ) {
104 + } elseif ( $slugs[3] == 'mu-plugin') {
95 105 $label[] = "{$n} (MU)";
96 106 } else {
97 107 $label[] = $n;
98 108 }
@@ -99,12 +109,12 @@
99 109
100 110 $data .= "{$slugs[1]},";
101 111 $total_time += $slugs[1];
102 112 }
103 -$data = rtrim( $data, ',' );
113 +$data = rtrim( $data, ',');
104 114 $count = count( $label ) - 1;
105 115 ?>
106 -<div style="width:80vw;margin:auto">
116 +<div style="width:80vw;margin:auto" aria-hidden="true">
107 117 <canvas id="myChart"></canvas>
108 118 </div>
109 119 <script>
110 120 jQuery(document).ready(function() {
@@ -119,15 +129,39 @@
119 129 [<?php echo esc_js( $data ) ?>], <?php echo esc_js( number_format( $total_time, 4 ) ) ?>
120 130 );
121 131 });
122 132 </script>
133 +
134 +<!-- Screen-reader only -->
135 +<div class="visually-hidden">
123 136 <?php
137 + $sr_data = explode(',', $data );
138 + echo "<table>\n".
139 + "\t<tr>\n".
140 + "\t\t<td>". esc_html__('Component name', 'code-profiler') ."</td>".
141 + "<td>". esc_html__('Time in seconds', 'code-profiler') ."</td>".
142 + "<td>". esc_html__('Time in percentage', 'code-profiler') ."</td>\n";
143 + for( $i = 0; $i <= $count; $i++ ) {
144 + if ( empty( $sr_data[ $i ] ) ) {
145 + $sr_data[ $i ] = 0;
146 + }
147 + echo "\t<tr>\n\t\t<td>". esc_html( $label[ $i ] ) ."</td>".
148 + "<td>". esc_html( number_format( $sr_data[ $i ], 3 ) ) ."</td>".
149 + "<td>". esc_html( number_format( ( $sr_data[ $i ] / $total_time ) * 100 ) ) .
150 + "%</td>\n\t</tr>\n";
151 + }
152 + echo "</table>\n";
153 +?>
154 +</div>
155 +<!-- End of Screen-reader only -->
156 +
157 +<?php
124 158 // Actions below stats
125 159 $save_png = 1;
126 160 $rotate_img = 1;
127 161 $type = 'slugs';
128 162
129 -// =====================================================================
163 +// ===================================================================== 2023-11-17
130 164 // Warn if multiple plugins are using composer
131 165
132 166 function code_profiler_composer_warning( $profile_path, $display_name ) {
133 167
@@ -143,9 +177,9 @@
143 177 $list = '';
144 178 $first = '';
145 179 $count = 1;
146 180 foreach( $res as $slug => $name ) {
147 - if ( $display_name == 'full' ) {
181 + if ( $display_name == 'full') {
148 182 $list .= "$count: <strong>". esc_html( $name ) .'</strong>, ';
149 183 if ( empty( $first ) ) {
150 184 $first = '<strong>'. esc_html( $name ) .'</strong>';
151 185 }
@@ -156,18 +190,26 @@
156 190 }
157 191 }
158 192 $count++;
159 193 }
160 - $list = rtrim( $list, ', ' ) .'.';
194 + $list = rtrim( $list, ', ') .'.';
161 195
162 - $msg = esc_html__('Code Profiler has detected that the following components, sorted by execution order, are using Composer dependency manager:', 'code-profiler') . "<br />$list<br />".
163 - sprintf(
164 - esc_html__('As that may increase the execution time of %s, make sure to consult the following FAQ: %s%s%s', 'code-profiler'),
165 - $first,
166 - '<a href="?page=code-profiler&cptab=faq#composerwarning" target="_blank" rel="noopener noreferrer">',
167 - esc_html__('Why does Code Profiler warn me that I have multiple plugins using Composer?', 'code-profiler' ),
168 - '</a>'
169 - );
196 + $msg = esc_html__('Code Profiler has detected that the following components, sorted by execution'.
197 + ' order, are using Composer dependency manager:', 'code-profiler') . "<br />$list<br />".
198 + sprintf(
199 + esc_html__(
200 + 'As that may increase the execution time of %s, make sure to consult the following FAQ: '.
201 + '%s%s%s', 'code-profiler'
202 + ),
203 + $first,
204 + '<a href="?page=code-profiler&cptab=faq#composerwarning" target="_blank" rel="noopener '.
205 + 'noreferrer">',
206 + esc_html__(
207 + 'Why does Code Profiler warn me that I have multiple plugins using Composer?',
208 + 'code-profiler'
209 + ),
210 + '</a>'
211 + );
170 212
171 213 return '<div class="cp-notice cp-notice-orange"><p>'. $msg .'</p></div>';
172 214
173 215 }