PluginProbe
Elementor Website Builder – more than just a page builder / 3.30.0-dev3
Elementor Website Builder – more than just a page builder v3.30.0-dev3
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 3.30.0-dev3, at modules/variables/classes/css-renderer.php

67 lines 1.4 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 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 class CSS_Renderer {
10 private Variables $variables;
11
12 public function __construct( Variables $variables ) {
13 $this->variables = $variables;
14 }
15
16 private function global_variables(): array {
17 return $this->variables->get_all();
18 }
19
20 public function raw_css(): string {
21 $list_of_variables = $this->global_variables();
22
23 if ( empty( $list_of_variables ) ) {
24 return '';
25 }
26
27 $css_entries = $this->css_entries_for( $list_of_variables );
28
29 if ( empty( $css_entries ) ) {
30 return '';
31 }
32
33 return $this->wrap_with_root( $css_entries );
34 }
35
36 private function css_entries_for( array $list_of_variables ): array {
37 $entries = [];
38
39 foreach ( $list_of_variables as $variable_id => $variable ) {
40 $entry = $this->build_css_variable_entry( $variable_id, $variable );
41
42 if ( empty( $entry ) ) {
43 continue;
44 }
45
46 $entries[] = $entry;
47 }
48
49 return $entries;
50 }
51
52 private function build_css_variable_entry( string $id, array $variable ): ?string {
53 $variable_name = sanitize_text_field( $id );
54 $value = sanitize_text_field( $variable['value'] ?? '' );
55
56 if ( empty( $value ) || empty( $variable_name ) ) {
57 return null;
58 }
59
60 return "--{$variable_name}:{$value};";
61 }
62
63 private function wrap_with_root( array $css_entries ): string {
64 return ':root { ' . implode( ' ', $css_entries ) . ' }';
65 }
66 }
67