PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.0.1
GenerateBlocks v1.0.1
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / includes / generate-css.php
generateblocks / includes Last commit date
class-do-css.php 6 years ago class-enqueue-css.php 6 years ago class-settings.php 6 years ago dashboard.php 6 years ago defaults.php 6 years ago functions.php 6 years ago general.php 6 years ago generate-css.php 6 years ago
generate-css.php
1342 lines
1 <?php
2 /**
3 * Output our dynamic CSS.
4 *
5 * @package GenerateBlocks
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Build the CSS from our block attributes.
14 *
15 * @since 0.1
16 * @param string $content The content we're looking through.
17 *
18 * @return string The dynamic CSS.
19 */
20 function generateblocks_get_dynamic_css( $content = '' ) {
21 if ( ! $content ) {
22 return;
23 }
24
25 $data = generateblocks_get_block_data( $content );
26
27 if ( empty( $data ) ) {
28 return;
29 }
30
31 $blocks_exist = false;
32 $icon_css_added = false;
33 $main_css_data = array();
34 $tablet_css_data = array();
35 $mobile_css_data = array();
36
37 foreach ( $data as $name => $blockData ) {
38 /**
39 * Get our Grid block CSS.
40 *
41 * @since 0.1
42 */
43 if ( 'grid' === $name ) {
44 if ( empty( $blockData ) ) {
45 continue;
46 }
47
48 $blocks_exist = true;
49
50 $css = new GenerateBlocks_Dynamic_CSS();
51 $tablet_css = new GenerateBlocks_Dynamic_CSS();
52 $mobile_css = new GenerateBlocks_Dynamic_CSS();
53
54 $css->set_selector( '.gb-grid-wrapper' );
55 $css->add_property( 'display', '-webkit-box' );
56 $css->add_property( 'display', '-ms-flexbox' );
57 $css->add_property( 'display', 'flex' );
58 $css->add_property( '-ms-flex-wrap', 'wrap' );
59 $css->add_property( 'flex-wrap', 'wrap' );
60
61 $css->set_selector( '.gb-grid-wrapper > .gb-grid-column > .gb-container' );
62 $css->add_property( 'display', '-webkit-box' );
63 $css->add_property( 'display', '-ms-flexbox' );
64 $css->add_property( 'display', 'flex' );
65 $css->add_property( '-ms-flex-direction', 'column' );
66 $css->add_property( 'flex-direction', 'column' );
67 $css->add_property( 'height', '100%' );
68
69 $css->set_selector( '.gb-grid-column' );
70 $css->add_property( 'box-sizing', 'border-box' );
71
72 $css->set_selector( '.gb-grid-wrapper .wp-block-image' );
73 $css->add_property( 'margin-bottom', '0px' );
74
75 foreach ( $blockData as $atts ) {
76 if ( ! isset( $atts['uniqueId'] ) ) {
77 continue;
78 }
79
80 $defaults = generateblocks_get_block_defaults();
81
82 $settings = wp_parse_args(
83 $atts,
84 $defaults['gridContainer']
85 );
86
87 $id = $atts['uniqueId'];
88
89 $css->set_selector( '.gb-grid-wrapper-' . $id );
90 $css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignment'] ) );
91 $css->add_property( 'align-items', $settings['verticalAlignment'] );
92 $css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['horizontalAlignment'] ) );
93 $css->add_property( 'justify-content', $settings['horizontalAlignment'] );
94
95 if ( $settings['horizontalGap'] ) {
96 $css->add_property( 'margin-left', '-' . $settings['horizontalGap'] . 'px' );
97 }
98
99 $css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' );
100 $css->add_property( 'padding-left', $settings['horizontalGap'], 'px' );
101 $css->add_property( 'padding-bottom', $settings['verticalGap'], 'px' );
102
103 $tablet_css->set_selector( '.gb-grid-wrapper-' . $id );
104
105 if ( 'inherit' !== $settings['verticalAlignmentTablet'] ) {
106 $tablet_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentTablet'] ) );
107 $tablet_css->add_property( 'align-items', $settings['verticalAlignmentTablet'] );
108 }
109
110 if ( 'inherit' !== $settings['horizontalAlignmentTablet'] ) {
111 $tablet_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['horizontalAlignmentTablet'] ) );
112 $tablet_css->add_property( 'justify-content', $settings['horizontalAlignmentTablet'] );
113 }
114
115 if ( $settings['horizontalGapTablet'] ) {
116 $tablet_css->add_property( 'margin-left', '-' . $settings['horizontalGapTablet'] . 'px' );
117 } elseif ( 0 === $settings['horizontalGapTablet'] ) {
118 $tablet_css->add_property( 'margin-left', $settings['horizontalGapTablet'] );
119 }
120
121 $tablet_css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' );
122 $tablet_css->add_property( 'padding-left', $settings['horizontalGapTablet'], 'px' );
123 $tablet_css->add_property( 'padding-bottom', $settings['verticalGapTablet'], 'px' );
124
125 $mobile_css->set_selector( '.gb-grid-wrapper-' . $id );
126
127 if ( 'inherit' !== $settings['verticalAlignmentMobile'] ) {
128 $mobile_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentMobile'] ) );
129 $mobile_css->add_property( 'align-items', $settings['verticalAlignmentMobile'] );
130 }
131
132 if ( 'inherit' !== $settings['horizontalAlignmentMobile'] ) {
133 $mobile_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['horizontalAlignmentMobile'] ) );
134 $mobile_css->add_property( 'justify-content', $settings['horizontalAlignmentMobile'] );
135 }
136
137 if ( $settings['horizontalGapMobile'] ) {
138 $mobile_css->add_property( 'margin-left', '-' . $settings['horizontalGapMobile'] . 'px' );
139 } elseif ( 0 === $settings['horizontalGapMobile'] ) {
140 $mobile_css->add_property( 'margin-left', $settings['horizontalGapMobile'] );
141 }
142
143 $mobile_css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' );
144 $mobile_css->add_property( 'padding-left', $settings['horizontalGapMobile'], 'px' );
145 $mobile_css->add_property( 'padding-bottom', $settings['verticalGapMobile'], 'px' );
146
147 /**
148 * Do generateblocks_block_css_data hook
149 *
150 * @since 1.0
151 *
152 * @param object $css Our desktop/main CSS data.
153 * @param object $tablet_css Our tablet CSS data.
154 * @param object $mobile_css Our mobile CSS data.
155 * @param string $name The name of our block.
156 * @param array $settings The settings for the current block.
157 */
158 do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings );
159 }
160
161 if ( $css->css_output() ) {
162 $main_css_data[] = $css->css_output();
163 }
164
165 if ( $tablet_css->css_output() ) {
166 $tablet_css_data[] = $tablet_css->css_output();
167 }
168
169 if ( $mobile_css->css_output() ) {
170 $mobile_css_data[] = $mobile_css->css_output();
171 }
172 }
173
174 /**
175 * Get our Container block CSS.
176 *
177 * @since 0.1
178 */
179 if ( 'container' === $name ) {
180 if ( empty( $blockData ) ) {
181 continue;
182 }
183
184 $blocks_exist = true;
185
186 $css = new GenerateBlocks_Dynamic_CSS();
187 $tablet_css = new GenerateBlocks_Dynamic_CSS();
188 $mobile_css = new GenerateBlocks_Dynamic_CSS();
189
190 $css->set_selector( '.gb-container .wp-block-image img' );
191 $css->add_property( 'vertical-align', 'middle' );
192
193 foreach ( $blockData as $atts ) {
194 if ( ! isset( $atts['uniqueId'] ) ) {
195 continue;
196 }
197
198 $defaults = generateblocks_get_block_defaults();
199
200 $settings = wp_parse_args(
201 $atts,
202 $defaults['container']
203 );
204
205 $id = $atts['uniqueId'];
206
207 $grid_atts = array();
208
209 if ( isset( $atts['gridId'] ) && $atts['gridId'] ) {
210 foreach ( $data['grid'] as $grid ) {
211 if ( $atts['gridId'] === $grid['uniqueId'] ) {
212 $grid_atts = $grid;
213 break;
214 }
215 }
216 }
217
218 $grid_settings = wp_parse_args(
219 $grid_atts,
220 $defaults['gridContainer']
221 );
222
223 $fontFamily = $settings['fontFamily'];
224
225 if ( $fontFamily && $settings['fontFamilyFallback'] ) {
226 $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback'];
227 }
228
229 $css->set_selector( '.gb-container.gb-container-' . $id );
230 $css->add_property( 'font-family', $fontFamily );
231 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
232 $css->add_property( 'font-weight', $settings['fontWeight'] );
233 $css->add_property( 'text-transform', $settings['textTransform'] );
234 $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) );
235
236 if ( 'contained' === $settings['outerContainer'] && ! $settings['isGrid'] ) {
237 $css->add_property( 'max-width', absint( $settings['containerWidth'] ), 'px' );
238 $css->add_property( 'margin-left', 'auto' );
239 $css->add_property( 'margin-right', 'auto' );
240 }
241
242 $settings['backgroundColor'] = generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] );
243
244 $css->add_property( 'background-color', $settings['backgroundColor'] );
245 $css->add_property( 'color', $settings['textColor'] );
246
247 $gradientColorStopOneValue = '';
248 $gradientColorStopTwoValue = '';
249
250 $settings['gradientColorOne'] = generateblocks_hex2rgba( $settings['gradientColorOne'], $settings['gradientColorOneOpacity'] );
251 $settings['gradientColorTwo'] = generateblocks_hex2rgba( $settings['gradientColorTwo'], $settings['gradientColorTwoOpacity'] );
252
253 if ( $settings['gradient'] ) {
254 if ( $settings['gradientColorOne'] && '' !== $settings['gradientColorStopOne'] ) {
255 $gradientColorStopOneValue = ' ' . $settings['gradientColorStopOne'] . '%';
256 }
257
258 if ( $settings['gradientColorTwo'] && '' !== $settings['gradientColorStopTwo'] ) {
259 $gradientColorStopTwoValue = ' ' . $settings['gradientColorStopTwo'] . '%';
260 }
261 }
262
263 if ( $settings['bgImage'] ) {
264 $url = $settings['bgImage']['image']['url'];
265
266 if ( ( $settings['backgroundColor'] || $settings['gradient'] ) && isset( $settings['bgOptions']['overlay'] ) && $settings['bgOptions']['overlay'] ) {
267 if ( $settings['gradient'] ) {
268 $css->add_property( 'background-image', 'linear-gradient(' . $settings['gradientDirection'] . 'deg, ' . $settings['gradientColorOne'] . $gradientColorStopOneValue . ', ' . $settings['gradientColorTwo'] . $gradientColorStopTwoValue . '), url(' . esc_url( $url ) . ')' );
269 } elseif ( $settings['backgroundColor'] ) {
270 $css->add_property( 'background-image', 'linear-gradient(0deg, ' . $settings['backgroundColor'] . ', ' . $settings['backgroundColor'] . '), url(' . esc_url( $url ) . ')' );
271 }
272 } else {
273 $css->add_property( 'background-image', 'url(' . esc_url( $url ) . ')' );
274 }
275
276 $css->add_property( 'background-repeat', $settings['bgOptions']['repeat'] );
277 $css->add_property( 'background-position', $settings['bgOptions']['position'] );
278 $css->add_property( 'background-size', $settings['bgOptions']['size'] );
279 $css->add_property( 'background-attachment', $settings['bgOptions']['attachment'] );
280 } elseif ( $settings['gradient'] ) {
281 $css->add_property( 'background-image', 'linear-gradient(' . $settings['gradientDirection'] . 'deg, ' . $settings['gradientColorOne'] . $gradientColorStopOneValue . ', ' . $settings['gradientColorTwo'] . $gradientColorStopTwoValue . ')' );
282 }
283
284 if ( $settings['zindex'] ) {
285 $css->add_property( 'position', 'relative' );
286 $css->add_property( 'z-index', $settings['zindex'] );
287 }
288
289 $css->add_property( 'border-radius', generateblocks_get_shorthand_css( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'], $settings['borderRadiusUnit'] ) );
290 $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) );
291
292 if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) {
293 $css->add_property( 'border-style', 'solid' );
294 }
295
296 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
297 $css->add_property( 'min-height', $settings['minHeight'], $settings['minHeightUnit'] );
298
299 // Set flags so we don't duplicate this CSS in media queries.
300 $usingMinHeightFlex = false;
301 $usingMinHeightInnerWidth = false;
302
303 if ( $settings['minHeight'] && $settings['verticalAlignment'] && ! $settings['isGrid'] ) {
304 $css->add_property( 'display', '-webkit-box' );
305 $css->add_property( 'display', '-ms-flexbox' );
306 $css->add_property( 'display', 'flex' );
307 $css->add_property( '-ms-flex-direction', 'row' );
308 $css->add_property( 'flex-direction', 'row' );
309 $css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignment'] ) );
310 $css->add_property( 'align-items', $settings['verticalAlignment'] );
311
312 $usingMinHeightFlex = true;
313 }
314
315 $css->add_property( 'text-align', $settings['alignment'] );
316
317 $css->set_selector( '.gb-container.gb-container-' . $id . ' > .gb-inside-container' );
318 $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) );
319
320 if ( 'contained' === $settings['innerContainer'] && ! $settings['isGrid'] ) {
321 $css->add_property( 'max-width', absint( $settings['containerWidth'] ), 'px' );
322 $css->add_property( 'margin-left', 'auto' );
323 $css->add_property( 'margin-right', 'auto' );
324 }
325
326 if ( $usingMinHeightFlex ) {
327 $css->add_property( 'width', '100%' );
328
329 $usingMinHeightInnerWidth = true;
330 }
331
332 $css->set_selector( '.gb-container.gb-container-' . $id . ' a, .gb-container.gb-container-' . $id . ' a:visited' );
333 $css->add_property( 'color', $settings['linkColor'] );
334
335 $css->set_selector( '.gb-container.gb-container-' . $id . ' a:hover' );
336 $css->add_property( 'color', $settings['linkColorHover'] );
337
338 if ( $settings['isGrid'] ) {
339 $css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id );
340 $css->add_property( 'width', $settings['width'], '%' );
341 }
342
343 if ( $settings['removeVerticalGap'] ) {
344 $css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
345 $css->add_property( 'padding-bottom', '0' );
346 }
347
348 $css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' );
349 $css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['verticalAlignment'] ) );
350 $css->add_property( 'justify-content', $settings['verticalAlignment'] );
351
352 $tablet_css->set_selector( '.gb-container.gb-container-' . $id );
353 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
354 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
355 $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] );
356 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
357
358 if ( $settings['borderSizeTopTablet'] || $settings['borderSizeRightTablet'] || $settings['borderSizeBottomTablet'] || $settings['borderSizeLeftTablet'] ) {
359 $tablet_css->add_property( 'border-style', 'solid' );
360 }
361
362 $tablet_css->add_property( 'min-height', $settings['minHeightTablet'], $settings['minHeightUnitTablet'] );
363
364 if ( ! $settings['isGrid'] ) {
365 if ( ! $usingMinHeightFlex && $settings['minHeightTablet'] && 'inherit' !== $settings['verticalAlignmentTablet'] ) {
366 $tablet_css->add_property( 'display', '-webkit-box' );
367 $tablet_css->add_property( 'display', '-ms-flexbox' );
368 $tablet_css->add_property( 'display', 'flex' );
369 $tablet_css->add_property( '-ms-flex-direction', 'row' );
370 $tablet_css->add_property( 'flex-direction', 'row' );
371
372 $usingMinHeightFlex = true;
373 }
374
375 if ( $usingMinHeightFlex && 'inherit' !== $settings['verticalAlignmentTablet'] ) {
376 $tablet_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentTablet'] ) );
377 $tablet_css->add_property( 'align-items', $settings['verticalAlignmentTablet'] );
378 }
379 }
380
381 $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] );
382
383 $tablet_css->set_selector( '.gb-container.gb-container-' . $id . ' > .gb-inside-container' );
384 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
385
386 if ( ! $settings['isGrid'] ) {
387 // Needs 100% width if it's a flex item.
388 if ( ! $usingMinHeightInnerWidth && $settings['minHeightTablet'] && 'inherit' !== $settings['verticalAlignmentTablet'] ) {
389 $tablet_css->add_property( 'width', '100%' );
390
391 $usingMinHeightInnerWidth = true;
392 }
393 }
394
395 $tablet_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id );
396 $tablet_css->add_property( 'width', $settings['widthTablet'], '%' );
397
398 if ( $settings['isGrid'] ) {
399 $tablet_css->add_property( '-ms-flex-order', $settings['orderTablet'] );
400 $tablet_css->add_property( 'order', $settings['orderTablet'] );
401 }
402
403 if ( $settings['removeVerticalGapTablet'] ) {
404 if ( ! $settings['removeVerticalGap'] ) {
405 $tablet_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
406 $tablet_css->add_property( 'padding-bottom', '0' );
407 }
408 } elseif ( $settings['removeVerticalGap'] ) {
409 // Removed vertical gap on desktop, so we need to add it back here.
410 $vertical_gap_added = false;
411
412 if ( ! empty( $grid_settings ) ) {
413 $tablet_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
414
415 if ( isset( $grid_settings['verticalGapTablet'] ) || isset( $grid_settings['verticalGap'] ) ) {
416 if ( ! empty( $grid_settings['verticalGapTablet'] ) ) {
417 $tablet_css->add_property( 'padding-bottom', $grid_settings['verticalGapTablet'], 'px' );
418 $vertical_gap_added = true;
419 } elseif ( ! empty( $grid_settings['verticalGap'] ) ) {
420 $tablet_css->add_property( 'padding-bottom', $grid_settings['verticalGap'], 'px' );
421 $vertical_gap_added = true;
422 }
423 }
424 }
425 }
426
427 $tablet_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' );
428
429 if ( 'inherit' !== $settings['verticalAlignmentTablet'] ) {
430 $tablet_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['verticalAlignmentTablet'] ) );
431 $tablet_css->add_property( 'justify-content', $settings['verticalAlignmentTablet'] );
432 }
433
434 $mobile_css->set_selector( '.gb-container.gb-container-' . $id );
435 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
436 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
437 $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftMobile'], $settings['borderRadiusTopRightMobile'], $settings['borderRadiusBottomRightMobile'], $settings['borderRadiusBottomLeftMobile'] ), $settings['borderRadiusUnit'] );
438 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
439
440 if ( $settings['borderSizeTopMobile'] || $settings['borderSizeRightMobile'] || $settings['borderSizeBottomMobile'] || $settings['borderSizeLeftMobile'] ) {
441 $mobile_css->add_property( 'border-style', 'solid' );
442 }
443
444 $mobile_css->add_property( 'min-height', $settings['minHeightMobile'], $settings['minHeightUnitMobile'] );
445
446 if ( ! $settings['isGrid'] ) {
447 if ( ! $usingMinHeightFlex && $settings['minHeightMobile'] && 'inherit' !== $settings['verticalAlignmentMobile'] ) {
448 $mobile_css->add_property( 'display', '-webkit-box' );
449 $mobile_css->add_property( 'display', '-ms-flexbox' );
450 $mobile_css->add_property( 'display', 'flex' );
451 $mobile_css->add_property( '-ms-flex-direction', 'row' );
452 $mobile_css->add_property( 'flex-direction', 'row' );
453
454 $usingMinHeightFlex = true;
455 }
456
457 if ( $usingMinHeightFlex && 'inherit' !== $settings['verticalAlignmentMobile'] ) {
458 $mobile_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentMobile'] ) );
459 $mobile_css->add_property( 'align-items', $settings['verticalAlignmentMobile'] );
460 }
461 }
462
463 $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] );
464
465 $mobile_css->set_selector( '.gb-container.gb-container-' . $id . ' > .gb-inside-container' );
466 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
467
468 if ( ! $settings['isGrid'] ) {
469 // Needs 100% width if it's a flex item.
470 if ( ! $usingMinHeightInnerWidth && $settings['minHeightMobile'] && 'inherit' !== $settings['verticalAlignmentMobile'] ) {
471 $tablet_css->add_property( 'width', '100%' );
472 }
473 }
474
475 $mobile_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id );
476
477 if ( 100 !== $settings['widthMobile'] ) {
478 $mobile_css->add_property( 'width', $settings['widthMobile'], '%' );
479 }
480
481 if ( $settings['isGrid'] ) {
482 $mobile_css->add_property( '-ms-flex-order', $settings['orderMobile'] );
483 $mobile_css->add_property( 'order', $settings['orderMobile'] );
484 }
485
486 if ( $settings['removeVerticalGapMobile'] ) {
487 if ( ! $settings['removeVerticalGapTablet'] ) {
488 $mobile_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
489 $mobile_css->add_property( 'padding-bottom', '0' );
490 }
491 } elseif ( $settings['removeVerticalGapTablet'] || $settings['removeVerticalGap'] ) {
492 // Removed vertical gap on tablet or desktop, so we need to add it back here.
493 if ( ! empty( $grid_settings ) ) {
494 $mobile_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
495
496 if ( empty( $vertical_gap_added ) && ( isset( $grid_settings['verticalGapMobile'] ) || isset( $grid_settings['verticalGapTablet'] ) || isset( $grid_settings['verticalGap'] ) ) ) {
497 if ( ! empty( $grid_settings['verticalGapMobile'] ) ) {
498 $mobile_css->add_property( 'padding-bottom', $grid_settings['verticalGapMobile'], 'px' );
499 } elseif ( ! empty( $grid_settings['verticalGapTablet'] ) ) {
500 $mobile_css->add_property( 'padding-bottom', $grid_settings['verticalGapTablet'], 'px' );
501 } elseif ( ! empty( $grid_settings['verticalGap'] ) ) {
502 $mobile_css->add_property( 'padding-bottom', $grid_settings['verticalGap'], 'px' );
503 }
504 }
505
506 $vertical_gap_added = false;
507 }
508 }
509
510 $mobile_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' );
511
512 if ( 'inherit' !== $settings['verticalAlignmentMobile'] ) {
513 $mobile_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['verticalAlignmentMobile'] ) );
514 $mobile_css->add_property( 'justify-content', $settings['verticalAlignmentMobile'] );
515 }
516
517 /**
518 * Do generateblocks_block_css_data hook
519 *
520 * @since 1.0
521 *
522 * @param object $css Our desktop/main CSS data.
523 * @param object $tablet_css Our tablet CSS data.
524 * @param object $mobile_css Our mobile CSS data.
525 * @param string $name The name of our block.
526 * @param array $settings The settings for the current block.
527 */
528 do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings );
529 }
530
531 if ( $css->css_output() ) {
532 $main_css_data[] = $css->css_output();
533 }
534
535 if ( $tablet_css->css_output() ) {
536 $tablet_css_data[] = $tablet_css->css_output();
537 }
538
539 if ( $mobile_css->css_output() ) {
540 $mobile_css_data[] = $mobile_css->css_output();
541 }
542 }
543
544 /**
545 * Get our Button Container block CSS.
546 *
547 * @since 0.1
548 */
549 if ( 'button-container' === $name ) {
550 if ( empty( $blockData ) ) {
551 continue;
552 }
553
554 $blocks_exist = true;
555
556 $css = new GenerateBlocks_Dynamic_CSS();
557 $tablet_css = new GenerateBlocks_Dynamic_CSS();
558 $mobile_css = new GenerateBlocks_Dynamic_CSS();
559
560 $css->set_selector( '.gb-button-wrapper' );
561 $css->add_property( 'display', 'flex' );
562 $css->add_property( 'flex-wrap', 'wrap' );
563 $css->add_property( 'align-items', 'flex-start' );
564 $css->add_property( 'justify-content', 'flex-start' );
565 $css->add_property( 'clear', 'both' );
566
567 foreach ( $blockData as $atts ) {
568 if ( ! isset( $atts['uniqueId'] ) ) {
569 continue;
570 }
571
572 $defaults = generateblocks_get_block_defaults();
573
574 $settings = wp_parse_args(
575 $atts,
576 $defaults['buttonContainer']
577 );
578
579 $id = $atts['uniqueId'];
580
581 $css->set_selector( '.gb-button-wrapper-' . $id );
582 $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) );
583 $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
584
585 if ( $settings['stack'] ) {
586 $css->add_property( '-ms-flex-direction', 'column' );
587 $css->add_property( 'flex-direction', 'column' );
588 $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
589 }
590
591 if ( $settings['fillHorizontalSpace'] ) {
592 $css->set_selector( '.gb-button-wrapper-' . $id . ' > a' );
593 $css->add_property( '-webkit-box-flex', '1' );
594 $css->add_property( '-ms-flex', '1' );
595 $css->add_property( 'flex', '1' );
596 }
597
598 if ( $settings['stack'] && $settings['fillHorizontalSpace'] ) {
599 $css->add_property( 'width', '100%' );
600 $css->add_property( 'box-sizing', 'border-box' );
601 }
602
603 $tablet_css->set_selector( '.gb-button-wrapper-' . $id );
604 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
605 $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
606
607 if ( $settings['stackTablet'] ) {
608 $tablet_css->add_property( '-ms-flex-direction', 'column' );
609 $tablet_css->add_property( 'flex-direction', 'column' );
610 $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
611 }
612
613 if ( $settings['fillHorizontalSpaceTablet'] ) {
614 $tablet_css->set_selector( '.gb-button-wrapper-' . $id . ' > a' );
615 $tablet_css->add_property( '-webkit-box-flex', '1' );
616 $tablet_css->add_property( '-ms-flex', '1' );
617 $tablet_css->add_property( 'flex', '1' );
618 }
619
620 if ( $settings['stackTablet'] && $settings['fillHorizontalSpaceTablet'] ) {
621 $tablet_css->add_property( 'width', '100%' );
622 $tablet_css->add_property( 'box-sizing', 'border-box' );
623 }
624
625 $mobile_css->set_selector( '.gb-button-wrapper-' . $id );
626 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
627 $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
628
629 if ( $settings['stackMobile'] ) {
630 $mobile_css->add_property( '-ms-flex-direction', 'column' );
631 $mobile_css->add_property( 'flex-direction', 'column' );
632 $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
633 }
634
635 if ( $settings['fillHorizontalSpaceMobile'] ) {
636 $mobile_css->set_selector( '.gb-button-wrapper-' . $id . ' > a' );
637 $mobile_css->add_property( '-webkit-box-flex', '1' );
638 $mobile_css->add_property( '-ms-flex', '1' );
639 $mobile_css->add_property( 'flex', '1' );
640 }
641
642 if ( $settings['stackMobile'] && $settings['fillHorizontalSpaceMobile'] ) {
643 $mobile_css->add_property( 'width', '100%' );
644 $mobile_css->add_property( 'box-sizing', 'border-box' );
645 }
646
647 /**
648 * Do generateblocks_block_css_data hook
649 *
650 * @since 1.0
651 *
652 * @param object $css Our desktop/main CSS data.
653 * @param object $tablet_css Our tablet CSS data.
654 * @param object $mobile_css Our mobile CSS data.
655 * @param string $name The name of our block.
656 * @param array $settings The settings for the current block.
657 */
658 do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings );
659 }
660
661 if ( $css->css_output() ) {
662 $main_css_data[] = $css->css_output();
663 }
664
665 if ( $tablet_css->css_output() ) {
666 $tablet_css_data[] = $tablet_css->css_output();
667 }
668
669 if ( $mobile_css->css_output() ) {
670 $mobile_css_data[] = $mobile_css->css_output();
671 }
672 }
673
674 /**
675 * Get our Button block CSS.
676 *
677 * @since 0.1
678 */
679 if ( 'button' === $name ) {
680 if ( empty( $blockData ) ) {
681 continue;
682 }
683
684 $blocks_exist = true;
685
686 $css = new GenerateBlocks_Dynamic_CSS();
687 $tablet_css = new GenerateBlocks_Dynamic_CSS();
688 $mobile_css = new GenerateBlocks_Dynamic_CSS();
689
690 if ( ! $icon_css_added ) {
691 $css->set_selector( '.gb-icon' );
692 $css->add_property( 'display', '-webkit-inline-box' );
693 $css->add_property( 'display', '-ms-inline-flexbox' );
694 $css->add_property( 'display', 'inline-flex' );
695 $css->add_property( 'line-height', '0' );
696
697 $css->set_selector( '.gb-icon svg' );
698 $css->add_property( 'height', '1em' );
699 $css->add_property( 'width', '1em' );
700 $css->add_property( 'fill', 'currentColor' );
701
702 $icon_css_added = true;
703 }
704
705 $css->set_selector( '.gb-button-wrapper a.gb-button' );
706 $css->add_property( 'display', '-webkit-inline-box' );
707 $css->add_property( 'display', '-ms-inline-flexbox' );
708 $css->add_property( 'display', 'inline-flex' );
709 $css->add_property( 'align-items', 'center' );
710 $css->add_property( 'justify-content', 'center' );
711 $css->add_property( 'text-align', 'center' );
712 $css->add_property( 'text-decoration', 'none' );
713 $css->add_property( 'transition', '.2s background-color ease-in-out, .2s color ease-in-out, .2s border-color ease-in-out, .2s opacity ease-in-out, .2s box-shadow ease-in-out' );
714
715 $css->set_selector( '.gb-button-wrapper .gb-button .gb-icon' );
716 $css->add_property( 'align-items', 'center' );
717
718 foreach ( $blockData as $atts ) {
719 if ( ! isset( $atts['uniqueId'] ) ) {
720 continue;
721 }
722
723 $defaults = generateblocks_get_block_defaults();
724
725 $settings = wp_parse_args(
726 $atts,
727 $defaults['button']
728 );
729
730 $id = $atts['uniqueId'];
731
732 // Back-compatibility for when icon held a value.
733 if ( $settings['icon'] ) {
734 $settings['hasIcon'] = true;
735 }
736
737 $fontFamily = $settings['fontFamily'];
738
739 if ( $fontFamily && $settings['fontFamilyFallback'] ) {
740 $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback'];
741 }
742
743 $gradientColorStopOneValue = '';
744 $gradientColorStopTwoValue = '';
745
746 if ( $settings['gradient'] ) {
747 if ( $settings['gradientColorOne'] && '' !== $settings['gradientColorStopOne'] ) {
748 $gradientColorStopOneValue = ' ' . $settings['gradientColorStopOne'] . '%';
749 }
750
751 if ( $settings['gradientColorTwo'] && '' !== $settings['gradientColorStopTwo'] ) {
752 $gradientColorStopTwoValue = ' ' . $settings['gradientColorStopTwo'] . '%';
753 }
754 }
755
756 $css->set_selector( '.gb-button-wrapper a.gb-button-' . $id . ',.gb-button-wrapper a.gb-button-' . $id . ':visited' );
757 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
758 $css->add_property( 'color', $settings['textColor'] );
759
760 if ( $settings['gradient'] ) {
761 $css->add_property( 'background-image', 'linear-gradient(' . $settings['gradientDirection'] . 'deg, ' . generateblocks_hex2rgba( $settings['gradientColorOne'], $settings['gradientColorOneOpacity'] ) . $gradientColorStopOneValue . ', ' . generateblocks_hex2rgba( $settings['gradientColorTwo'], $settings['gradientColorTwoOpacity'] ) . $gradientColorStopTwoValue . ')' );
762 }
763
764 $css->add_property( 'font-family', $fontFamily );
765 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
766 $css->add_property( 'font-weight', $settings['fontWeight'] );
767 $css->add_property( 'text-transform', $settings['textTransform'] );
768 $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' );
769 $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) );
770 $css->add_property( 'border-radius', generateblocks_get_shorthand_css( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'], $settings['borderRadiusUnit'] ) );
771 $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) );
772 $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) );
773
774 if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) {
775 $css->add_property( 'border-style', 'solid' );
776 }
777
778 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
779 $css->add_property( 'text-transform', $settings['textTransform'] );
780
781 if ( $settings['hasIcon'] ) {
782 $css->add_property( 'display', '-webkit-inline-box' );
783 $css->add_property( 'display', '-ms-inline-flexbox' );
784 $css->add_property( 'display', 'inline-flex' );
785 $css->add_property( 'align-items', 'center' );
786 }
787
788 $css->set_selector( '.gb-button-wrapper a.gb-button-' . $id . ':hover,.gb-button-wrapper a.gb-button-' . $id . ':active,.gb-button-wrapper a.gb-button-' . $id . ':focus' );
789 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColorHover'], $settings['backgroundColorHoverOpacity'] ) );
790 $css->add_property( 'color', $settings['textColorHover'] );
791 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColorHover'], $settings['borderColorHoverOpacity'] ) );
792
793 if ( $settings['hasIcon'] ) {
794 $css->set_selector( 'a.gb-button-' . $id . ' .gb-icon' );
795 $css->add_property( 'font-size', $settings['iconSize'], $settings['iconSizeUnit'] );
796
797 if ( ! $settings['removeText'] ) {
798 $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'], $settings['iconPaddingUnit'] ) );
799 }
800 }
801
802 $tablet_css->set_selector( '.gb-button-wrapper a.gb-button-' . $id );
803 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
804 $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' );
805 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
806 $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] );
807 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
808 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
809
810 if ( $settings['hasIcon'] ) {
811 $tablet_css->set_selector( 'a.gb-button-' . $id . ' .gb-icon' );
812 $tablet_css->add_property( 'font-size', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
813
814 if ( ! $settings['removeText'] ) {
815 $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] );
816 }
817 }
818
819 $mobile_css->set_selector( '.gb-button-wrapper a.gb-button-' . $id );
820 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
821 $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' );
822 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
823 $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] );
824 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
825 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
826
827 if ( $settings['hasIcon'] ) {
828 $mobile_css->set_selector( 'a.gb-button-' . $id . ' .gb-icon' );
829 $mobile_css->add_property( 'font-size', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
830
831 if ( ! $settings['removeText'] ) {
832 $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] );
833 }
834 }
835
836 /**
837 * Do generateblocks_block_css_data hook
838 *
839 * @since 1.0
840 *
841 * @param object $css Our desktop/main CSS data.
842 * @param object $tablet_css Our tablet CSS data.
843 * @param object $mobile_css Our mobile CSS data.
844 * @param string $name The name of our block.
845 * @param array $settings The settings for the current block.
846 */
847 do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings );
848 }
849
850 if ( $css->css_output() ) {
851 $main_css_data[] = $css->css_output();
852 }
853
854 if ( $tablet_css->css_output() ) {
855 $tablet_css_data[] = $tablet_css->css_output();
856 }
857
858 if ( $mobile_css->css_output() ) {
859 $mobile_css_data[] = $mobile_css->css_output();
860 }
861 }
862
863 /**
864 * Get our Headline block CSS.
865 *
866 * @since 0.1
867 */
868 if ( 'headline' === $name ) {
869 if ( empty( $blockData ) ) {
870 continue;
871 }
872
873 $blocks_exist = true;
874
875 $css = new GenerateBlocks_Dynamic_CSS();
876 $tablet_css = new GenerateBlocks_Dynamic_CSS();
877 $mobile_css = new GenerateBlocks_Dynamic_CSS();
878
879 if ( ! $icon_css_added ) {
880 $css->set_selector( '.gb-icon' );
881 $css->add_property( 'display', '-webkit-inline-box' );
882 $css->add_property( 'display', '-ms-inline-flexbox' );
883 $css->add_property( 'display', 'inline-flex' );
884 $css->add_property( 'line-height', '0' );
885
886 $css->set_selector( '.gb-icon svg' );
887 $css->add_property( 'height', '1em' );
888 $css->add_property( 'width', '1em' );
889 $css->add_property( 'fill', 'currentColor' );
890
891 $icon_css_added = true;
892 }
893
894 $css->set_selector( '.gb-highlight' );
895 $css->add_property( 'background', 'unset' );
896 $css->add_property( 'color', 'unset' );
897
898 $css->set_selector( '.gb-headline-wrapper' );
899 $css->add_property( 'display', '-ms-flexbox' );
900 $css->add_property( 'display', 'flex' );
901
902 $css->set_selector( '.gb-headline-wrapper > .gb-headline' );
903 $css->add_property( 'margin', '0' );
904 $css->add_property( 'padding', '0' );
905
906 foreach ( $blockData as $atts ) {
907 if ( ! isset( $atts['uniqueId'] ) ) {
908 continue;
909 }
910
911 $defaults = generateblocks_get_block_defaults();
912
913 $settings = wp_parse_args(
914 $atts,
915 $defaults['headline']
916 );
917
918 $id = $atts['uniqueId'];
919
920 // Back-compatibility for when icon held a value.
921 if ( $settings['icon'] ) {
922 $settings['hasIcon'] = true;
923 }
924
925 $fontFamily = $settings['fontFamily'];
926
927 if ( $fontFamily && $settings['fontFamilyFallback'] ) {
928 $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback'];
929 }
930
931 $css->set_selector( '.gb-headline-' . $id );
932 $css->add_property( 'font-family', $fontFamily );
933
934 if ( ! $settings['hasIcon'] ) {
935 $css->add_property( 'text-align', $settings['alignment'] );
936 }
937
938 $css->add_property( 'color', $settings['textColor'] );
939
940 if ( ! $settings['hasIcon'] ) {
941 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
942
943 if ( $settings['inlineWidth'] ) {
944 $css->add_property( 'display', '-webkit-inline-box' );
945 $css->add_property( 'display', '-ms-inline-flexbox' );
946 $css->add_property( 'display', 'inline-flex' );
947 }
948
949 $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) );
950
951 if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) {
952 $css->add_property( 'border-style', 'solid' );
953 }
954
955 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
956 }
957
958 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
959 $css->add_property( 'font-weight', $settings['fontWeight'] );
960 $css->add_property( 'text-transform', $settings['textTransform'] );
961 $css->add_property( 'line-height', $settings['lineHeight'], $settings['lineHeightUnit'] );
962 $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' );
963
964 if ( ! $settings['hasIcon'] ) {
965 $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) );
966 $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) );
967
968 if ( function_exists( 'generate_get_default_fonts' ) && '' === $settings['marginBottom'] ) {
969 $defaultBlockStyles = generateblocks_get_default_styles();
970
971 if ( isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) {
972 $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
973 }
974 }
975 }
976
977 $css->set_selector( '.gb-headline-' . $id . ' a, .gb-headline-' . $id . ' a:visited' );
978 $css->add_property( 'color', $settings['linkColor'] );
979
980 $css->set_selector( '.gb-headline-' . $id . ' a:hover' );
981 $css->add_property( 'color', $settings['linkColorHover'] );
982
983 if ( $settings['hasIcon'] ) {
984 $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
985
986 if ( ! $settings['removeText'] ) {
987 $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'], $settings['iconPaddingUnit'] ) );
988 }
989
990 $css->add_property( 'color', generateblocks_hex2rgba( $settings['iconColor'], $settings['iconColorOpacity'] ) );
991
992 if ( 'above' === $settings['iconLocation'] ) {
993 $css->add_property( 'display', 'unset' );
994 }
995
996 $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
997 $css->add_property( 'width', $settings['iconSize'], $settings['iconSizeUnit'] );
998 $css->add_property( 'height', $settings['iconSize'], $settings['iconSizeUnit'] );
999
1000 $css->set_selector( '.gb-headline-wrapper-' . $id );
1001 $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) );
1002 $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) );
1003
1004 $defaultBlockStyles = generateblocks_get_default_styles();
1005
1006 if ( '' === $settings['marginBottom'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) {
1007 $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
1008 }
1009
1010 if ( '' === $settings['fontSize'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'] ) ) {
1011 $css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
1012 } else {
1013 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
1014 }
1015
1016 if ( 'above' === $settings['iconLocation'] ) {
1017 $css->add_property( 'text-align', $settings['alignment'] );
1018 } else {
1019 $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
1020 }
1021
1022 if ( $settings['inlineWidth'] ) {
1023 $css->add_property( 'display', '-webkit-inline-box' );
1024 $css->add_property( 'display', '-ms-inline-flexbox' );
1025 $css->add_property( 'display', 'inline-flex' );
1026 }
1027
1028 if ( 'inline' === $settings['iconLocation'] ) {
1029 $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignment'] ) );
1030 }
1031
1032 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
1033 $css->add_property( 'color', $settings['textColor'] );
1034 $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) );
1035
1036 if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) {
1037 $css->add_property( 'border-style', 'solid' );
1038 }
1039
1040 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
1041
1042 if ( 'above' === $settings['iconLocation'] ) {
1043 $css->add_property( '-ms-flex-direction', 'column' );
1044 $css->add_property( 'flex-direction', 'column' );
1045 }
1046 }
1047
1048 if ( $settings['highlightTextColor'] ) {
1049 $css->set_selector( '.gb-headline-' . $id . ' .gb-highlight' );
1050 $css->add_property( 'color', $settings['highlightTextColor'] );
1051 }
1052
1053 $tablet_css->set_selector( '.gb-headline-' . $id );
1054 $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] );
1055 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
1056 $tablet_css->add_property( 'line-height', $settings['lineHeightTablet'], $settings['lineHeightUnit'] );
1057 $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' );
1058
1059 if ( ! $settings['hasIcon'] ) {
1060 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
1061 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
1062 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
1063
1064 if ( $settings['inlineWidthTablet'] ) {
1065 $tablet_css->add_property( 'display', '-webkit-inline-box' );
1066 $tablet_css->add_property( 'display', '-ms-inline-flexbox' );
1067 $tablet_css->add_property( 'display', 'inline-flex' );
1068 }
1069 }
1070
1071 if ( $settings['hasIcon'] ) {
1072 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
1073
1074 if ( ! $settings['removeText'] ) {
1075 $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] );
1076 }
1077
1078 if ( 'above' === $settings['iconLocationTablet'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationTablet'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1079 $tablet_css->add_property( '-ms-flex-item-align', generateblocks_get_vendor_prefix( $settings['alignmentTablet'] ) );
1080 $tablet_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
1081 }
1082
1083 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
1084 $tablet_css->add_property( 'width', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
1085 $tablet_css->add_property( 'height', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
1086
1087 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id );
1088 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
1089 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
1090 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
1091 $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
1092
1093 $defaultBlockStyles = generateblocks_get_default_styles();
1094
1095 if ( '' === $settings['marginBottomTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) ) {
1096 $tablet_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
1097 }
1098
1099 if ( '' === $settings['fontSizeTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'] ) ) {
1100 $tablet_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
1101 } else {
1102 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
1103 }
1104
1105 if ( $settings['inlineWidthTablet'] ) {
1106 $tablet_css->add_property( 'display', '-webkit-inline-box' );
1107 $tablet_css->add_property( 'display', '-ms-inline-flexbox' );
1108 $tablet_css->add_property( 'display', 'inline-flex' );
1109 }
1110
1111 if ( 'inline' === $settings['iconLocationTablet'] ) {
1112 $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentTablet'] ) );
1113 }
1114
1115 if ( 'above' === $settings['iconLocationTablet'] ) {
1116 $tablet_css->add_property( '-ms-flex-direction', 'column' );
1117 $tablet_css->add_property( 'flex-direction', 'column' );
1118 }
1119 }
1120
1121 $mobile_css->set_selector( '.gb-headline-' . $id );
1122 $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] );
1123 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
1124 $mobile_css->add_property( 'line-height', $settings['lineHeightMobile'], $settings['lineHeightUnit'] );
1125 $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' );
1126
1127 if ( ! $settings['hasIcon'] ) {
1128 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
1129 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
1130 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
1131
1132 if ( $settings['inlineWidthMobile'] ) {
1133 $mobile_css->add_property( 'display', '-webkit-inline-box' );
1134 $mobile_css->add_property( 'display', '-ms-inline-flexbox' );
1135 $mobile_css->add_property( 'display', 'inline-flex' );
1136 }
1137 }
1138
1139 if ( $settings['hasIcon'] ) {
1140 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
1141
1142 if ( ! $settings['removeText'] ) {
1143 $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] );
1144 }
1145
1146 if ( 'above' === $settings['iconLocationMobile'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationMobile'] ) || ( 'above' === $settings['iconLocationTablet'] && '' == $settings['iconLocationMobile'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1147 $mobile_css->add_property( '-ms-flex-item-align', generateblocks_get_vendor_prefix( $settings['alignmentMobile'] ) );
1148 $mobile_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
1149 }
1150
1151 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
1152 $mobile_css->add_property( 'width', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
1153 $mobile_css->add_property( 'height', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
1154
1155 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id );
1156 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
1157 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
1158 $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
1159
1160 $defaultBlockStyles = generateblocks_get_default_styles();
1161
1162 if ( '' === $settings['marginBottomMobile'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) ) {
1163 $mobile_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
1164 }
1165
1166 if ( '' === $settings['fontSizeMobile'] && ! $settings['removeText'] && ! empty( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'] ) ) {
1167 $mobile_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
1168 } else {
1169 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
1170 }
1171
1172 if ( $settings['inlineWidthMobile'] ) {
1173 $mobile_css->add_property( 'display', '-webkit-inline-box' );
1174 $mobile_css->add_property( 'display', '-ms-inline-flexbox' );
1175 $mobile_css->add_property( 'display', 'inline-flex' );
1176 }
1177
1178 if ( 'inline' === $settings['iconLocationMobile'] ) {
1179 $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentMobile'] ) );
1180 }
1181
1182 if ( 'above' === $settings['iconLocationMobile'] ) {
1183 $mobile_css->add_property( '-ms-flex-direction', 'column' );
1184 $mobile_css->add_property( 'flex-direction', 'column' );
1185 }
1186 }
1187
1188 /**
1189 * Do generateblocks_block_css_data hook
1190 *
1191 * @since 1.0
1192 *
1193 * @param object $css Our desktop/main CSS data.
1194 * @param object $tablet_css Our tablet CSS data.
1195 * @param object $mobile_css Our mobile CSS data.
1196 * @param string $name The name of our block.
1197 * @param array $settings The settings for the current block.
1198 */
1199 do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings );
1200 }
1201
1202 if ( $css->css_output() ) {
1203 $main_css_data[] = $css->css_output();
1204 }
1205
1206 if ( $tablet_css->css_output() ) {
1207 $tablet_css_data[] = $tablet_css->css_output();
1208 }
1209
1210 if ( $mobile_css->css_output() ) {
1211 $mobile_css_data[] = $mobile_css->css_output();
1212 }
1213 }
1214 }
1215
1216 if ( ! $blocks_exist ) {
1217 return false;
1218 }
1219
1220 return apply_filters(
1221 'generateblocks_css_device_data',
1222 array(
1223 'main' => $main_css_data,
1224 'tablet' => $tablet_css_data,
1225 'mobile' => $mobile_css_data,
1226 ),
1227 $settings
1228 );
1229 }
1230
1231 /**
1232 * Turn our CSS array into plain CSS.
1233 *
1234 * @since 1.0
1235 *
1236 * @param array $data Our CSS data.
1237 */
1238 function generateblocks_get_parsed_css( $data ) {
1239 $output = '';
1240
1241 foreach ( $data as $device => $selectors ) {
1242 foreach ( $selectors as $selector => $properties ) {
1243 if ( ! count( $properties ) ) {
1244 continue;
1245 }
1246
1247 $temporary_output = $selector . '{';
1248 $elements_added = 0;
1249
1250 foreach ( $properties as $key => $value ) {
1251 if ( empty( $value ) ) {
1252 continue;
1253 }
1254
1255 $elements_added++;
1256 $temporary_output .= $value;
1257 }
1258
1259 $temporary_output .= '}';
1260
1261 if ( $elements_added > 0 ) {
1262 $output .= $temporary_output;
1263 }
1264 }
1265 }
1266
1267 return $output;
1268 }
1269
1270 /**
1271 * Print our CSS for each block.
1272 *
1273 * @since 0.1
1274 */
1275 function generateblocks_get_frontend_block_css() {
1276 if ( ! function_exists( 'has_blocks' ) ) {
1277 return;
1278 }
1279
1280 $content = '';
1281
1282 if ( has_blocks( get_the_ID() ) ) {
1283
1284 global $post;
1285
1286 if ( ! is_object( $post ) ) {
1287 return;
1288 }
1289
1290 $content = $post->post_content;
1291 }
1292
1293 $content = apply_filters( 'generateblocks_do_content', $content );
1294
1295 if ( ! function_exists( 'parse_blocks' ) ) {
1296 return;
1297 }
1298
1299 $content = parse_blocks( $content );
1300
1301 if ( ! $content ) {
1302 return;
1303 }
1304
1305 $data = generateblocks_get_dynamic_css( $content );
1306
1307 if ( ! $data ) {
1308 return;
1309 }
1310
1311 $css = '';
1312
1313 $css .= generateblocks_get_parsed_css( $data['main'] );
1314
1315 if ( ! empty( $data['tablet'] ) ) {
1316 $css .= sprintf(
1317 '@media %1$s {%2$s}',
1318 generateblocks_get_media_query( 'tablet' ),
1319 generateblocks_get_parsed_css( $data['tablet'] )
1320 );
1321 }
1322
1323 array_unshift(
1324 $data['mobile'],
1325 array(
1326 '.gb-grid-wrapper > .gb-grid-column' => array(
1327 'width: 100%;',
1328 ),
1329 )
1330 );
1331
1332 if ( ! empty( $data['mobile'] ) ) {
1333 $css .= sprintf(
1334 '@media %1$s {%2$s}',
1335 generateblocks_get_media_query( 'mobile' ),
1336 generateblocks_get_parsed_css( $data['mobile'] )
1337 );
1338 }
1339
1340 return apply_filters( 'generateblocks_css_output', $css );
1341 }
1342