PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 1.1.4
Gutenify – Visual Site Builder Blocks & Starter Templates v1.1.4
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / inc / styles.php

styles.php in Gutenify – Visual Site Builder Blocks & Starter Templates 1.1.4, at inc/styles.php

93 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Function to add style variables.
4 *
5 * @return void
6 */
7 function gutenify_get_color_value( $value ) {
8 if ( strpos($value, 'var:') !== false ) {
9 // var:preset|color|vivid-red
10 $value = str_replace( 'var:','', $value );
11 $value = str_replace( '|', '--', $value );
12 return 'var( --wp--' . $value . ')';
13 }
14 return $value;
15 }
16 function gutenify_global_styles_vars() {
17 $transient_name = 'gutenify_global_styles_vars';
18 $cached = get_transient( $transient_name );
19 if ( $cached ) {
20 wp_add_inline_style( 'global-styles', $cached );
21 return false;
22 }
23
24 $core_button_styles = wp_get_global_styles(
25 array(),
26 array( 'block_name' => 'core/button' )
27 );
28 $css_styles = '';
29 $element_css_styles = '';
30 if ( ! empty( $core_button_styles['spacing']['padding'] ) ) {
31 if ( ! empty( $core_button_styles['spacing']['padding']['left'] ) ) {
32 $element_css_styles .= '--wp--custom--core-button--spacing--padding--left: ' . $core_button_styles['spacing']['padding']['left'] . ';';
33 }
34 if ( ! empty( $core_button_styles['spacing']['padding']['right'] ) ) {
35 $element_css_styles .= '--wp--custom--core-button--spacing--padding--right: ' . $core_button_styles['spacing']['padding']['right'] . ';';
36 }
37 if ( ! empty( $core_button_styles['spacing']['padding']['top'] ) ) {
38 $element_css_styles .= '--wp--custom--core-button--spacing--padding--top: ' . $core_button_styles['spacing']['padding']['top'] . ';';
39 }
40 if ( ! empty( $core_button_styles['spacing']['padding']['bottom'] ) ) {
41 $element_css_styles .= '--wp--custom--core-button--spacing--padding--bottom: ' . $core_button_styles['spacing']['padding']['bottom'] . ';';
42 }
43 }
44
45 if ( ! empty( $core_button_styles['color']['background'] ) ) {
46 $element_css_styles .= '--wp--custom--core-button--color--background: ' . gutenify_get_color_value( $core_button_styles['color']['background'] ) . ';';
47 }
48
49 if ( ! empty( $core_button_styles['color']['text'] ) ) {
50 $element_css_styles .= '--wp--custom--core-button--color: ' . gutenify_get_color_value( $core_button_styles['color']['text'] ) . ';';
51 }
52
53 if ( isset( $core_button_styles['border']['width'] ) ) {
54 $element_css_styles .= '--wp--custom--core-button--border--width: ' . $core_button_styles['border']['width'] . ';';
55 }
56
57 if ( isset( $core_button_styles['border']['radius'] ) ) {
58 $top_left = is_array( $core_button_styles['border']['radius'] ) ? $core_button_styles['border']['radius']['topLeft'] : $core_button_styles['border']['radius'];
59 $top_right = is_array( $core_button_styles['border']['radius'] ) ? $core_button_styles['border']['radius']['topRight'] : $core_button_styles['border']['radius'];
60 $bottom_left = is_array( $core_button_styles['border']['radius'] ) ? $core_button_styles['border']['radius']['bottomLeft'] : $core_button_styles['border']['radius'];
61 $bottom_right = is_array( $core_button_styles['border']['radius'] ) ? $core_button_styles['border']['radius']['bottomRight'] : $core_button_styles['border']['radius'];
62 if ( '' !== $top_left ) {
63 $element_css_styles .= '--wp--custom--core-button--border-radius--top-left: ' . $top_left . ';';
64 }
65 if ( '' !== ( $top_right ) ) {
66 $element_css_styles .= '--wp--custom--core-button--border-radius--top-right: ' . $top_right . ';';
67 }
68 if ( '' !== ( $bottom_left ) ) {
69 $element_css_styles .= '--wp--custom--core-button--border-radius--bottom-left: ' . $bottom_left . ';';
70 }
71 if ( '' !== ( $bottom_right ) ) {
72 $element_css_styles .= '--wp--custom--core-button--border-radius--bottom-right: ' . $bottom_right . ';';
73 }
74 }
75
76 if ( isset( $core_button_styles['typography']['fontSize'] ) ) {
77 $element_css_styles .= '--wp--custom--core-button--typography--font-size: ' . $core_button_styles['typography']['fontSize'] . ';';
78 }
79
80 if ( isset( $core_button_styles['typography']['fontWeight'] ) ) {
81 $element_css_styles .= '--wp--custom--core-button--typography--font-weight: ' . $core_button_styles['typography']['fontWeight'] . ';';
82 }
83
84 if ( ! empty( $element_css_styles ) ) {
85 $css_styles .= 'body{' . $element_css_styles . '}';
86 }
87
88 set_transient( $transient_name, $css_styles, MINUTE_IN_SECONDS );
89 wp_add_inline_style( 'global-styles', $css_styles );
90
91 }
92 add_action( 'wp_enqueue_scripts', 'gutenify_global_styles_vars', 200 );
93