| @@ -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 | |
| @@ -24,9 +22,11 @@ | ||
| 24 | 22 | parent::__construct(); |
| 25 | 23 | |
| 26 | 24 | $this->register_shortcode(); |
| 27 | 25 | |
| 28 | - add_filter( 'elementor/element_cache/unique_id', [ $this, 'get_unique_id' ] ); | |
| 26 | + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) { | |
| 27 | + return; | |
| 28 | + } | |
| 29 | 29 | |
| 30 | 30 | $this->add_advanced_tab_actions(); |
| 31 | 31 | |
| 32 | 32 | if ( is_admin() ) { |
| @@ -31,19 +31,26 @@ | ||
| 31 | 31 | |
| 32 | 32 | if ( is_admin() ) { |
| 33 | 33 | add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 100 ); |
| 34 | 34 | } |
| 35 | + | |
| 36 | + $this->clear_cache_on_site_changed(); | |
| 35 | 37 | } |
| 36 | 38 | |
| 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; | |
| 39 | + public static function get_experimental_data(): array { | |
| 40 | + return [ | |
| 41 | + 'name' => 'e_element_cache', | |
| 42 | + 'title' => esc_html__( 'Element Caching', 'elementor' ), | |
| 43 | + 'tag' => esc_html__( 'Performance', 'elementor' ), | |
| 44 | + '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' ), | |
| 45 | + 'release_status' => ExperimentsManager::RELEASE_STATUS_BETA, | |
| 46 | + 'default' => ExperimentsManager::STATE_INACTIVE, | |
| 47 | + 'new_site' => [ | |
| 48 | + 'default_active' => true, | |
| 49 | + 'minimum_installation_version' => '3.23.0', | |
| 50 | + ], | |
| 51 | + 'generator_tag' => true, | |
| 52 | + ]; | |
| 46 | 53 | } |
| 47 | 54 | |
| 48 | 55 | private function register_shortcode() { |
| 49 | 56 | add_shortcode( 'elementor-element', function ( $atts ) { |
| @@ -50,12 +57,8 @@ | ||
| 50 | 57 | if ( empty( $atts['data'] ) ) { |
| 51 | 58 | return ''; |
| 52 | 59 | } |
| 53 | 60 | |
| 54 | - if ( empty( $atts['k'] ) || $atts['k'] !== $this->get_unique_id() ) { | |
| 55 | - return ''; | |
| 56 | - } | |
| 57 | - | |
| 58 | 61 | $widget_data = json_decode( base64_decode( $atts['data'] ), true ); |
| 59 | 62 | |
| 60 | 63 | if ( empty( $widget_data ) || ! is_array( $widget_data ) ) { |
| 61 | 64 | return ''; |
| @@ -60,8 +63,10 @@ | ||
| 60 | 63 | if ( empty( $widget_data ) || ! is_array( $widget_data ) ) { |
| 61 | 64 | return ''; |
| 62 | 65 | } |
| 63 | 66 | |
| 67 | + $widget_data['settings']['isShortcode'] = true; | |
| 68 | + | |
| 64 | 69 | ob_start(); |
| 65 | 70 | |
| 66 | 71 | $element = Plugin::$instance->elements_manager->create_element_instance( $widget_data ); |
| 67 | 72 | |
| @@ -139,6 +144,19 @@ | ||
| 139 | 144 | '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 | 145 | ], |
| 141 | 146 | ] |
| 142 | 147 | ); |
| 148 | + } | |
| 149 | + | |
| 150 | + private function clear_cache_on_site_changed() { | |
| 151 | + add_action( 'activated_plugin', [ $this, 'clear_cache' ] ); | |
| 152 | + add_action( 'deactivated_plugin', [ $this, 'clear_cache' ] ); | |
| 153 | + add_action( 'switch_theme', [ $this, 'clear_cache' ] ); | |
| 154 | + add_action( 'upgrader_process_complete', [ $this, 'clear_cache' ] ); | |
| 155 | + | |
| 156 | + add_action( 'update_option_elementor_element_cache_ttl', [ $this, 'clear_cache' ] ); | |
| 157 | + } | |
| 158 | + | |
| 159 | + public function clear_cache() { | |
| 160 | + Plugin::$instance->files_manager->clear_cache(); | |
| 143 | 161 | } |
| 144 | 162 | } |