PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-beta5
Elementor Website Builder – more than just a page builder v3.23.0-beta5
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
← All changes | modules/element-cache/module.php +35 -20 4.3.2 → 3.23.0-beta5 View file →
@@ -13,10 +13,8 @@
13 13 }
14 14
15 15 class Module extends BaseModule {
16 16
17 - const OPTION_UNIQUE_ID = '_elementor_element_cache_unique_id';
18 -
19 17 public function get_name() {
20 18 return 'element-cache';
21 19 }
22 20
@@ -22,11 +20,14 @@
22 20
23 21 public function __construct() {
24 22 parent::__construct();
25 23
24 + $this->register_experiments();
26 25 $this->register_shortcode();
27 26
28 - add_filter( 'elementor/element_cache/unique_id', [ $this, 'get_unique_id' ] );
27 + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) {
28 + return;
29 + }
29 30
30 31 $this->add_advanced_tab_actions();
31 32
32 33 if ( is_admin() ) {
@@ -31,19 +32,26 @@
31 32
32 33 if ( is_admin() ) {
33 34 add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 100 );
34 35 }
36 +
37 + $this->clear_cache_on_site_changed();
35 38 }
36 39
37 - public function get_unique_id() {
38 - $unique_id = get_option( static::OPTION_UNIQUE_ID );
39 -
40 - if ( ! $unique_id ) {
41 - $unique_id = md5( uniqid( wp_generate_password() ) );
42 - update_option( static::OPTION_UNIQUE_ID, $unique_id );
43 - }
44 -
45 - return $unique_id;
40 + private function register_experiments() {
41 + Plugin::$instance->experiments->add_feature( [
42 + 'name' => 'e_element_cache',
43 + 'title' => esc_html__( 'Element Caching', 'elementor' ),
44 + 'tag' => esc_html__( 'Performance', 'elementor' ),
45 + 'description' => esc_html__( 'Elements caching reduces loading times by serving up a copy of an element instead of rendering it fresh every time the page is loaded. When active, Elementor will determine which elements can benefit from static loading - but you can override this.', 'elementor' ),
46 + 'release_status' => ExperimentsManager::RELEASE_STATUS_BETA,
47 + 'default' => ExperimentsManager::STATE_INACTIVE,
48 + 'new_site' => [
49 + 'default_active' => true,
50 + 'minimum_installation_version' => '3.23.0',
51 + ],
52 + 'generator_tag' => true,
53 + ] );
46 54 }
47 55
48 56 private function register_shortcode() {
49 57 add_shortcode( 'elementor-element', function ( $atts ) {
@@ -50,12 +58,8 @@
50 58 if ( empty( $atts['data'] ) ) {
51 59 return '';
52 60 }
53 61
54 - if ( empty( $atts['k'] ) || $atts['k'] !== $this->get_unique_id() ) {
55 - return '';
56 - }
57 -
58 62 $widget_data = json_decode( base64_decode( $atts['data'] ), true );
59 63
60 64 if ( empty( $widget_data ) || ! is_array( $widget_data ) ) {
61 65 return '';
@@ -73,11 +77,11 @@
73 77 } );
74 78 }
75 79
76 80 private function add_advanced_tab_actions() {
77 - $hooks = [
81 + $hooks = array(
78 82 'elementor/element/common/_section_style/after_section_end' => '_css_classes', // Widgets
79 - ];
83 + );
80 84
81 85 foreach ( $hooks as $hook => $injection_position ) {
82 86 add_action(
83 87 $hook,
@@ -118,15 +122,14 @@
118 122 Settings::TAB_PERFORMANCE,
119 123 Settings::TAB_PERFORMANCE,
120 124 'element_cache_ttl',
121 125 [
122 - 'label' => esc_html__( 'Element Cache', 'elementor' ),
126 + 'label' => esc_html__( 'Element Cache Expiration', 'elementor' ),
123 127 'field_args' => [
124 128 'class' => 'elementor-element-cache-ttl',
125 129 'type' => 'select',
126 130 'std' => '24',
127 131 'options' => [
128 - 'disable' => esc_html__( 'Disable', 'elementor' ),
129 132 '1' => esc_html__( '1 Hour', 'elementor' ),
130 133 '6' => esc_html__( '6 Hours', 'elementor' ),
131 134 '12' => esc_html__( '12 Hours', 'elementor' ),
132 135 '24' => esc_html__( '1 Day', 'elementor' ),
@@ -139,6 +142,18 @@
139 142 'desc' => esc_html__( 'Specify the duration for which data is stored in the cache. Elements caching speeds up loading by serving pre-rendered copies of elements, rather than rendering them fresh each time. This control ensures efficient performance and up-to-date content.', 'elementor' ),
140 143 ],
141 144 ]
142 145 );
146 + }
147 +
148 + private function clear_cache_on_site_changed() {
149 + add_action( 'activated_plugin', [ $this, 'clear_cache' ] );
150 + add_action( 'deactivated_plugin', [ $this, 'clear_cache' ] );
151 + add_action( 'switch_theme', [ $this, 'clear_cache' ] );
152 + add_action( 'upgrader_process_complete', [ $this, 'clear_cache' ] );
153 + }
154 +
155 + public function clear_cache() {
156 + Plugin::$instance->files_manager->clear_cache();
157 +
143 158 }
144 159 }