PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / trunk
Gutenify – Visual Site Builder Blocks & Starter Templates vtrunk
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 1.1.5 1.1.6 All 72 releases
gutenify / core / dist / blocks / button / index.php

index.php in Gutenify – Visual Site Builder Blocks & Starter Templates trunk, at core/dist/blocks/button/index.php

118 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace gutenify;
4
5
6 defined('ABSPATH') || exit;
7
8 class Button{
9 public static function init() {
10 add_action('init', array(__CLASS__, 'register_block'));
11 add_filter('gutenify_render_block_gutenify/button', array(__CLASS__, 'render_block'), 10, 4);
12 }
13
14 public static function register_block() {
15 register_block_type(__DIR__);
16 }
17
18 public static function render_block($block_content, $block, $instance, $block_id){
19
20 $root_selector = '.' . $block_id;
21 $css = '';
22
23 /**
24 * Padding.
25 */
26 if ( ! empty( $block['attrs']['blockAdvanceOptions']['padding'] ) ) {
27 $css .= Dynamic_Styles::get_spacing_with_media( $root_selector . ' .gutenify-button-link.wp-block-button__link', $block['attrs']['blockAdvanceOptions']['padding'], 'padding-' );
28 }
29
30 /**
31 * Margin.
32 */
33 if ( ! empty( $block['attrs']['blockAdvanceOptions']['margin'] ) ) {
34 $css .= Dynamic_Styles::get_spacing_with_media( $root_selector . ' .gutenify-button-link.wp-block-button__link', $block['attrs']['blockAdvanceOptions']['margin'], 'margin-' );
35 }
36
37 $css .= $root_selector . ' .gutenify-button-link.wp-block-button__link{font: inherit;';
38
39 /**
40 * Normal state.
41 */
42 if (!empty($block['attrs']['blockAdvanceOptions']['textColor'])) {
43 $css .= 'color:' . esc_attr( $block['attrs']['blockAdvanceOptions']['textColor'] ) . ';';
44 }
45 if (!empty($block['attrs']['backgroundGradient'])) {
46 $css .= 'background:' . esc_attr( $block['attrs']['backgroundGradient'] ) . ';';
47 }elseif (!empty($block['attrs']['backgroundColor'])) {
48 $css .= 'background:' . esc_attr( $block['attrs']['backgroundColor'] ) . ';';
49 } elseif (!empty($block['attrs']['blockAdvanceOptions']['backgroundGradient'])) {
50 $css .= 'background:' . esc_attr( $block['attrs']['blockAdvanceOptions']['backgroundGradient'] ) . ';';
51 } elseif (!empty($block['attrs']['blockAdvanceOptions']['backgroundColor'])) {
52 $css .= 'background:' . esc_attr( $block['attrs']['blockAdvanceOptions']['backgroundColor'] ) . ';';
53 } else {
54 $css .= '';
55 }
56
57 // Border.
58 if (!empty($block['attrs']['blockAdvanceOptions']['borderColor'])) {
59 $css .= 'border-color:' . esc_attr( $block['attrs']['blockAdvanceOptions']['borderColor'] ) . ';';
60 }
61 if ( ! empty( $block['attrs']['blockAdvanceOptions']['borderWidth'] ) ) {
62 $css .= 'border-style:solid;';
63 if ( ! is_array( $block['attrs']['blockAdvanceOptions']['borderWidth'] ) ) {
64 $css .= 'border-width: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['borderWidth'] ) . 'px;';
65 } else {
66 $css .= \gutenify\Style_Helpers::box_control( $block['attrs']['blockAdvanceOptions']['borderWidth'], 'border-', '-width');
67 }
68 }
69
70 if ( ! empty( $block['attrs']['blockAdvanceOptions']['borderRadius'] ) ) {
71 $css .= \gutenify\Style_Helpers::border_radius_control( $block['attrs']['blockAdvanceOptions']['borderRadius'] );
72 }
73 // Icon.
74 if (!empty($block['attrs']['icon']['position']) && 'after' === $block['attrs']['icon']['position']) {
75 $css .= 'flex-direction: row-reverse;';
76 }
77 if (!empty($block['attrs']['icon']['spacing'])) {
78 $css .= 'gap: ' . esc_attr( $block['attrs']['icon']['spacing'] ) . 'px;';
79 }
80
81 $css .= '}';
82
83 /**
84 * Hover state.
85 */
86 $css .= $root_selector . ' .wp-block-button__link:hover{ ';
87 if (!empty($block['attrs']['blockAdvanceOptions']['hoverTextColor'])) {
88 $css .= 'color:' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverTextColor'] ) . ';';
89 }
90
91
92 if (!empty($block['attrs']['hoverBackgroundGradient'])) {
93 $css .= 'background:' . esc_attr( $block['attrs']['hoverBackgroundGradient'] ) . ';';
94 } elseif (!empty($block['attrs']['hoverBackgroundColor'])) {
95 $css .= 'background:' . esc_attr( $block['attrs']['hoverBackgroundColor'] ) . ';';
96 }elseif (!empty($block['attrs']['blockAdvanceOptions']['hoverBackgroundGradient'])) {
97 $css .= 'background:' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverBackgroundGradient'] ) . ';';
98 } elseif (!empty($block['attrs']['blockAdvanceOptions']['hoverBackgroundColor'])) {
99 $css .= 'background:' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverBackgroundColor'] ) . ';';
100 } else {
101 $css .= '';
102 }
103
104 // Border.
105 if (!empty($block['attrs']['blockAdvanceOptions']['hoverBorderColor'])) {
106 $css .= 'border-color:' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverBorderColor'] ) . ';';
107 }
108 $css .= '}';
109
110 $handle = 'gutenify_'. str_replace( '/', '_', $block['blockName'] ) . '_' . $block_id;
111 wp_add_inline_style( $handle, $css);
112 return $block_content;
113 }
114 }
115
116 Button::init();
117
118