PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.3
Elementor Website Builder – more than just a page builder v4.2.3
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 / design-system-sync / classes / global-classes-sync-map.php

global-classes-sync-map.php in Elementor Website Builder – more than just a page builder 4.2.3, at modules/design-system-sync/classes/global-classes-sync-map.php

90 lines 1.7 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\DesignSystemSync\Classes;
4
5 use Elementor\Core\Kits\Documents\Kit;
6 use Elementor\Modules\GlobalClasses\Concerns\Has_Kit_Dependency;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class Global_Classes_Sync_Map {
13 use Has_Kit_Dependency;
14
15 const META_KEY = '_elementor_global_classes_sync_to_v3';
16
17 private ?array $cache = null;
18
19 private function __construct() {
20 }
21
22 public static function make( ?Kit $kit = null ): self {
23 $instance = new self();
24
25 if ( ! $kit ) {
26 return $instance;
27 }
28
29 return $instance->set_kit( $kit );
30 }
31
32 public function get_synced_ids(): array {
33 return array_keys( $this->read_stored() );
34 }
35
36 public function is_synced( string $id ): bool {
37 return isset( $this->read_stored()[ $id ] );
38 }
39
40 public function set_map( array $id_to_true ): bool {
41 $kit = $this->get_kit();
42
43 if ( ! $kit ) {
44 return false;
45 }
46
47 $result = $kit->update_meta( self::META_KEY, $id_to_true );
48 $this->cache = $id_to_true;
49
50 return false !== $result;
51 }
52
53 public function apply_changes( array $touched_items, array $deleted_ids ): bool {
54 $current = $this->read_stored();
55
56 foreach ( $deleted_ids as $id ) {
57 unset( $current[ $id ] );
58 }
59
60 foreach ( $touched_items as $id => $item ) {
61 if ( ! empty( $item['sync_to_v3'] ) && (bool) $item['sync_to_v3'] ) {
62 $current[ $id ] = true;
63 } else {
64 unset( $current[ $id ] );
65 }
66 }
67
68 return $this->set_map( $current );
69 }
70
71 private function read_stored(): array {
72 if ( null !== $this->cache ) {
73 return $this->cache;
74 }
75
76 $kit = $this->get_kit();
77
78 if ( ! $kit ) {
79 $this->cache = [];
80
81 return [];
82 }
83
84 $raw = $kit->get_meta( self::META_KEY );
85 $this->cache = is_array( $raw ) ? $raw : [];
86
87 return $this->cache;
88 }
89 }
90