Divi.php
5.02 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
namespace WP_Rocket\ThirdParty\Themes;
use WP_Rocket\Admin\{Options, Options_Data};
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
class Divi extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'divi';
/**
* Options API instance.
*
* @var Options
*/
private $options_api;
/**
* WP Rocket options instance.
*
* @var Options_Data
*/
private $options;
/**
* Delay JS HTML class.
*
* @var HTML
*/
private $delayjs_html;
/**
* Instantiate the class
*
* @param Options $options_api Options API instance.
* @param Options_Data $options WP Rocket options instance.
* @param HTML $delayjs_html DelayJS HTML class.
*/
public function __construct( Options $options_api, Options_Data $options, HTML $delayjs_html ) {
$this->options_api = $options_api;
$this->options = $options;
$this->delayjs_html = $delayjs_html;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
$events = [
'switch_theme' => [ 'maybe_disable_youtube_preview', PHP_INT_MAX, 2 ],
'rocket_specify_dimension_images' => 'disable_image_dimensions_height_percentage',
];
if ( ! self::is_current_theme() ) {
return $events;
}
$events['rocket_exclude_js'] = 'exclude_js';
$events['rocket_maybe_disable_youtube_lazyload_helper'] = 'add_divi_to_description';
$events['wp_enqueue_scripts'] = 'disable_divi_jquery_body';
$events['rocket_exclude_css'] = 'exclude_css_from_combine';
$events['wp'] = 'disable_dynamic_css_on_rucss';
$events['after_setup_theme'] = 'remove_assets_generated';
return $events;
}
/**
* Excludes Divi's Salvatorre script from JS minification
*
* Prevent an error after minification/concatenation
*
* @since 3.6.3
*
* @param array $excluded_js An array of JS paths to be excluded.
*
* @return array the updated array of paths
*/
public function exclude_js( $excluded_js ) {
if ( ! rocket_get_constant( 'ET_BUILDER_URI' ) ) {
return $excluded_js;
}
$excluded_js[] = str_replace( home_url(), '', rocket_get_constant( 'ET_BUILDER_URI' ) . '/scripts/salvattore.min.js' );
return $excluded_js;
}
/**
* Disables the Replace Youtube iframe by preview thumbnail option if new theme (or parent) is Divi
*
* @since 3.6.3
*
* @param string $name Name of the new theme.
* @param WP_Theme $theme instance of the new theme.
*
* @return void
*/
public function maybe_disable_youtube_preview( $name, $theme ) {
if ( ! self::is_current_theme( $theme ) ) {
return;
}
$this->options->set( 'lazyload_youtube', 0 );
$this->options_api->set( 'settings', $this->options->get_options() );
}
/**
* Adds Divi to the array of items disabling Youtube lazyload
*
* @since 3.6.3
*
* @param array $disable_youtube_lazyload Array of items names.
*
* @return array
*/
public function add_divi_to_description( $disable_youtube_lazyload ) {
if ( ! self::is_current_theme() ) {
return $disable_youtube_lazyload;
}
$disable_youtube_lazyload[] = 'Divi';
return $disable_youtube_lazyload;
}
/**
* Disables setting explicit dimensions on images where Divi calculates height as percentage.
*
* @since 3.8.2
*
* @param array $images The array of images selected for adding image dimensions.
*
* @return array The array without images using data-height-percentage.
*/
public function disable_image_dimensions_height_percentage( array $images ) {
foreach ( $images as $key => $image ) {
if ( false !== strpos( strtolower( $image ), 'data-height-percentage' ) ) {
unset( $images[ $key ] );
}
}
return $images;
}
/**
* Disable divi jquery body.
*
* @since 3.9.3
*/
public function disable_divi_jquery_body() {
if (
$this->delayjs_html->is_allowed()
&& defined( 'ET_CORE_VERSION' )
&& version_compare( ET_CORE_VERSION, '4.10', '>=' )
) {
add_filter( 'et_builder_enable_jquery_body', '__return_false' );
}
}
/**
* Excludes Divi's CSS files from CSS combination
*
* @since 3.10.1
*
* @param array $exclude_css An array of CSS to be excluded.
*
* @return array the updated array of paths
*/
public function exclude_css_from_combine( $exclude_css ) {
if ( ! (bool) $this->options->get( 'minify_concatenate_css', 0 ) ) {
return $exclude_css;
}
$wp_content = wp_parse_url( content_url( '/' ), PHP_URL_PATH );
if ( $wp_content ) {
$exclude_css[] = $wp_content . 'et-cache/(.*).css';
}
return $exclude_css;
}
/**
* Disable Divi dynamic CSS when RUCSS is activated
*
* @return void
*/
public function disable_dynamic_css_on_rucss() {
if ( ! $this->options->get( 'remove_unused_css', false ) ) {
return;
}
add_filter( 'et_use_dynamic_css', '__return_false' );
}
/**
* Remove dynamic late assets action.
*
* @return void
*/
public function remove_assets_generated() {
remove_all_actions( 'et_dynamic_late_assets_generated' );
}
}