PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.4
Elementor Website Builder – more than just a page builder v4.1.4
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 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | modules/interactions/module.php +36 -19 4.0.94.1.4 View file →
@@ -1,14 +1,16 @@
1 1 <?php
2 +
2 3 namespace Elementor\Modules\Interactions;
3 4
4 5 use Elementor\Core\Base\Module as BaseModule;
6 +use Elementor\Core\Base\Document;
5 7 use Elementor\Core\Experiments\Manager as Experiments_Manager;
6 8 use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule;
9 +use Elementor\Modules\Interactions\Cache\Interactions_Postmeta;
7 10 use Elementor\Plugin;
8 11 use Elementor\Utils;
9 12
10 -
11 13 if ( ! defined( 'ABSPATH' ) ) {
12 14 exit; // Exit if accessed directly.
13 15 }
14 16
@@ -28,10 +30,8 @@
28 30 }
29 31
30 32 private $preset_animations;
31 33
32 - private $frontend_handler;
33 -
34 34 private function get_presets() {
35 35 if ( ! $this->preset_animations ) {
36 36 $this->preset_animations = new Presets();
37 37 }
@@ -38,8 +38,10 @@
38 38
39 39 return $this->preset_animations;
40 40 }
41 41
42 + private $frontend_handler;
43 +
42 44 private function get_frontend_handler() {
43 45 if ( ! $this->frontend_handler ) {
44 46 $this->frontend_handler = new Interactions_Frontend_Handler( fn () => $this->get_config() );
45 47 }
@@ -69,35 +71,50 @@
69 71 if ( ! $this->is_experiment_active() ) {
70 72 return;
71 73 }
72 74
75 + $this->register_hooks();
76 + }
77 +
78 + private function register_hooks() {
73 79 add_action( 'elementor/frontend/after_register_scripts', fn () => $this->register_frontend_scripts() );
80 + add_action( 'elementor/preview/enqueue_scripts', fn () => $this->enqueue_preview_scripts() );
81 +
74 82 add_action( 'elementor/editor/before_enqueue_scripts', fn () => $this->enqueue_editor_scripts() );
75 - add_action( 'elementor/preview/enqueue_scripts', fn () => $this->enqueue_preview_scripts() );
76 83 add_action( 'elementor/editor/after_enqueue_scripts', fn () => $this->enqueue_editor_scripts() );
77 84
85 + add_filter( 'elementor/document/save/data', [ $this, 'handle_interactions' ], 10, 2 );
86 + add_action( 'elementor/document/after_save', [ $this, 'handle_interactions_cache' ], 10, 2 );
87 +
78 88 // Collect interactions from documents before they render (header, footer, post content)
79 - add_filter( 'elementor/frontend/builder_content_data', [ $this->get_frontend_handler(), 'collect_document_interactions' ], 10, 2 );
89 + add_filter( 'elementor/frontend/builder_content_data', [
90 + $this->get_frontend_handler(),
91 + 'collect_document_interactions',
92 + ], 10, 2 );
80 93
81 94 // Output centralized interaction data in footer
82 95 add_action( 'wp_footer', [ $this->get_frontend_handler(), 'print_interactions_data' ], 1 );
96 + }
83 97
84 - add_filter( 'elementor/document/save/data',
85 - /**
86 - * @throws \Exception
87 - */
88 - function( $data, $document ) {
89 - $validation = new Validation();
90 - $document_after_sanitization = $validation->sanitize( $data );
91 - $validation->validate();
98 + /**
99 + * Sanitize and validate data before saving the document.
100 + *
101 + * @throws \Exception When validation fails.
102 + * @return array
103 + */
104 + public function handle_interactions( $data, $document ) {
105 + $validation = new Validation();
106 + $document_after_sanitization = $validation->sanitize( $data );
92 107
93 - return $document_after_sanitization;
94 - },
95 - 10, 2 );
108 + $validation->validate();
96 109
97 - add_filter( 'elementor/document/save/data', function( $data, $document ) {
98 - return ( new Parser( $document->get_main_id() ) )->assign_interaction_ids( $data );
99 - }, 11, 2 );
110 + $parser = new Parser( $document->get_main_id() );
111 + return $parser->assign_interaction_ids( $document_after_sanitization );
112 + }
113 +
114 + public function handle_interactions_cache( Document $document, $data ) {
115 + $postmeta = new Interactions_Postmeta();
116 + $postmeta->process_content( $document->get_main_id(), $data );
100 117 }
101 118
102 119 public function get_config() {
103 120 return [