PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev4
Elementor Website Builder – more than just a page builder v4.0.0-dev4
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
elementor / modules / atomic-widgets / import-export / modifiers / interactions-ids-modifier.php

interactions-ids-modifier.php in Elementor Website Builder – more than just a page builder 4.0.0-dev4, at modules/atomic-widgets/import-export/modifiers/interactions-ids-modifier.php

57 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\ImportExport\Modifiers;
4
5 use Elementor\Modules\AtomicWidgets\Utils\Utils;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Interactions_Ids_Modifier {
12
13 public static function make() {
14 return new self();
15 }
16
17 public function run( array $element ) {
18 if ( empty( $element['id'] ) || ! isset( $element['interactions'] ) ) {
19 return $element;
20 }
21
22 $interactions = $element['interactions'];
23 if ( is_string( $interactions ) ) {
24 $decoded = json_decode( $interactions, true );
25 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $decoded ) ) {
26 return $element;
27 }
28 $interactions = $decoded;
29 }
30
31 if ( empty( $interactions['items'] ) || ! is_array( $interactions['items'] ) ) {
32 return $element;
33 }
34
35 $existing_ids = [];
36 $prefix = "e-{$element['id']}-";
37
38 foreach ( $interactions['items'] as $index => $item ) {
39 if ( ! is_array( $item ) || ( $item['$$type'] ?? '' ) !== 'interaction-item' || ! isset( $item['value'] ) || ! is_array( $item['value'] ) ) {
40 continue;
41 }
42
43 $new_id = Utils::generate_id( $prefix, $existing_ids );
44 $existing_ids[] = $new_id;
45
46 $interactions['items'][ $index ]['value']['interaction_id'] = [
47 '$$type' => 'string',
48 'value' => $new_id,
49 ];
50 }
51
52 $element['interactions'] = $interactions;
53
54 return $element;
55 }
56 }
57