PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.0
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 / variables / classes / css-renderer.php

css-renderer.php in Elementor Website Builder – more than just a page builder 4.2.0, at modules/variables/classes/css-renderer.php

78 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\Variables\Classes;
4
5 use Elementor\Modules\Variables\Services\Variables_Service;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class CSS_Renderer {
12 private Variables_Service $service;
13
14 public function __construct( Variables_Service $service ) {
15 $this->service = $service;
16 }
17
18 private function global_variables(): array {
19 return $this->service->get_variables_list();
20 }
21
22 public function raw_css(): string {
23 $list_of_variables = $this->global_variables();
24
25 if ( empty( $list_of_variables ) ) {
26 return '';
27 }
28
29 $css_entries = $this->css_entries_for( $list_of_variables );
30
31 if ( empty( $css_entries ) ) {
32 return '';
33 }
34
35 return $this->wrap_with_root( $css_entries );
36 }
37
38 private function css_entries_for( array $list_of_variables ): array {
39 $entries = [];
40
41 foreach ( $list_of_variables as $variable_id => $variable ) {
42 $entry = $this->build_css_variable_entry( $variable_id, $variable );
43
44 if ( empty( $entry ) ) {
45 continue;
46 }
47
48 $entries[] = $entry;
49 }
50
51 return $entries;
52 }
53
54 private function build_css_variable_entry( string $id, array $variable ): ?string {
55 $variable_name = sanitize_text_field( $id );
56
57 if ( ! array_key_exists( 'deleted_at', $variable ) ) {
58 $variable_name = sanitize_text_field( $variable['label'] ?? '' );
59 }
60
61 $value = sanitize_text_field( $variable['value'] ?? '' );
62
63 if ( empty( $value ) || empty( $variable_name ) ) {
64 return null;
65 }
66
67 $entry = "--{$variable_name}:{$value};";
68
69 $additional = apply_filters( 'elementor/variables/css_entry_additional', '', $variable, $id );
70
71 return $entry . $additional;
72 }
73
74 private function wrap_with_root( array $css_entries ): string {
75 return ':root { ' . implode( ' ', $css_entries ) . ' }';
76 }
77 }
78