PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / trunk
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder vtrunk
2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 All 78 releases
ablocks / includes / controls / color.php

color.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder trunk, at includes/controls/color.php

53 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Controls;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\ControlBaseAbstract;
9
10 class Color {
11
12 private static function parse_color_variable_to_object( $value, $type ) {
13 if ( is_string( $value ) && strpos( $value, "var:{$type}" ) === 0 ) {
14 $parts = explode( '|', $value );
15 if ( count( $parts ) === 3 ) {
16 $result = [
17 'source' => $parts[0],
18 'color' => $parts[1] ?: '',
19 ];
20 $result[ $type === 'preset' ? 'slug' : 'id' ] = $parts[2];
21 return $result;
22 }
23 }
24 return false;
25 }
26
27 public static function parse_preset_color_to_object( $value ) {
28 return self::parse_color_variable_to_object( $value, 'preset' );
29 }
30
31 public static function parse_global_color_to_object( $value ) {
32 return self::parse_color_variable_to_object( $value, 'global' );
33 }
34
35 public static function get_css( $attribute_value ) {
36 if ( ! empty( $attribute_value ) ) {
37 $preset_color = self::parse_preset_color_to_object( $attribute_value );
38 $global_color = self::parse_global_color_to_object( $attribute_value );
39
40 if ( $preset_color ) {
41 return sprintf( 'var(--wp--preset--color--%s)', esc_attr( $preset_color['slug'] ) );
42 }
43
44 if ( $global_color ) {
45 return sprintf( 'var(--ablocks-%s)', esc_attr( $global_color['id'] ) );
46 }
47
48 return $attribute_value;
49 }
50 return '';
51 }
52 }
53