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.5 1.3.8.6 1.3.8.7 1.3.8.8 1.3.8.9 1.3.9.0 1.3.9.1 1.3.9.2 1.3.9.3 1.3.9.4 1.3.9.5 1.3.9.6 1.3.9.7 1.3.9.8 1.3.9.9 1.4 1.4.0.1 1.4.0.2 1.4.0.3 1.4.0.4
wp-asset-clean-up / classes / Debug.php
wp-asset-clean-up / classes Last commit date
Admin 1 month ago OptimiseAssets 1 month ago ThirdParty 1 year ago AdminBar.php 1 year ago AssetsManager.php 1 month ago BulkChanges.php 1 year ago CleanUp.php 1 month ago Debug.php 1 month ago FileSystem.php 1 year ago HardcodedAssets.php 1 month ago Lite.php 3 years ago Main.php 1 month ago MainFront.php 1 month ago Maintenance.php 1 month ago Menu.php 1 month ago MetaBoxes.php 1 month ago Misc.php 1 month ago ObjectCache.php 1 month ago OwnAssets.php 1 month ago PluginNotifications.php 1 year ago PluginTracking.php 1 month ago Preloads.php 1 month ago Settings.php 1 month ago Tips.php 1 year ago Update.php 1 month ago
Debug.php
438 lines
1 <?php
2 namespace WpAssetCleanUp;
3
4 use WpAssetCleanUp\Admin\MiscAdmin;
5 use WpAssetCleanUp\OptimiseAssets\OptimizeCommon;
6
7 /**
8 * Class Debug
9 * @package WpAssetCleanUp
10 */
11 class Debug
12 {
13 /**
14 * Debug constructor.
15 */
16 public function __construct()
17 {
18 if ( isset($_GET['wpacu_debug']) && ! is_admin() ) {
19 add_action('wp_footer', array($this, 'showDebugOptionsFront'), PHP_INT_MAX);
20
21 }
22
23 foreach( array('wp', 'admin_init') as $wpacuActionHook ) {
24 add_action( $wpacuActionHook, static function() {
25 if (isset( $_GET['wpacu_get_cache_dir_size'] ) && Menu::userCanAccessPlugin()) {
26 self::printCacheDirInfo();
27 }
28
29 // For debugging purposes
30 if (isset($_GET['wpacu_get_already_minified']) && Menu::userCanAccessPlugin()) {
31 echo '<pre>'; print_r(OptimizeCommon::getAlreadyMarkedAsMinified()); echo '</pre>';
32 exit();
33 }
34
35 if (isset($_GET['wpacu_remove_already_minified']) && Menu::userCanAccessPlugin()) {
36 echo '<pre>'; OptimizeCommon::removeAlreadyMarkedAsMinified(); echo '</pre>';
37 exit();
38 }
39
40 if (isset($_GET['wpacu_limit_already_minified']) && Menu::userCanAccessPlugin()) {
41 OptimizeCommon::limitAlreadyMarkedAsMinified();
42 echo '<pre>'; print_r(OptimizeCommon::getAlreadyMarkedAsMinified()); echo '</pre>';
43 exit();
44 }
45 } );
46 }
47 }
48
49 /**
50 * @param $wpacuCacheKey
51 *
52 * @return array
53 */
54 public static function getTimingValues($wpacuCacheKey)
55 {
56 $wpacuExecTiming = ObjectCache::wpacu_cache_get( $wpacuCacheKey, 'wpacu_exec_time' ) ?: 0;
57
58 $wpacuExecTimingMs = $wpacuExecTiming;
59
60 $wpacuTimingFormatMs = str_replace('.00', '', number_format($wpacuExecTimingMs, 2));
61 $wpacuTimingFormatS = str_replace(array('.00', ','), '', number_format(($wpacuExecTimingMs / 1000), 3));
62
63 return array('ms' => $wpacuTimingFormatMs, 's' => $wpacuTimingFormatS);
64 }
65
66 /**
67 * @param $timingKey
68 * @param $htmlSource
69 *
70 * @return string|string[]
71 */
72 public static function printTimingFor($timingKey, $htmlSource)
73 {
74 $wpacuCacheKey = 'wpacu_' . $timingKey . '_exec_time';
75 $timingValues = self::getTimingValues( $wpacuCacheKey);
76 $wpacuTimingFormatMs = $timingValues['ms'];
77 $wpacuTimingFormatS = $timingValues['s'];
78
79 return str_replace(
80 array(
81 '{' . $wpacuCacheKey . '}',
82 '{' . $wpacuCacheKey . '_sec}'
83 ),
84
85 array(
86 $wpacuTimingFormatMs . 'ms',
87 $wpacuTimingFormatS . 's',
88 ), // clean it up
89
90 $htmlSource
91 );
92 }
93
94 /**
95 * @param $htmlSource
96 *
97 * @return string|string[]
98 */
99 public static function applyDebugTiming($htmlSource)
100 {
101 $timingKeys = array(
102 'prepare_optimize_files_css',
103 'prepare_optimize_files_js',
104
105 // All HTML alteration via "wp_loaded" action hook
106 'alter_html_source',
107
108 'alter_html_source_for_resource_loading',
109
110 // HTML CleanUp
111 'alter_html_source_cleanup',
112 'alter_html_source_for_remove_html_comments',
113 'alter_html_source_for_remove_meta_generators',
114
115 // CSS
116 'alter_html_source_for_optimize_css',
117 'alter_html_source_unload_ignore_deps_css',
118 'alter_html_source_for_google_fonts_optimization_removal',
119 'alter_html_source_for_inline_css',
120
121 'alter_html_source_original_to_optimized_css',
122 'alter_html_source_for_preload_css',
123
124 'alter_html_source_for_combine_css',
125 'alter_html_source_for_minify_inline_style_tags',
126
127 'alter_html_source_for_local_fonts_display_style_inline',
128
129 'alter_html_source_for_optimize_css_final_cleanups',
130
131 // JS
132 'alter_html_source_for_optimize_js',
133 'alter_html_source_maybe_move_jquery_after_body_tag',
134 'alter_html_source_unload_ignore_deps_js',
135
136 'alter_html_source_original_to_optimized_js',
137 'alter_html_source_for_preload_js',
138
139 'alter_html_source_for_combine_js',
140
141 'alter_html_source_move_inline_jquery_after_src_tag',
142 'alter_html_source_for_optimize_js_final_cleanups',
143
144 'alter_html_source_strip_any_references_for_unloaded_assets',
145
146 'fetch_strip_hardcoded_assets',
147 'fetch_all_hardcoded_assets',
148
149 'output_css_js_manager',
150
151 'style_loader_tag',
152 'script_loader_tag',
153
154 'style_loader_tag_preload_css',
155 'script_loader_tag_preload_js',
156
157 'style_loader_tag_pro_changes',
158 'script_loader_tag_pro_changes',
159
160 'all_timings'
161 );
162
163 foreach ( $timingKeys as $timingKey ) {
164 $htmlSource = self::printTimingFor($timingKey, $htmlSource);
165 }
166
167 return $htmlSource;
168 }
169
170 /**
171 *
172 */
173 public function showDebugOptionsFront()
174 {
175 if (! Menu::userCanAccessPlugin()) {
176 return;
177 }
178
179 $markedCssListForUnload = array_unique(Main::instance()->allUnloadedAssets['styles']);
180 $markedJsListForUnload = array_unique(Main::instance()->allUnloadedAssets['scripts']);
181
182 $allDebugOptions = array(
183 // [For CSS]
184 'wpacu_no_css_unload' => 'Do not apply any CSS unload rules',
185 'wpacu_no_css_minify' => 'Do not minify any CSS',
186 'wpacu_no_css_combine' => 'Do not combine any CSS',
187
188 'wpacu_no_css_preload_basic' => 'Do not preload any CSS (Basic)',
189
190 // [/For CSS]
191
192 // [For JS]
193 'wpacu_no_js_unload' => 'Do not apply any JavaScript unload rules',
194 'wpacu_no_js_minify' => 'Do not minify any JavaScript',
195 'wpacu_no_js_combine' => 'Do not combine any JavaScript',
196
197 'wpacu_no_js_preload_basic' => 'Do not preload any JS (Basic)',
198 // [/For JS]
199
200 // Others
201 'wpacu_no_frontend_show' => 'Do not show the bottom CSS/JS managing list',
202 'wpacu_no_admin_bar' => 'Do not show the admin bar',
203 'wpacu_no_html_changes' => 'Do not alter the HTML DOM (this will also load all assets non-minified and non-combined)',
204 );
205 ?>
206 <style <?php echo Misc::getStyleTypeAttribute(); ?>>
207 <?php echo file_get_contents(WPACU_PLUGIN_DIR.'/assets/wpacu-debug.css'); ?>
208 </style>
209
210 <script <?php echo Misc::getScriptTypeAttribute(); ?>>
211 <?php echo file_get_contents(WPACU_PLUGIN_DIR.'/assets/wpacu-debug.js'); ?>
212 </script>
213
214 <div id="wpacu-debug-options">
215 <table>
216 <tr>
217 <td style="vertical-align: top;">
218 <p>View the page with the following options <strong>disabled</strong> (for debugging purposes):</p>
219 <form method="post">
220 <ul class="wpacu-options">
221 <?php
222 foreach ($allDebugOptions as $debugKey => $debugText) {
223 ?>
224 <li>
225 <label>
226 <input type="checkbox"
227 name="<?php echo esc_attr($debugKey); ?>"
228 <?php if ( isset($_REQUEST[$debugKey]) ) { echo 'checked="checked"'; } ?> /> &nbsp;<?php echo esc_html($debugText); ?>
229 </label>
230 </li>
231 <?php
232 }
233 ?>
234 </ul>
235
236 <div>
237 <input type="submit"
238 value="Preview this page with the changes made above" />
239 </div>
240 <input type="hidden" name="wpacu_debug" value="on" />
241 </form>
242 </td>
243 <td style="vertical-align: top;">
244 <div style="margin: 0 0 10px; padding: 10px 0;">
245 <strong>CSS handles marked for unload:</strong>&nbsp;
246 <?php
247 if (! empty($markedCssListForUnload)) {
248 sort($markedCssListForUnload);
249 $markedCssListForUnloadFiltered = array_map(static function($handle) {
250 return '<span style="color: darkred;">'.esc_html($handle).'</span>';
251 }, $markedCssListForUnload);
252 echo implode(' &nbsp;/&nbsp; ', $markedCssListForUnloadFiltered);
253 } else {
254 echo 'None';
255 }
256 ?>
257 </div>
258
259 <div style="margin: 0 0 10px; padding: 10px 0;">
260 <strong>JS handles marked for unload:</strong>&nbsp;
261 <?php
262 if (! empty($markedJsListForUnload)) {
263 sort($markedJsListForUnload);
264 $markedJsListForUnloadFiltered = array_map(static function($handle) {
265 return '<span style="color: darkred;">'.esc_html($handle).'</span>';
266 }, $markedJsListForUnload);
267
268 echo implode(' &nbsp;/&nbsp; ', $markedJsListForUnloadFiltered);
269 } else {
270 echo 'None';
271 }
272 ?>
273 </div>
274
275 <hr />
276
277 <div style="margin: 0 0 10px; padding: 10px 0;">
278 <ul style="list-style: none; padding-left: 0;">
279 <script>
280 jQuery(document).ready(function($) {
281 let valueNum = 0;
282
283 $('[data-wpacu-count-it]').each(function(index, value) {
284 let extractedNumber = parseFloat($(this).attr("data-wpacu-count-it").replace('ms', ''));
285 console.log(extractedNumber);
286
287 valueNum += extractedNumber;
288 });
289
290 valueNum = valueNum.toFixed(2);
291
292 $('#wpacu-total-all-timings').html(valueNum);
293 });
294 </script>
295 <li style="margin-bottom: 15px; border-bottom: 1px solid #e7e7e7;"><strong>Total timing for all recorded actions:</strong> <span id="wpacu-total-all-timings"></span>ms</li>
296
297 <li style="margin-bottom: 10px;" data-wpacu-count-it="<?php echo self::printTimingFor('filter_dequeue_styles', '{wpacu_filter_dequeue_styles_exec_time}'); ?>">Dequeue any chosen styles (.css): <?php echo self::printTimingFor('filter_dequeue_styles', '{wpacu_filter_dequeue_styles_exec_time} ({wpacu_filter_dequeue_styles_exec_time_sec})'); ?></li>
298 <li style="margin-bottom: 20px;" data-wpacu-count-it="<?php echo self::printTimingFor('filter_dequeue_scripts', '{wpacu_filter_dequeue_scripts_exec_time}'); ?>">Dequeue any chosen scripts (.js): <?php echo self::printTimingFor('filter_dequeue_scripts', '{wpacu_filter_dequeue_scripts_exec_time} ({wpacu_filter_dequeue_scripts_exec_time_sec})'); ?></li>
299
300 <li style="margin-bottom: 10px;" data-wpacu-count-it="{wpacu_prepare_optimize_files_css_exec_time}">Prepare CSS files to optimize: {wpacu_prepare_optimize_files_css_exec_time} ({wpacu_prepare_optimize_files_css_exec_time_sec})</li>
301 <li style="margin-bottom: 20px;" data-wpacu-count-it="{wpacu_prepare_optimize_files_js_exec_time}">Prepare JS files to optimize: {wpacu_prepare_optimize_files_js_exec_time} ({wpacu_prepare_optimize_files_js_exec_time_sec})</li>
302
303 <li style="margin-bottom: 10px;" data-wpacu-count-it="{wpacu_alter_html_source_exec_time}">OptimizeCommon - HTML alteration via <em>wp_loaded</em>: {wpacu_alter_html_source_exec_time} ({wpacu_alter_html_source_exec_time_sec})
304 <ul id="wpacu-debug-timing">
305 <li style="margin-top: 10px; margin-bottom: 10px;">&nbsp;OptimizeCSS: {wpacu_alter_html_source_for_optimize_css_exec_time} ({wpacu_alter_html_source_for_optimize_css_exec_time_sec})
306 <ul>
307 <li>Google Fonts Optimization/Removal: {wpacu_alter_html_source_for_google_fonts_optimization_removal_exec_time}</li>
308 <li>From CSS file to Inline: {wpacu_alter_html_source_for_inline_css_exec_time}</li>
309 <li>Update Original to Optimized: {wpacu_alter_html_source_original_to_optimized_css_exec_time}</li>
310 <li>Preloads: {wpacu_alter_html_source_for_preload_css_exec_time}</li>
311
312 <!-- -->
313
314 <li>Combine: {wpacu_alter_html_source_for_combine_css_exec_time}</li>
315 <li>Minify Inline Tags: {wpacu_alter_html_source_for_minify_inline_style_tags_exec_time}</li>
316 <li>Unload (ignore dependencies): {wpacu_alter_html_source_unload_ignore_deps_css_exec_time}</li>
317 <li>Alter Inline CSS (font-display): {wpacu_alter_html_source_for_local_fonts_display_style_inline_exec_time}</li>
318 <li>Final Cleanups for the HTML source: {wpacu_alter_html_source_for_optimize_css_final_cleanups_exec_time}</li>
319 </ul>
320 </li>
321
322 <li style="margin-top: 10px; margin-bottom: 10px;">OptimizeJs: {wpacu_alter_html_source_for_optimize_js_exec_time} ({wpacu_alter_html_source_for_optimize_js_exec_time_sec})
323 <ul>
324 <li>Update Original to Optimized: {wpacu_alter_html_source_original_to_optimized_js_exec_time}</li>
325 <li>Preloads: {wpacu_alter_html_source_for_preload_js_exec_time}</li>
326 <!-- -->
327
328 <li>Combine: {wpacu_alter_html_source_for_combine_js_exec_time}</li>
329
330 <li>Move jQuery within the BODY tag: {wpacu_alter_html_source_maybe_move_jquery_after_body_tag_exec_time}</li>
331 <li>Unload (ignore dependencies): {wpacu_alter_html_source_unload_ignore_deps_js_exec_time}</li>
332 <li>Move any inline with jQuery code after jQuery library: {wpacu_alter_html_source_move_inline_jquery_after_src_tag_exec_time}</li>
333 <li>Final Cleanups for the HTML source: {wpacu_alter_html_source_for_optimize_js_final_cleanups_exec_time}</li>
334 </ul>
335 </li>
336
337 <li>Strip any references for unloaded assets: {wpacu_alter_html_source_strip_any_references_for_unloaded_assets_exec_time}</li>
338
339 <li>Apply any Resource Loading rules: {wpacu_alter_html_source_for_resource_loading_exec_time}</li>
340
341 <li>HTML CleanUp: {wpacu_alter_html_source_cleanup_exec_time}
342 <ul>
343 <li>Strip HTML Comments: {wpacu_alter_html_source_for_remove_html_comments_exec_time}</li>
344 <li>Remove Generator META tags: {wpacu_alter_html_source_for_remove_meta_generators_exec_time}</li>
345 </ul>
346 </li>
347 </ul>
348 </li>
349
350 <li style="margin-bottom: 10px;" data-wpacu-count-it="{wpacu_output_css_js_manager_exec_time}">Output CSS &amp; JS Management List: {wpacu_output_css_js_manager_exec_time} ({wpacu_output_css_js_manager_exec_time_sec})</li>
351
352 <li style="margin-bottom: 10px;" data-wpacu-count-it="{wpacu_style_loader_tag_exec_time}">"style_loader_tag" filters: {wpacu_style_loader_tag_exec_time} ({wpacu_style_loader_tag_exec_time_sec})</li>
353 <li style="margin-bottom: 10px;" data-wpacu-count-it="{wpacu_script_loader_tag_exec_time}">"script_loader_tag" filters: {wpacu_script_loader_tag_exec_time} ({wpacu_script_loader_tag_exec_time_sec})</li>
354
355 <li style="margin-bottom: 10px;" data-wpacu-count-it="{wpacu_style_loader_tag_preload_css_exec_time}">"style_loader_tag" filters (Preload CSS): {wpacu_style_loader_tag_preload_css_exec_time} ({wpacu_style_loader_tag_preload_css_exec_time_sec})</li>
356 <li style="margin-bottom: 10px;" data-wpacu-count-it="{wpacu_script_loader_tag_preload_js_exec_time}">"script_loader_tag" filters (Preload JS): {wpacu_script_loader_tag_preload_js_exec_time} ({wpacu_script_loader_tag_preload_js_exec_time_sec})</li>
357 </ul>
358 </div>
359 </td>
360 </tr>
361 </table>
362 </div>
363 <?php
364 }
365
366 /**
367 *
368 */
369 public static function printCacheDirInfo()
370 {
371 $assetCleanUpCacheDirRel = OptimizeCommon::getRelPathPluginCacheDir();
372 $assetCleanUpCacheDir = WP_CONTENT_DIR . $assetCleanUpCacheDirRel;
373
374 echo '<h3>'.WPACU_PLUGIN_TITLE.': Caching Directory Stats</h3>';
375
376 if (is_dir($assetCleanUpCacheDir)) {
377 $printCacheDirOutput = '<em>'.str_replace($assetCleanUpCacheDirRel, '<strong>'.$assetCleanUpCacheDirRel.'</strong>', $assetCleanUpCacheDir).'</em>';
378
379 if (! is_writable($assetCleanUpCacheDir)) {
380 echo '<span style="color: red;">'.
381 'The '.wp_kses($printCacheDirOutput, array('em' => array(), 'strong' => array())).' directory is <em>not writable</em>.</span>'.
382 '<br /><br />';
383 } else {
384 echo '<span style="color: green;">The '.wp_kses($printCacheDirOutput, array('em' => array(), 'strong' => array())).' directory is <em>writable</em>.</span>' . '<br /><br />';
385 }
386
387 $dirItems = new \RecursiveDirectoryIterator( $assetCleanUpCacheDir, \RecursiveDirectoryIterator::SKIP_DOTS );
388
389 $totalFiles = 0;
390 $totalSize = 0;
391
392 foreach (
393 new \RecursiveIteratorIterator( $dirItems, \RecursiveIteratorIterator::SELF_FIRST,
394 \RecursiveIteratorIterator::CATCH_GET_CHILD ) as $item
395 ) {
396 $appendAfter = '';
397
398 if ($item->isDir()) {
399 echo '<br />';
400
401 $appendAfter = ' - ';
402
403 if (is_writable($item)) {
404 $appendAfter .= ' <em><strong>writable</strong> directory</em>';
405 } else {
406 $appendAfter .= ' <em><strong style="color: red;">not writable</strong> directory</em>';
407 }
408 } elseif ($item->isFile()) {
409 $appendAfter = '(<em>'.MiscAdmin::formatBytes($item->getSize()).'</em>)';
410
411 echo '&nbsp;-&nbsp;';
412 }
413
414 echo wp_kses($item.' '.$appendAfter, array(
415 'em' => array(),
416 'strong' => array('style' => array()),
417 'br' => array(),
418 'span' => array('style' => array())
419 ))
420
421 .'<br />';
422
423 if ( $item->isFile() ) {
424 $totalSize += $item->getSize();
425 $totalFiles ++;
426 }
427 }
428
429 echo '<br />'.'Total Files: <strong>'.$totalFiles.'</strong> / Total Size: <strong>'.MiscAdmin::formatBytes($totalSize).'</strong>';
430 } else {
431 echo 'The directory does not exists.';
432 }
433
434 exit();
435 }
436
437 }
438