PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.0-beta1
Elementor Website Builder – more than just a page builder v3.22.0-beta1
4.3.4 4.3.3 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 All 457 releases
← All changes | modules/element-cache/module.php +37 -89 4.3.1 → 3.22.0-beta1 View file →
@@ -5,9 +5,8 @@
5 5 use Elementor\Core\Base\Module as BaseModule;
6 6 use Elementor\Core\Experiments\Manager as ExperimentsManager;
7 7 use Elementor\Element_Base;
8 8 use Elementor\Plugin;
9 -use Elementor\Settings;
10 9
11 10 if ( ! defined( 'ABSPATH' ) ) {
12 11 exit; // Exit if accessed directly.
13 12 }
@@ -13,10 +12,8 @@
13 12 }
14 13
15 14 class Module extends BaseModule {
16 15
17 - const OPTION_UNIQUE_ID = '_elementor_element_cache_unique_id';
18 -
19 16 public function get_name() {
20 17 return 'element-cache';
21 18 }
22 19
@@ -22,64 +19,33 @@
22 19
23 20 public function __construct() {
24 21 parent::__construct();
25 22
23 + $this->register_experiments();
24 + $this->add_advanced_tab_actions();
26 25 $this->register_shortcode();
26 + }
27 27
28 - add_filter( 'elementor/element_cache/unique_id', [ $this, 'get_unique_id' ] );
29 -
30 - $this->add_advanced_tab_actions();
31 -
32 - if ( is_admin() ) {
33 - add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 100 );
34 - }
35 -
36 - $this->clear_cache_on_site_changed();
28 + private function register_experiments() {
29 + Plugin::$instance->experiments->add_feature( [
30 + 'name' => 'e_element_cache',
31 + 'title' => esc_html__( 'Element Caching', 'elementor' ),
32 + 'tag' => esc_html__( 'Performance', 'elementor' ),
33 + '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' ),
34 + 'release_status' => ExperimentsManager::RELEASE_STATUS_DEV,
35 + 'default' => ExperimentsManager::STATE_INACTIVE,
36 + 'generator_tag' => true,
37 + ] );
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 );
40 + private function add_advanced_tab_actions() {
41 + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) {
42 + return;
45 43 }
46 44
47 - return $unique_id;
48 - }
49 -
50 - private function register_shortcode() {
51 - add_shortcode( 'elementor-element', function ( $atts ) {
52 - if ( empty( $atts['data'] ) ) {
53 - return '';
54 - }
55 -
56 - if ( empty( $atts['k'] ) || $atts['k'] !== $this->get_unique_id() ) {
57 - return '';
58 - }
59 -
60 - $widget_data = json_decode( base64_decode( $atts['data'] ), true );
61 -
62 - if ( empty( $widget_data ) || ! is_array( $widget_data ) ) {
63 - return '';
64 - }
65 -
66 - ob_start();
67 -
68 - $element = Plugin::$instance->elements_manager->create_element_instance( $widget_data );
69 -
70 - if ( $element ) {
71 - $element->print_element();
72 - }
73 -
74 - return ob_get_clean();
75 - } );
76 - }
77 -
78 - private function add_advanced_tab_actions() {
79 - $hooks = [
45 + $hooks = array(
80 46 'elementor/element/common/_section_style/after_section_end' => '_css_classes', // Widgets
81 - ];
47 + );
82 48
83 49 foreach ( $hooks as $hook => $injection_position ) {
84 50 add_action(
85 51 $hook,
@@ -114,46 +80,28 @@
114 80
115 81 $element->end_injection();
116 82 }
117 83
118 - public function register_admin_fields( Settings $settings ) {
119 - $settings->add_field(
120 - Settings::TAB_PERFORMANCE,
121 - Settings::TAB_PERFORMANCE,
122 - 'element_cache_ttl',
123 - [
124 - 'label' => esc_html__( 'Element Cache', 'elementor' ),
125 - 'field_args' => [
126 - 'class' => 'elementor-element-cache-ttl',
127 - 'type' => 'select',
128 - 'std' => '24',
129 - 'options' => [
130 - 'disable' => esc_html__( 'Disable', 'elementor' ),
131 - '1' => esc_html__( '1 Hour', 'elementor' ),
132 - '6' => esc_html__( '6 Hours', 'elementor' ),
133 - '12' => esc_html__( '12 Hours', 'elementor' ),
134 - '24' => esc_html__( '1 Day', 'elementor' ),
135 - '72' => esc_html__( '3 Days', 'elementor' ),
136 - '168' => esc_html__( '1 Week', 'elementor' ),
137 - '336' => esc_html__( '2 Weeks', 'elementor' ),
138 - '720' => esc_html__( '1 Month', 'elementor' ),
139 - '8760' => esc_html__( '1 Year', 'elementor' ),
140 - ],
141 - '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' ),
142 - ],
143 - ]
144 - );
145 - }
84 + private function register_shortcode() {
85 + add_shortcode( 'elementor-element', function ( $atts ) {
86 + if ( empty( $atts['data'] ) ) {
87 + return '';
88 + }
146 89
147 - private function clear_cache_on_site_changed() {
148 - add_action( 'activated_plugin', [ $this, 'clear_cache' ] );
149 - add_action( 'deactivated_plugin', [ $this, 'clear_cache' ] );
150 - add_action( 'switch_theme', [ $this, 'clear_cache' ] );
151 - add_action( 'upgrader_process_complete', [ $this, 'clear_cache' ] );
90 + $widget_data = json_decode( base64_decode( $atts['data'] ), true );
152 91
153 - add_action( 'update_option_elementor_element_cache_ttl', [ $this, 'clear_cache' ] );
154 - }
92 + if ( empty( $widget_data ) || ! is_array( $widget_data ) ) {
93 + return '';
94 + }
155 95
156 - public function clear_cache() {
157 - Plugin::$instance->files_manager->clear_cache();
96 + ob_start();
97 +
98 + $element = Plugin::$instance->elements_manager->create_element_instance( $widget_data );
99 +
100 + if ( $element ) {
101 + $element->print_element();
102 + }
103 +
104 + return ob_get_clean();
105 + } );
158 106 }
159 107 }