| @@ -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() ) { |
| @@ -35,17 +36,22 @@ | ||
| 35 | 36 | |
| 36 | 37 | $this->clear_cache_on_site_changed(); |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | - public function get_unique_id() { | |
| 40 | - $unique_id = get_option( static::OPTION_UNIQUE_ID ); | |
| 41 | - | |
| 42 | - if ( ! $unique_id ) { | |
| 43 | - $unique_id = md5( uniqid( wp_generate_password() ) ); | |
| 44 | - update_option( static::OPTION_UNIQUE_ID, $unique_id ); | |
| 45 | - } | |
| 46 | - | |
| 47 | - 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 | + ] ); | |
| 48 | 54 | } |
| 49 | 55 | |
| 50 | 56 | private function register_shortcode() { |
| 51 | 57 | add_shortcode( 'elementor-element', function ( $atts ) { |
| @@ -52,12 +58,8 @@ | ||
| 52 | 58 | if ( empty( $atts['data'] ) ) { |
| 53 | 59 | return ''; |
| 54 | 60 | } |
| 55 | 61 | |
| 56 | - if ( empty( $atts['k'] ) || $atts['k'] !== $this->get_unique_id() ) { | |
| 57 | - return ''; | |
| 58 | - } | |
| 59 | - | |
| 60 | 62 | $widget_data = json_decode( base64_decode( $atts['data'] ), true ); |
| 61 | 63 | |
| 62 | 64 | if ( empty( $widget_data ) || ! is_array( $widget_data ) ) { |
| 63 | 65 | return ''; |
| @@ -120,15 +122,14 @@ | ||
| 120 | 122 | Settings::TAB_PERFORMANCE, |
| 121 | 123 | Settings::TAB_PERFORMANCE, |
| 122 | 124 | 'element_cache_ttl', |
| 123 | 125 | [ |
| 124 | - 'label' => esc_html__( 'Element Cache', 'elementor' ), | |
| 126 | + 'label' => esc_html__( 'Element Cache Expiration', 'elementor' ), | |
| 125 | 127 | 'field_args' => [ |
| 126 | 128 | 'class' => 'elementor-element-cache-ttl', |
| 127 | 129 | 'type' => 'select', |
| 128 | 130 | 'std' => '24', |
| 129 | 131 | 'options' => [ |
| 130 | - 'disable' => esc_html__( 'Disable', 'elementor' ), | |
| 131 | 132 | '1' => esc_html__( '1 Hour', 'elementor' ), |
| 132 | 133 | '6' => esc_html__( '6 Hours', 'elementor' ), |
| 133 | 134 | '12' => esc_html__( '12 Hours', 'elementor' ), |
| 134 | 135 | '24' => esc_html__( '1 Day', 'elementor' ), |
| @@ -148,12 +149,11 @@ | ||
| 148 | 149 | add_action( 'activated_plugin', [ $this, 'clear_cache' ] ); |
| 149 | 150 | add_action( 'deactivated_plugin', [ $this, 'clear_cache' ] ); |
| 150 | 151 | add_action( 'switch_theme', [ $this, 'clear_cache' ] ); |
| 151 | 152 | add_action( 'upgrader_process_complete', [ $this, 'clear_cache' ] ); |
| 152 | - | |
| 153 | - add_action( 'update_option_elementor_element_cache_ttl', [ $this, 'clear_cache' ] ); | |
| 154 | 153 | } |
| 155 | 154 | |
| 156 | 155 | public function clear_cache() { |
| 157 | 156 | Plugin::$instance->files_manager->clear_cache(); |
| 157 | + | |
| 158 | 158 | } |
| 159 | 159 | } |