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 +40 -77 4.3.2 → 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,62 +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 - }
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 + ] );
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 );
40 + private function add_advanced_tab_actions() {
41 + if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) {
42 + return;
43 43 }
44 44
45 - return $unique_id;
46 - }
47 -
48 - private function register_shortcode() {
49 - add_shortcode( 'elementor-element', function ( $atts ) {
50 - if ( empty( $atts['data'] ) ) {
51 - return '';
52 - }
53 -
54 - if ( empty( $atts['k'] ) || $atts['k'] !== $this->get_unique_id() ) {
55 - return '';
56 - }
57 -
58 - $widget_data = json_decode( base64_decode( $atts['data'] ), true );
59 -
60 - if ( empty( $widget_data ) || ! is_array( $widget_data ) ) {
61 - return '';
62 - }
63 -
64 - ob_start();
65 -
66 - $element = Plugin::$instance->elements_manager->create_element_instance( $widget_data );
67 -
68 - if ( $element ) {
69 - $element->print_element();
70 - }
71 -
72 - return ob_get_clean();
73 - } );
74 - }
75 -
76 - private function add_advanced_tab_actions() {
77 - $hooks = [
45 + $hooks = array(
78 46 'elementor/element/common/_section_style/after_section_end' => '_css_classes', // Widgets
79 - ];
47 + );
80 48
81 49 foreach ( $hooks as $hook => $injection_position ) {
82 50 add_action(
83 51 $hook,
@@ -112,33 +80,28 @@
112 80
113 81 $element->end_injection();
114 82 }
115 83
116 - public function register_admin_fields( Settings $settings ) {
117 - $settings->add_field(
118 - Settings::TAB_PERFORMANCE,
119 - Settings::TAB_PERFORMANCE,
120 - 'element_cache_ttl',
121 - [
122 - 'label' => esc_html__( 'Element Cache', 'elementor' ),
123 - 'field_args' => [
124 - 'class' => 'elementor-element-cache-ttl',
125 - 'type' => 'select',
126 - 'std' => '24',
127 - 'options' => [
128 - 'disable' => esc_html__( 'Disable', 'elementor' ),
129 - '1' => esc_html__( '1 Hour', 'elementor' ),
130 - '6' => esc_html__( '6 Hours', 'elementor' ),
131 - '12' => esc_html__( '12 Hours', 'elementor' ),
132 - '24' => esc_html__( '1 Day', 'elementor' ),
133 - '72' => esc_html__( '3 Days', 'elementor' ),
134 - '168' => esc_html__( '1 Week', 'elementor' ),
135 - '336' => esc_html__( '2 Weeks', 'elementor' ),
136 - '720' => esc_html__( '1 Month', 'elementor' ),
137 - '8760' => esc_html__( '1 Year', 'elementor' ),
138 - ],
139 - '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 - ],
141 - ]
142 - );
84 + private function register_shortcode() {
85 + add_shortcode( 'elementor-element', function ( $atts ) {
86 + if ( empty( $atts['data'] ) ) {
87 + return '';
88 + }
89 +
90 + $widget_data = json_decode( base64_decode( $atts['data'] ), true );
91 +
92 + if ( empty( $widget_data ) || ! is_array( $widget_data ) ) {
93 + return '';
94 + }
95 +
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 + } );
143 106 }
144 107 }