PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev2
Elementor Website Builder – more than just a page builder v4.0.0-dev2
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 / variables-provider.php

variables-provider.php in Elementor Website Builder – more than just a page builder 4.0.0-dev2, at modules/design-system-sync/classes/variables-provider.php

81 lines 1.9 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\Modules\DesignSystemSync\Module;
6 use Elementor\Modules\Variables\Services\Batch_Operations\Batch_Processor;
7 use Elementor\Modules\Variables\Services\Variables_Service;
8 use Elementor\Modules\Variables\Storage\Variables_Repository;
9 use Elementor\Plugin;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class Variables_Provider {
16 private static $cached_variables = null;
17
18 public static function get_all_variables(): array {
19 if ( null !== self::$cached_variables ) {
20 return self::$cached_variables;
21 }
22
23 $kit = Plugin::$instance->kits_manager->get_active_kit();
24
25 if ( ! $kit ) {
26 return [];
27 }
28
29 $repository = new Variables_Repository( $kit );
30 $service = new Variables_Service( $repository, new Batch_Processor() );
31 self::$cached_variables = $service->get_variables_list();
32
33 return self::$cached_variables;
34 }
35
36 public static function get_synced_color_variables(): array {
37 $all_variables = self::get_all_variables();
38 $color_variables = [];
39
40 foreach ( $all_variables as $id => $variable ) {
41 if ( isset( $variable['deleted'] ) && $variable['deleted'] ) {
42 continue;
43 }
44
45 if ( empty( $variable['type'] ) || 'global-color-variable' !== $variable['type'] ) {
46 continue;
47 }
48
49 if ( empty( $variable['sync_to_v3'] ) ) {
50 continue;
51 }
52
53 $color_variables[ $id ] = $variable;
54 }
55 return $color_variables;
56 }
57
58 public static function clear_cache() {
59 self::$cached_variables = null;
60 }
61
62 public static function get_synced_color_css_entries(): array {
63 $synced_variables = self::get_synced_color_variables();
64 $css_entries = [];
65
66 foreach ( $synced_variables as $id => $variable ) {
67 $label = sanitize_text_field( $variable['label'] ?? '' );
68
69 if ( empty( $label ) ) {
70 continue;
71 }
72
73 $v3_id = Module::get_v3_sync_id( $label );
74
75 $css_entries[] = "--e-global-color-{$v3_id}:var(--{$label});";
76 }
77
78 return $css_entries;
79 }
80 }
81