PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-beta1
Elementor Website Builder – more than just a page builder v3.28.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 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 All 457 releases
← All changes | modules/global-classes/global-classes-repository.php +8 -78 4.0.9 → 3.28.0-beta1 View file →
@@ -1,10 +1,7 @@
1 1 <?php
2 2 namespace Elementor\Modules\GlobalClasses;
3 3
4 -use Elementor\Core\Kits\Documents\Kit;
5 -use Elementor\Modules\AtomicWidgets\PropTypeMigrations\Migrations_Orchestrator;
6 -use Elementor\Modules\GlobalClasses\Global_Classes_Parser;
7 4 use Elementor\Plugin;
8 5
9 6 if ( ! defined( 'ABSPATH' ) ) {
10 7 exit; // Exit if accessed directly.
@@ -10,68 +7,20 @@
10 7 exit; // Exit if accessed directly.
11 8 }
12 9
13 10 class Global_Classes_Repository {
11 + const META_KEY = '_elementor_global_classes';
14 12
15 - const META_KEY_FRONTEND = '_elementor_global_classes';
16 - const META_KEY_PREVIEW = '_elementor_global_classes_preview';
17 -
18 - const CONTEXT_FRONTEND = 'frontend';
19 - const CONTEXT_PREVIEW = 'preview';
20 -
21 - private string $context = self::CONTEXT_FRONTEND;
22 -
23 - private ?Global_Classes $cache = null;
24 -
25 - private ?Kit $kit = null;
26 -
27 - public function __construct( ?Kit $kit = null ) {
28 - $this->kit = $kit;
13 + public static function make(): Global_Classes_Repository {
14 + return new self();
29 15 }
30 16
31 - public static function make( ?Kit $kit = null ): Global_Classes_Repository {
32 - return new self( $kit );
33 - }
17 + public function all() {
18 + $all = Plugin::$instance->kits_manager->get_active_kit()->get_json_meta( self::META_KEY );
34 19
35 - public function context( string $context ): self {
36 - $this->context = $context;
37 - $this->cache = null;
38 -
39 - return $this;
20 + return Global_Classes::make( $all['items'] ?? [], $all['order'] ?? [] );
40 21 }
41 22
42 - public function all( bool $force = false ): Global_Classes {
43 - if ( ! $force && null !== $this->cache ) {
44 - return $this->cache;
45 - }
46 -
47 - $meta_key = $this->get_meta_key();
48 - $kit = $this->get_kit();
49 - $all = $kit->get_json_meta( $meta_key );
50 -
51 - $is_preview = static::META_KEY_PREVIEW === $meta_key;
52 - $is_empty = empty( $all );
53 -
54 - if ( $is_preview && $is_empty ) {
55 - $all = $kit->get_json_meta( static::META_KEY_FRONTEND );
56 - }
57 -
58 - $all['order'] = Global_Classes_Parser::sanitize_order( $all['items'] ?? [], $all['order'] ?? [] );
59 -
60 - Migrations_Orchestrator::make()->migrate(
61 - $all,
62 - $kit->get_id(),
63 - $meta_key,
64 - function( $migrated_data ) use ( $kit, $meta_key ) {
65 - $kit->update_json_meta( $meta_key, $migrated_data );
66 - }
67 - );
68 -
69 - $this->cache = Global_Classes::make( $all['items'] ?? [], $all['order'] ?? [] );
70 -
71 - return $this->cache;
72 - }
73 -
74 23 public function put( array $items, array $order ) {
75 24 $current_value = $this->all()->get();
76 25
77 26 $updated_value = [
@@ -83,32 +32,13 @@
83 32 if ( $current_value === $updated_value ) {
84 33 return;
85 34 }
86 35
87 - $meta_key = $this->get_meta_key();
88 - $value = $this->get_kit()->update_json_meta( $meta_key, $updated_value );
36 + $value = Plugin::$instance->kits_manager->get_active_kit()->update_json_meta( self::META_KEY, $updated_value );
89 37
90 - $should_delete_preview = static::META_KEY_FRONTEND === $meta_key;
91 -
92 - if ( $should_delete_preview ) {
93 - $this->get_kit()->delete_meta( static::META_KEY_PREVIEW );
94 - }
95 -
96 38 if ( ! $value ) {
97 39 throw new \Exception( 'Failed to update global classes' );
98 40 }
99 41
100 - $this->cache = null;
101 -
102 - do_action( 'elementor/global_classes/update', $this->context, $updated_value, $current_value );
103 - }
104 -
105 - private function get_meta_key(): string {
106 - return static::CONTEXT_FRONTEND === $this->context
107 - ? static::META_KEY_FRONTEND
108 - : static::META_KEY_PREVIEW;
109 - }
110 -
111 - private function get_kit(): Kit {
112 - return $this->kit ?? Plugin::$instance->kits_manager->get_active_kit();
42 + do_action( 'elementor/global_classes/update' );
113 43 }
114 44 }