-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-clean-slate.php
107 lines (90 loc) · 2.7 KB
/
wp-clean-slate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Plugin Name: Clean Slate
* Plugin URI: https://github.com/ideasonpurpose/wp-clean-slate-plugin
* Description: An experimental plugin for removing ALL WordPress styles from the front end
* Version: 0.0.1
* Author: Ideas On Purpose
* Author URI: https://www.ideasonpurpose.com
* License: MIT
* Requires at least: 6
* Requires PHP: 8
*
*/
namespace IdeasOnPurpose;
defined('ABSPATH') or die();
require __DIR__ . '/vendor/autoload.php';
class CleanSlate
{
public function __construct()
{
add_filter('print_styles_array', [$this, 'remove_styles']);
// add_filter('style_loader_tag', [$this, 'dump_tag'], 10, 4);
// add_action('wp_print_scripts', [$this, 'scrub_styles']);
}
public function remove_styles($styles)
{
if (is_admin()) {
return $styles;
}
/**
* Style handles to preserve
* TODO: Provide an interface for adding to this?
*/
$keepStyles = ['admin-bar', 'dashicons'];
/**
* Styles to remove
* All style handles starting with 'wp-block' will also be removed
* Removal can be overridden by adding a handle to $keepStyles
*/
$dumpStyles = [
'classic-theme-styles',
'core-block-supports',
'global-styles',
'wp-webfonts',
];
$newStyles = [];
foreach ($styles as $handle) {
/**
* Default to keeping everything in $keepFiles first
*/
if (in_array($handle, $keepStyles)) {
$newStyles[] = $handle;
continue;
}
/**
* Skip anything listed in $dumpStyles
*/
if (in_array($handle, $dumpStyles)) {
continue;
}
/**
* Remove all wp-block* styles
*/
if (strpos($handle, 'wp-block') === 0) {
continue;
}
/**
* Add whatever's left
*/
$newStyles[] = $handle;
}
// DEBUG SNIPPET START
if (class_exists('Kint')) {
\Kint::$mode_default = \Kint::MODE_CLI;
}
if (class_exists('Sage')) {
\Sage::enabled(\Sage::MODE_CLI);
}
error_log(@d($styles, $newStyles, strpos($handle, 'wp-block')));
if (class_exists('Kint')) {
\Kint::$mode_default = \Kint::MODE_RICH;
}
if (class_exists('Sage')) {
\Sage::enabled(\Sage::MODE_RICH);
}
// DEBUG SNIPPET END
return $newStyles;
}
}
new CleanSlate();