Avada.php
3.79 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
<?php
namespace WP_Rocket\ThirdParty\Themes;
use WP_Rocket\Admin\Options_Data;
/**
* Compatibility class for Avada theme
*/
class Avada extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'avada';
/**
* Options instance
*
* @var Options_Data
*/
private $options;
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.3.1
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'avada_clear_dynamic_css_cache' => 'clean_domain',
'rocket_exclude_defer_js' => 'exclude_defer_js',
'rocket_maybe_disable_lazyload_helper' => 'maybe_disable_lazyload',
'fusion_cache_reset_after' => 'clean_domain',
'update_option_fusion_options' => [ 'maybe_deactivate_lazyload', 10, 2 ],
'rocket_wc_product_gallery_delay_js_exclusions' => 'exclude_delay_js',
'init' => 'disable_compilers',
];
}
/**
* Constructor
*
* @param Options_Data $options WP Rocket options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* When Avada theme purge its own cache.
* Clear WP Rocket cache when Avada dynamic CSS is updated.
*
* @return void
*/
public function clean_domain() {
rocket_clean_domain();
}
/**
* Deactivate WP Rocket lazyload if Avada lazyload is enabled.
*
* @since 3.3.4
*
* @param string $old_value Previous Avada option value.
* @param string $value New Avada option value.
* @return void
*/
public function maybe_deactivate_lazyload( $old_value, $value ) {
if (
empty( $old_value['lazy_load'] )
||
( ! empty( $value['lazy_load'] ) && 'avada' === $value['lazy_load'] )
) {
update_rocket_option( 'lazyload', 0 );
}
}
/**
* Excludes Avada Google Maps JS files from defer JS
*
* @param array $exclude_defer_js Array of JS filepaths to be excluded.
* @return array
*/
public function exclude_defer_js( $exclude_defer_js ) {
$exclude_defer_js[] = '/jquery-?[0-9.]*(.min|.slim|.slim.min)?.js';
$exclude_defer_js[] = 'maps.googleapis.com';
return $exclude_defer_js;
}
/**
* Disable WP Rocket lazyload field if Avada lazyload is enabled
*
* @since 3.3.4
* @param array $disable_images_lazyload Array with plugins which disable lazyload functionality.
* @return array
*/
public function maybe_disable_lazyload( $disable_images_lazyload ) {
$avada_options = get_option( 'fusion_options' );
if ( empty( $avada_options['lazy_load'] ) ) {
return $disable_images_lazyload;
}
if ( ! empty( $avada_options['lazy_load'] && 'avada' !== $avada_options['lazy_load'] ) ) {
return $disable_images_lazyload;
}
$disable_images_lazyload[] = __( 'Avada', 'rocket' );
return $disable_images_lazyload;
}
/**
* Excludes some Avada JS from delay JS execution when WC product gallery has images
*
* @since 3.10.2
*
* @param array $exclusions Array of exclusion patterns.
*
* @return array
*/
public function exclude_delay_js( $exclusions ): array {
$base_path = wp_parse_url( get_stylesheet_directory_uri(), PHP_URL_PATH );
if ( empty( $base_path ) ) {
return $exclusions;
}
$exclusions[] = $base_path . '/includes/lib/assets/min/js/library/jquery.flexslider.js';
$exclusions[] = $base_path . '/assets/min/js/general/avada-woo-product-images.js';
return $exclusions;
}
/**
* Disable CSS and JS combine file from Avada.
*/
public function disable_compilers() {
if ( $this->options->get( 'remove_unused_css', false ) && ! defined( 'FUSION_DISABLE_COMPILERS' ) ) {
define( 'FUSION_DISABLE_COMPILERS', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
}
}
}