| @@ -1,16 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | namespace Elementor\Modules\Interactions; |
| 4 | 3 | |
| 5 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 6 | -use Elementor\Core\Base\Document; | |
| 7 | 5 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 8 | 6 | use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule; |
| 9 | -use Elementor\Modules\Interactions\Cache\Interactions_Postmeta; | |
| 10 | 7 | use Elementor\Plugin; |
| 11 | 8 | use Elementor\Utils; |
| 12 | 9 | |
| 10 | + | |
| 13 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | 12 | exit; // Exit if accessed directly. |
| 15 | 13 | } |
| 16 | 14 | |
| @@ -30,8 +28,10 @@ | ||
| 30 | 28 | } |
| 31 | 29 | |
| 32 | 30 | private $preset_animations; |
| 33 | 31 | |
| 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,10 +38,8 @@ | ||
| 38 | 38 | |
| 39 | 39 | return $this->preset_animations; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - private $frontend_handler; | |
| 43 | - | |
| 44 | 42 | private function get_frontend_handler() { |
| 45 | 43 | if ( ! $this->frontend_handler ) { |
| 46 | 44 | $this->frontend_handler = new Interactions_Frontend_Handler( fn () => $this->get_config() ); |
| 47 | 45 | } |
| @@ -71,50 +69,35 @@ | ||
| 71 | 69 | if ( ! $this->is_experiment_active() ) { |
| 72 | 70 | return; |
| 73 | 71 | } |
| 74 | 72 | |
| 75 | - $this->register_hooks(); | |
| 76 | - } | |
| 77 | - | |
| 78 | - private function register_hooks() { | |
| 79 | 73 | add_action( 'elementor/frontend/after_register_scripts', fn () => $this->register_frontend_scripts() ); |
| 74 | + add_action( 'elementor/editor/before_enqueue_scripts', fn () => $this->enqueue_editor_scripts() ); | |
| 80 | 75 | add_action( 'elementor/preview/enqueue_scripts', fn () => $this->enqueue_preview_scripts() ); |
| 81 | - | |
| 82 | - add_action( 'elementor/editor/before_enqueue_scripts', fn () => $this->enqueue_editor_scripts() ); | |
| 83 | 76 | add_action( 'elementor/editor/after_enqueue_scripts', fn () => $this->enqueue_editor_scripts() ); |
| 84 | 77 | |
| 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 | - | |
| 88 | 78 | // Collect interactions from documents before they render (header, footer, post content) |
| 89 | - add_filter( 'elementor/frontend/builder_content_data', [ | |
| 90 | - $this->get_frontend_handler(), | |
| 91 | - 'collect_document_interactions', | |
| 92 | - ], 10, 2 ); | |
| 79 | + add_filter( 'elementor/frontend/builder_content_data', [ $this->get_frontend_handler(), 'collect_document_interactions' ], 10, 2 ); | |
| 93 | 80 | |
| 94 | 81 | // Output centralized interaction data in footer |
| 95 | 82 | add_action( 'wp_footer', [ $this->get_frontend_handler(), 'print_interactions_data' ], 1 ); |
| 96 | - } | |
| 97 | 83 | |
| 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 ); | |
| 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(); | |
| 107 | 92 | |
| 108 | - $validation->validate(); | |
| 93 | + return $document_after_sanitization; | |
| 94 | + }, | |
| 95 | + 10, 2 ); | |
| 109 | 96 | |
| 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 ); | |
| 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 ); | |
| 117 | 100 | } |
| 118 | 101 | |
| 119 | 102 | public function get_config() { |
| 120 | 103 | return [ |