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.4 1.3.8.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 year ago OptimiseAssets 1 year ago ThirdParty 1 year ago AdminBar.php 1 year ago AssetsManager.php 1 year ago BulkChanges.php 1 year ago CleanUp.php 1 year ago Debug.php 1 year ago FileSystem.php 1 year ago HardcodedAssets.php 1 year ago Lite.php 1 year ago Main.php 1 year ago MainFront.php 1 year ago Maintenance.php 1 year ago Menu.php 1 year ago MetaBoxes.php 1 year ago Misc.php 1 year ago ObjectCache.php 1 year ago OwnAssets.php 1 year ago PluginNotifications.php 1 year ago PluginTracking.php 1 year ago Preloads.php 1 year ago Settings.php 1 year ago Tips.php 1 year ago Update.php 1 year ago
Debug.php
434 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::userCanAccessAssetCleanUp()) {
26 self::printCacheDirInfo();
27 }
28
29 // For debugging purposes
30 if (isset($_GET['wpacu_get_already_minified']) && Menu::userCanAccessAssetCleanUp()) {
31 echo '<pre>'; print_r(OptimizeCommon::getAlreadyMarkedAsMinified()); echo '</pre>';
32 exit();
33 }
34
35 if (isset($_GET['wpacu_remove_already_minified']) && Menu::userCanAccessAssetCleanUp()) {
36 echo '<pre>'; OptimizeCommon::removeAlreadyMarkedAsMinified(); echo '</pre>';
37 exit();
38 }
39
40 if (isset($_GET['wpacu_limit_already_minified']) && Menu::userCanAccessAssetCleanUp()) {
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 // HTML CleanUp
109 'alter_html_source_cleanup',
110 'alter_html_source_for_remove_html_comments',
111 'alter_html_source_for_remove_meta_generators',
112
113 // CSS
114 'alter_html_source_for_optimize_css',
115 'alter_html_source_unload_ignore_deps_css',
116 'alter_html_source_for_google_fonts_optimization_removal',
117 'alter_html_source_for_inline_css',
118
119 'alter_html_source_original_to_optimized_css',
120 'alter_html_source_for_preload_css',
121
122 'alter_html_source_for_combine_css',
123 'alter_html_source_for_minify_inline_style_tags',
124
125 'alter_html_source_for_local_fonts_display_style_inline',
126
127 'alter_html_source_for_optimize_css_final_cleanups',
128
129 // JS
130 'alter_html_source_for_optimize_js',
131 'alter_html_source_maybe_move_jquery_after_body_tag',
132 'alter_html_source_unload_ignore_deps_js',
133
134 'alter_html_source_original_to_optimized_js',
135 'alter_html_source_for_preload_js',
136
137 'alter_html_source_for_combine_js',
138
139 'alter_html_source_move_inline_jquery_after_src_tag',
140 'alter_html_source_for_optimize_js_final_cleanups',
141
142 'alter_html_source_strip_any_references_for_unloaded_assets',
143
144 'fetch_strip_hardcoded_assets',
145 'fetch_all_hardcoded_assets',
146
147 'output_css_js_manager',
148
149 'style_loader_tag',
150 'script_loader_tag',
151
152 'style_loader_tag_preload_css',
153 'script_loader_tag_preload_js',
154
155 'style_loader_tag_pro_changes',
156 'script_loader_tag_pro_changes',
157
158 'all_timings'
159 );
160
161 foreach ( $timingKeys as $timingKey ) {
162 $htmlSource = self::printTimingFor($timingKey, $htmlSource);
163 }
164
165 return $htmlSource;
166 }
167
168 /**
169 *
170 */
171 public function showDebugOptionsFront()
172 {
173 if (! Menu::userCanAccessAssetCleanUp()) {
174 return;
175 }
176
177 $markedCssListForUnload = array_unique(Main::instance()->allUnloadedAssets['styles']);
178 $markedJsListForUnload = array_unique(Main::instance()->allUnloadedAssets['scripts']);
179
180 $allDebugOptions = array(
181 // [For CSS]
182 'wpacu_no_css_unload' => 'Do not apply any CSS unload rules',
183 'wpacu_no_css_minify' => 'Do not minify any CSS',
184 'wpacu_no_css_combine' => 'Do not combine any CSS',
185
186 'wpacu_no_css_preload_basic' => 'Do not preload any CSS (Basic)',
187
188 // [/For CSS]
189
190 // [For JS]
191 'wpacu_no_js_unload' => 'Do not apply any JavaScript unload rules',
192 'wpacu_no_js_minify' => 'Do not minify any JavaScript',
193 'wpacu_no_js_combine' => 'Do not combine any JavaScript',
194
195 'wpacu_no_js_preload_basic' => 'Do not preload any JS (Basic)',
196 // [/For JS]
197
198 // Others
199 'wpacu_no_frontend_show' => 'Do not show the bottom CSS/JS managing list',
200 'wpacu_no_admin_bar' => 'Do not show the admin bar',
201 'wpacu_no_html_changes' => 'Do not alter the HTML DOM (this will also load all assets non-minified and non-combined)',
202 );
203 ?>
204 <style <?php echo Misc::getStyleTypeAttribute(); ?>>
205 <?php echo file_get_contents(WPACU_PLUGIN_DIR.'/assets/wpacu-debug.css'); ?>
206 </style>
207
208 <script <?php echo Misc::getScriptTypeAttribute(); ?>>
209 <?php echo file_get_contents(WPACU_PLUGIN_DIR.'/assets/wpacu-debug.js'); ?>
210 </script>
211
212 <div id="wpacu-debug-options">
213 <table>
214 <tr>
215 <td style="vertical-align: top;">
216 <p>View the page with the following options <strong>disabled</strong> (for debugging purposes):</p>
217 <form method="post">
218 <ul class="wpacu-options">
219 <?php
220 foreach ($allDebugOptions as $debugKey => $debugText) {
221 ?>
222 <li>
223 <label>
224 <input type="checkbox"
225 name="<?php echo esc_attr($debugKey); ?>"
226 <?php if ( isset($_REQUEST[$debugKey]) ) { echo 'checked="checked"'; } ?> /> &nbsp;<?php echo esc_html($debugText); ?>
227 </label>
228 </li>
229 <?php
230 }
231 ?>
232 </ul>
233
234 <div>
235 <input type="submit"
236 value="Preview this page with the changes made above" />
237 </div>
238 <input type="hidden" name="wpacu_debug" value="on" />
239 </form>
240 </td>
241 <td style="vertical-align: top;">
242 <div style="margin: 0 0 10px; padding: 10px 0;">
243 <strong>CSS handles marked for unload:</strong>&nbsp;
244 <?php
245 if (! empty($markedCssListForUnload)) {
246 sort($markedCssListForUnload);
247 $markedCssListForUnloadFiltered = array_map(static function($handle) {
248 return '<span style="color: darkred;">'.esc_html($handle).'</span>';
249 }, $markedCssListForUnload);
250 echo implode(' &nbsp;/&nbsp; ', $markedCssListForUnloadFiltered);
251 } else {
252 echo 'None';
253 }
254 ?>
255 </div>
256
257 <div style="margin: 0 0 10px; padding: 10px 0;">
258 <strong>JS handles marked for unload:</strong>&nbsp;
259 <?php
260 if (! empty($markedJsListForUnload)) {
261 sort($markedJsListForUnload);
262 $markedJsListForUnloadFiltered = array_map(static function($handle) {
263 return '<span style="color: darkred;">'.esc_html($handle).'</span>';
264 }, $markedJsListForUnload);
265
266 echo implode(' &nbsp;/&nbsp; ', $markedJsListForUnloadFiltered);
267 } else {
268 echo 'None';
269 }
270 ?>
271 </div>
272
273 <hr />
274
275 <div style="margin: 0 0 10px; padding: 10px 0;">
276 <ul style="list-style: none; padding-left: 0;">
277 <script>
278 jQuery(document).ready(function($) {
279 let valueNum = 0;
280
281 $('[data-wpacu-count-it]').each(function(index, value) {
282 let extractedNumber = parseFloat($(this).attr("data-wpacu-count-it").replace('ms', ''));
283 console.log(extractedNumber);
284
285 valueNum += extractedNumber;
286 });
287
288 valueNum = valueNum.toFixed(2);
289
290 $('#wpacu-total-all-timings').html(valueNum);
291 });
292 </script>
293 <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>
294
295 <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>
296 <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>
297
298 <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>
299 <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>
300
301 <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})
302 <ul id="wpacu-debug-timing">
303 <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})
304 <ul>
305 <li>Google Fonts Optimization/Removal: {wpacu_alter_html_source_for_google_fonts_optimization_removal_exec_time}</li>
306 <li>From CSS file to Inline: {wpacu_alter_html_source_for_inline_css_exec_time}</li>
307 <li>Update Original to Optimized: {wpacu_alter_html_source_original_to_optimized_css_exec_time}</li>
308 <li>Preloads: {wpacu_alter_html_source_for_preload_css_exec_time}</li>
309
310 <!-- -->
311
312 <li>Combine: {wpacu_alter_html_source_for_combine_css_exec_time}</li>
313 <li>Minify Inline Tags: {wpacu_alter_html_source_for_minify_inline_style_tags_exec_time}</li>
314 <li>Unload (ignore dependencies): {wpacu_alter_html_source_unload_ignore_deps_css_exec_time}</li>
315 <li>Alter Inline CSS (font-display): {wpacu_alter_html_source_for_local_fonts_display_style_inline_exec_time}</li>
316 <li>Final Cleanups for the HTML source: {wpacu_alter_html_source_for_optimize_css_final_cleanups_exec_time}</li>
317 </ul>
318 </li>
319
320 <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})
321 <ul>
322 <li>Update Original to Optimized: {wpacu_alter_html_source_original_to_optimized_js_exec_time}</li>
323 <li>Preloads: {wpacu_alter_html_source_for_preload_js_exec_time}</li>
324 <!-- -->
325
326 <li>Combine: {wpacu_alter_html_source_for_combine_js_exec_time}</li>
327
328 <li>Move jQuery within the BODY tag: {wpacu_alter_html_source_maybe_move_jquery_after_body_tag_exec_time}</li>
329 <li>Unload (ignore dependencies): {wpacu_alter_html_source_unload_ignore_deps_js_exec_time}</li>
330 <li>Move any inline with jQuery code after jQuery library: {wpacu_alter_html_source_move_inline_jquery_after_src_tag_exec_time}</li>
331 <li>Final Cleanups for the HTML source: {wpacu_alter_html_source_for_optimize_js_final_cleanups_exec_time}</li>
332 </ul>
333 </li>
334
335 <li>Strip any references for unloaded assets: {wpacu_alter_html_source_strip_any_references_for_unloaded_assets_exec_time}</li>
336
337 <li>HTML CleanUp: {wpacu_alter_html_source_cleanup_exec_time}
338 <ul>
339 <li>Strip HTML Comments: {wpacu_alter_html_source_for_remove_html_comments_exec_time}</li>
340 <li>Remove Generator META tags: {wpacu_alter_html_source_for_remove_meta_generators_exec_time}</li>
341 </ul>
342 </li>
343 </ul>
344 </li>
345
346 <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>
347
348 <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>
349 <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>
350
351 <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>
352 <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>
353 </ul>
354 </div>
355 </td>
356 </tr>
357 </table>
358 </div>
359 <?php
360 }
361
362 /**
363 *
364 */
365 public static function printCacheDirInfo()
366 {
367 $assetCleanUpCacheDirRel = OptimizeCommon::getRelPathPluginCacheDir();
368 $assetCleanUpCacheDir = WP_CONTENT_DIR . $assetCleanUpCacheDirRel;
369
370 echo '<h3>'.WPACU_PLUGIN_TITLE.': Caching Directory Stats</h3>';
371
372 if (is_dir($assetCleanUpCacheDir)) {
373 $printCacheDirOutput = '<em>'.str_replace($assetCleanUpCacheDirRel, '<strong>'.$assetCleanUpCacheDirRel.'</strong>', $assetCleanUpCacheDir).'</em>';
374
375 if (! is_writable($assetCleanUpCacheDir)) {
376 echo '<span style="color: red;">'.
377 'The '.wp_kses($printCacheDirOutput, array('em' => array(), 'strong' => array())).' directory is <em>not writable</em>.</span>'.
378 '<br /><br />';
379 } else {
380 echo '<span style="color: green;">The '.wp_kses($printCacheDirOutput, array('em' => array(), 'strong' => array())).' directory is <em>writable</em>.</span>' . '<br /><br />';
381 }
382
383 $dirItems = new \RecursiveDirectoryIterator( $assetCleanUpCacheDir, \RecursiveDirectoryIterator::SKIP_DOTS );
384
385 $totalFiles = 0;
386 $totalSize = 0;
387
388 foreach (
389 new \RecursiveIteratorIterator( $dirItems, \RecursiveIteratorIterator::SELF_FIRST,
390 \RecursiveIteratorIterator::CATCH_GET_CHILD ) as $item
391 ) {
392 $appendAfter = '';
393
394 if ($item->isDir()) {
395 echo '<br />';
396
397 $appendAfter = ' - ';
398
399 if (is_writable($item)) {
400 $appendAfter .= ' <em><strong>writable</strong> directory</em>';
401 } else {
402 $appendAfter .= ' <em><strong style="color: red;">not writable</strong> directory</em>';
403 }
404 } elseif ($item->isFile()) {
405 $appendAfter = '(<em>'.MiscAdmin::formatBytes($item->getSize()).'</em>)';
406
407 echo '&nbsp;-&nbsp;';
408 }
409
410 echo wp_kses($item.' '.$appendAfter, array(
411 'em' => array(),
412 'strong' => array('style' => array()),
413 'br' => array(),
414 'span' => array('style' => array())
415 ))
416
417 .'<br />';
418
419 if ( $item->isFile() ) {
420 $totalSize += $item->getSize();
421 $totalFiles ++;
422 }
423 }
424
425 echo '<br />'.'Total Files: <strong>'.$totalFiles.'</strong> / Total Size: <strong>'.MiscAdmin::formatBytes($totalSize).'</strong>';
426 } else {
427 echo 'The directory does not exists.';
428 }
429
430 exit();
431 }
432
433 }
434