PluginProbe
Getwid – Gutenberg Blocks / 2.0.10
Getwid – Gutenberg Blocks v2.0.10
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
getwid / includes / blocks / template-parts / acf / select.php

select.php in Getwid – Gutenberg Blocks 2.0.10, at includes/blocks/template-parts/acf/select.php

162 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Getwid\Blocks;
4
5 class AcfSelect extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-acf-select';
8 protected static $assetsHandle = 'getwid/template-parts/acf';
9
10 public function __construct() {
11
12 parent::__construct( self::$blockName );
13
14 register_block_type(
15 self::$blockName,
16 array(
17 'attributes' => array(
18 'customField' => array(
19 'type' => 'string'
20 ),
21 'labelName' => array(
22 'type' => 'string'
23 ),
24 'separator' => array(
25 'type' => 'string',
26 'default' => ','
27 ),
28
29 // Colors
30 'textColor' => array(
31 'type' => 'string'
32 ),
33 'customTextColor' => array(
34 'type' => 'string'
35 ),
36
37 // Font
38 'fontSize' => array(
39 'type' => 'string'
40 ),
41 'customFontSize' => array(
42 'type' => 'string'
43 ),
44 'bold' => array(
45 'type' => 'boolean',
46 'default' => false
47 ),
48 'italic' => array(
49 'type' => 'boolean',
50 'default' => false
51 ),
52 'textAlignment' => array(
53 'type' => 'string'
54 ),
55
56 'className' => array(
57 'type' => 'string'
58 ),
59 ),
60 'render_callback' => [$this, 'render_callback']
61 )
62 );
63 }
64
65 public function block_frontend_assets() {
66
67 if ( is_admin() ) {
68 return;
69 }
70
71 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
72 return;
73 }
74
75 add_filter( 'getwid/optimize/assets',
76 function ( $assets ) {
77 $assets[] = self::$assetsHandle;
78
79 return $assets;
80 }
81 );
82
83 $rtl = is_rtl() ? '.rtl' : '';
84
85 wp_enqueue_style(
86 self::$assetsHandle,
87 getwid_get_plugin_url( 'assets/blocks/template-parts/acf/style' . $rtl . '.css' ),
88 [],
89 getwid()->settings()->getVersion()
90 );
91 }
92
93 public function render_callback( $attributes, $content ) {
94
95 //Not BackEnd render if we view from template page
96 if ( (get_post_type() == getwid()->postTemplatePart()->postType) || (get_post_type() == 'revision') ) {
97 return $content;
98 }
99
100 $block_name = 'wp-block-getwid-template-acf-select';
101 $wrapper_class = $block_name;
102
103 if ( isset( $attributes['className'] ) ) {
104 $wrapper_class .= ' ' . esc_attr( $attributes['className'] );
105 }
106
107 if ( isset( $attributes['customField'] ) ) {
108 $wrapper_class .= ' ' . 'custom-field-' . esc_attr( $attributes['customField'] );
109 }
110
111 $wrapper_style = '';
112
113 // Font
114 if ( isset( $attributes['textAlignment'] ) ) {
115 $wrapper_style .= 'text-align: ' . esc_attr( $attributes['textAlignment'] ) . ';';
116 }
117
118 if ( isset( $attributes['bold'] ) && $attributes['bold'] ) {
119 $wrapper_style .= 'font-weight: bold;';
120 }
121
122 if ( isset( $attributes['italic'] ) && $attributes['italic'] ) {
123 $wrapper_style .= 'font-style: italic;';
124 }
125
126 // Link style & class
127 if ( isset( $attributes['customFontSize'] ) ) {
128 $font_size = is_numeric( $attributes['customFontSize'] ) ? $attributes['customFontSize'] . 'px' : $attributes['customFontSize'];
129 $wrapper_style .= 'font-size: ' . esc_attr( $font_size ) . ';';
130 }
131
132 if ( isset( $attributes['fontSize'] ) ) {
133 $wrapper_class .= ' has-' . esc_attr( $attributes['fontSize'] ) . '-font-size';
134 }
135
136 $is_back_end = getwid_is_block_editor();
137
138 getwid_custom_color_style_and_class( $wrapper_style, $wrapper_class, $attributes, 'color', $is_back_end );
139
140 $result = '';
141
142 $extra_attr = array(
143 'wrapper_class' => $wrapper_class,
144 'wrapper_style' => $wrapper_style,
145 );
146
147 if ( getwid_acf_is_active() && isset( $attributes['customField'] ) ) {
148 ob_start();
149
150 getwid_get_template_part( 'template-parts/acf/select', $attributes, false, $extra_attr );
151
152 $result = ob_get_clean();
153 }
154
155 $this->block_frontend_assets();
156
157 return $result;
158 }
159 }
160
161 new \Getwid\Blocks\AcfSelect();
162