| @@ -10,20 +10,20 @@ | ||
| 10 | 10 | | (c) Jerome Bruandet ~ https://code-profiler.com/ | |
| 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 Plugins & Theme stats. |
| 18 | 18 | |
| 19 | -$buffer = code_profiler_get_profile_data( $profile_path, 'slugs' ); | |
| 19 | +$buffer = code_profiler_get_profile_data( $profile_path, 'slugs'); | |
| 20 | 20 | if ( isset( $buffer['error'] ) ) { |
| 21 | 21 | return; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | // Fetch options |
| 25 | -$cp_options = get_option( 'code-profiler' ); | |
| 25 | +$cp_options = get_option('code-profiler'); | |
| 26 | 26 | |
| 27 | 27 | // Name vs slug |
| 28 | 28 | if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) { |
| 29 | 29 | $cp_options['display_name'] = 'full'; |
| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) { |
| 29 | 29 | $cp_options['display_name'] = 'full'; |
| 30 | 30 | } |
| 31 | 31 | // Truncate name |
| 32 | -if ( empty( $cp_options['truncate_name'] ) || ! preg_match( '/^\d+$/', ( $cp_options['truncate_name'] ) ) ) { | |
| 32 | +if ( empty( $cp_options['truncate_name'] ) || ! preg_match('/^\d+$/', ( $cp_options['truncate_name'] ) ) ) { | |
| 33 | 33 | $cp_options['truncate_name'] = 30; |
| 34 | 34 | } |
| 35 | 35 | // Horizontal vs vertical chart |
| 36 | 36 | if ( empty( $cp_options['chart_type'] ) || ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) { |
| @@ -38,9 +38,9 @@ | ||
| 38 | 38 | } else { |
| 39 | 39 | $axis = $cp_options['chart_type']; |
| 40 | 40 | } |
| 41 | 41 | // Max plugins to display |
| 42 | -if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match( '/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) { | |
| 42 | +if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match('/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) { | |
| 43 | 43 | $chart_max_plugins = 25; |
| 44 | 44 | } else { |
| 45 | 45 | $chart_max_plugins = $cp_options['chart_max_plugins']; |
| 46 | 46 | } |
| @@ -75,9 +75,9 @@ | ||
| 75 | 75 | continue; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Check whether we should use the name or the slug |
| 79 | - if ( $cp_options['display_name'] == 'slug' ) { | |
| 79 | + if ( $cp_options['display_name'] == 'slug') { | |
| 80 | 80 | $n = $slugs[0]; |
| 81 | 81 | } else { |
| 82 | 82 | $n = $slugs[2]; |
| 83 | 83 | } |
| @@ -87,12 +87,12 @@ | ||
| 87 | 87 | $n = mb_substr( $n, 0, $cp_options['truncate_name'] , 'utf-8') .'...'; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Mark theme as such |
| 91 | - if ( $slugs[3] == 'theme' ) { | |
| 91 | + if ( $slugs[3] == 'theme') { | |
| 92 | 92 | $label[] = "{$n} ($theme)"; |
| 93 | 93 | // ...and MU plugins |
| 94 | - } elseif ( $slugs[3] == 'mu-plugin' ) { | |
| 94 | + } elseif ( $slugs[3] == 'mu-plugin') { | |
| 95 | 95 | $label[] = "{$n} (MU)"; |
| 96 | 96 | } else { |
| 97 | 97 | $label[] = $n; |
| 98 | 98 | } |
| @@ -99,12 +99,12 @@ | ||
| 99 | 99 | |
| 100 | 100 | $data .= "{$slugs[1]},"; |
| 101 | 101 | $total_time += $slugs[1]; |
| 102 | 102 | } |
| 103 | -$data = rtrim( $data, ',' ); | |
| 103 | +$data = rtrim( $data, ','); | |
| 104 | 104 | $count = count( $label ) - 1; |
| 105 | 105 | ?> |
| 106 | -<div style="width:80vw;margin:auto"> | |
| 106 | +<div style="width:80vw;margin:auto" aria-hidden="true"> | |
| 107 | 107 | <canvas id="myChart"></canvas> |
| 108 | 108 | </div> |
| 109 | 109 | <script> |
| 110 | 110 | jQuery(document).ready(function() { |
| @@ -119,9 +119,32 @@ | ||
| 119 | 119 | [<?php echo esc_js( $data ) ?>], <?php echo esc_js( number_format( $total_time, 4 ) ) ?> |
| 120 | 120 | ); |
| 121 | 121 | }); |
| 122 | 122 | </script> |
| 123 | + | |
| 124 | +<!-- Screen-reader only --> | |
| 125 | +<div class="visually-hidden"> | |
| 123 | 126 | <?php |
| 127 | + $sr_data = explode(',', $data ); | |
| 128 | + echo "<table>\n". | |
| 129 | + "\t<tr>\n". | |
| 130 | + "\t\t<td>". esc_html__('Component name', 'code-profiler') ."</td>". | |
| 131 | + "<td>". esc_html__('Time in seconds', 'code-profiler') ."</td>". | |
| 132 | + "<td>". esc_html__('Time in percentage', 'code-profiler') ."</td>\n"; | |
| 133 | + for( $i = 0; $i <= $count; $i++ ) { | |
| 134 | + if ( empty( $sr_data[ $i ] ) ) { | |
| 135 | + $sr_data[ $i ] = 0; | |
| 136 | + } | |
| 137 | + echo "\t<tr>\n\t\t<td>". esc_html( $label[ $i ] ) ."</td>". | |
| 138 | + "<td>". esc_html( number_format( $sr_data[ $i ], 3 ) ) ."</td>". | |
| 139 | + "<td>". esc_html( number_format( ( $sr_data[ $i ] / $total_time ) * 100 ) ) ."%</td>\n\t</tr>\n"; | |
| 140 | + } | |
| 141 | + echo "</table>\n"; | |
| 142 | +?> | |
| 143 | +</div> | |
| 144 | +<!-- End of Screen-reader only --> | |
| 145 | + | |
| 146 | +<?php | |
| 124 | 147 | // Actions below stats |
| 125 | 148 | $save_png = 1; |
| 126 | 149 | $rotate_img = 1; |
| 127 | 150 | $type = 'slugs'; |
| @@ -143,9 +166,9 @@ | ||
| 143 | 166 | $list = ''; |
| 144 | 167 | $first = ''; |
| 145 | 168 | $count = 1; |
| 146 | 169 | foreach( $res as $slug => $name ) { |
| 147 | - if ( $display_name == 'full' ) { | |
| 170 | + if ( $display_name == 'full') { | |
| 148 | 171 | $list .= "$count: <strong>". esc_html( $name ) .'</strong>, '; |
| 149 | 172 | if ( empty( $first ) ) { |
| 150 | 173 | $first = '<strong>'. esc_html( $name ) .'</strong>'; |
| 151 | 174 | } |
| @@ -156,9 +179,9 @@ | ||
| 156 | 179 | } |
| 157 | 180 | } |
| 158 | 181 | $count++; |
| 159 | 182 | } |
| 160 | - $list = rtrim( $list, ', ' ) .'.'; | |
| 183 | + $list = rtrim( $list, ', ') .'.'; | |
| 161 | 184 | |
| 162 | 185 | $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 | 186 | sprintf( |
| 164 | 187 | esc_html__('As that may increase the execution time of %s, make sure to consult the following FAQ: %s%s%s', 'code-profiler'), |
| @@ -163,9 +186,9 @@ | ||
| 163 | 186 | sprintf( |
| 164 | 187 | esc_html__('As that may increase the execution time of %s, make sure to consult the following FAQ: %s%s%s', 'code-profiler'), |
| 165 | 188 | $first, |
| 166 | 189 | '<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' ), | |
| 190 | + esc_html__('Why does Code Profiler warn me that I have multiple plugins using Composer?', 'code-profiler'), | |
| 168 | 191 | '</a>' |
| 169 | 192 | ); |
| 170 | 193 | |
| 171 | 194 | return '<div class="cp-notice cp-notice-orange"><p>'. $msg .'</p></div>'; |