PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
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 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/interactions/module.php +38 -34 4.0.94.3.0-beta3 View file →
@@ -1,21 +1,22 @@
1 1 <?php
2 +
2 3 namespace Elementor\Modules\Interactions;
3 4
4 5 use Elementor\Core\Base\Module as BaseModule;
5 -use Elementor\Core\Experiments\Manager as Experiments_Manager;
6 +use Elementor\Core\Base\Document;
6 7 use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule;
8 +use Elementor\Modules\Interactions\Cache\Interactions_Postmeta;
7 9 use Elementor\Plugin;
8 10 use Elementor\Utils;
9 11
10 -
11 12 if ( ! defined( 'ABSPATH' ) ) {
12 13 exit; // Exit if accessed directly.
13 14 }
14 15
15 16 class Module extends BaseModule {
17 + const EXPERIMENT_NAME = AtomicWidgetsModule::EXPERIMENT_NAME;
16 18 const MODULE_NAME = 'e-interactions';
17 - const EXPERIMENT_NAME = 'e_interactions';
18 19
19 20 const HANDLE_MOTION_JS = 'motion-js';
20 21 const HANDLE_SHARED_UTILS = 'elementor-interactions-shared-utils';
21 22 const HANDLE_FRONTEND = 'elementor-interactions';
@@ -28,10 +29,8 @@
28 29 }
29 30
30 31 private $preset_animations;
31 32
32 - private $frontend_handler;
33 -
34 33 private function get_presets() {
35 34 if ( ! $this->preset_animations ) {
36 35 $this->preset_animations = new Presets();
37 36 }
@@ -38,8 +37,10 @@
38 37
39 38 return $this->preset_animations;
40 39 }
41 40
41 + private $frontend_handler;
42 +
42 43 private function get_frontend_handler() {
43 44 if ( ! $this->frontend_handler ) {
44 45 $this->frontend_handler = new Interactions_Frontend_Handler( fn () => $this->get_config() );
45 46 }
@@ -46,22 +47,10 @@
46 47
47 48 return $this->frontend_handler;
48 49 }
49 50
50 - public static function get_experimental_data() {
51 - return [
52 - 'name' => self::EXPERIMENT_NAME,
53 - 'title' => esc_html__( 'Interactions', 'elementor' ),
54 - 'description' => esc_html__( 'Enable element interactions.', 'elementor' ),
55 - 'hidden' => true,
56 - 'default' => Experiments_Manager::STATE_ACTIVE,
57 - 'release_status' => Experiments_Manager::RELEASE_STATUS_DEV,
58 - ];
59 - }
60 -
61 51 public function is_experiment_active() {
62 - return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME )
63 - && Plugin::$instance->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME );
52 + return Plugin::$instance->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME );
64 53 }
65 54
66 55 public function __construct() {
67 56 parent::__construct();
@@ -69,35 +58,50 @@
69 58 if ( ! $this->is_experiment_active() ) {
70 59 return;
71 60 }
72 61
62 + $this->register_hooks();
63 + }
64 +
65 + private function register_hooks() {
73 66 add_action( 'elementor/frontend/after_register_scripts', fn () => $this->register_frontend_scripts() );
67 + add_action( 'elementor/preview/enqueue_scripts', fn () => $this->enqueue_preview_scripts() );
68 +
74 69 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 70 add_action( 'elementor/editor/after_enqueue_scripts', fn () => $this->enqueue_editor_scripts() );
77 71
72 + add_filter( 'elementor/document/save/data', [ $this, 'handle_interactions' ], 10, 2 );
73 + add_action( 'elementor/document/after_save', [ $this, 'handle_interactions_cache' ], 10, 2 );
74 +
78 75 // 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 );
76 + add_filter( 'elementor/frontend/builder_content_data', [
77 + $this->get_frontend_handler(),
78 + 'collect_document_interactions',
79 + ], 10, 2 );
80 80
81 81 // Output centralized interaction data in footer
82 82 add_action( 'wp_footer', [ $this->get_frontend_handler(), 'print_interactions_data' ], 1 );
83 + }
83 84
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();
85 + /**
86 + * Sanitize and validate data before saving the document.
87 + *
88 + * @throws \Exception When validation fails.
89 + * @return array
90 + */
91 + public function handle_interactions( $data, $document ) {
92 + $validation = new Validation();
93 + $document_after_sanitization = $validation->sanitize( $data );
92 94
93 - return $document_after_sanitization;
94 - },
95 - 10, 2 );
95 + $validation->validate();
96 96
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 );
97 + $parser = new Parser( $document->get_main_id() );
98 + return $parser->assign_interaction_ids( $document_after_sanitization );
99 + }
100 +
101 + public function handle_interactions_cache( Document $document, $data ) {
102 + $postmeta = new Interactions_Postmeta();
103 + $postmeta->process_content( $document->get_main_id(), $data );
100 104 }
101 105
102 106 public function get_config() {
103 107 return [