PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.4.2
GenerateBlocks v1.4.2
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 4 years ago class-enqueue-css.php 4 years ago class-legacy-attributes.php 4 years ago class-plugin-update.php 5 years ago class-render-blocks.php 4 years ago class-rest.php 4 years ago class-settings.php 5 years ago dashboard.php 5 years ago defaults.php 4 years ago functions.php 4 years ago general.php 4 years ago generate-css.php 4 years ago
generate-css.php
1744 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 $desktop_css_data = array();
35 $tablet_css_data = array();
36 $tablet_only_css_data = array();
37 $mobile_css_data = array();
38
39 foreach ( $data as $name => $blockData ) {
40 /**
41 * Get our Grid block CSS.
42 *
43 * @since 0.1
44 */
45 if ( 'grid' === $name ) {
46 if ( empty( $blockData ) ) {
47 continue;
48 }
49
50 $blocks_exist = true;
51
52 $css = new GenerateBlocks_Dynamic_CSS();
53 $desktop_css = new GenerateBlocks_Dynamic_CSS();
54 $tablet_css = new GenerateBlocks_Dynamic_CSS();
55 $tablet_only_css = new GenerateBlocks_Dynamic_CSS();
56 $mobile_css = new GenerateBlocks_Dynamic_CSS();
57
58 $css->set_selector( '.gb-grid-wrapper' );
59 $css->add_property( 'display', 'flex' );
60 $css->add_property( 'flex-wrap', 'wrap' );
61
62 $css->set_selector( '.gb-grid-wrapper > .gb-grid-column > .gb-container' );
63 $css->add_property( 'display', 'flex' );
64 $css->add_property( 'flex-direction', 'column' );
65 $css->add_property( 'height', '100%' );
66
67 $css->set_selector( '.gb-grid-column' );
68 $css->add_property( 'box-sizing', 'border-box' );
69
70 $css->set_selector( '.gb-grid-wrapper .wp-block-image' );
71 $css->add_property( 'margin-bottom', '0' );
72
73 foreach ( $blockData as $atts ) {
74 if ( ! isset( $atts['uniqueId'] ) ) {
75 continue;
76 }
77
78 $defaults = generateblocks_get_block_defaults();
79
80 $settings = wp_parse_args(
81 $atts,
82 $defaults['gridContainer']
83 );
84
85 $id = $atts['uniqueId'];
86 $blockVersion = ! empty( $settings['blockVersion'] ) ? $settings['blockVersion'] : 1;
87
88 // Use legacy settings if needed.
89 if ( $blockVersion < 2 ) {
90 $settings = GenerateBlocks_Legacy_Attributes::get_settings( '1.4.0', 'grid', $settings, $atts );
91 }
92
93 $gap_direction = 'left';
94
95 if ( is_rtl() ) {
96 $gap_direction = 'right';
97 }
98
99 // Don't output horizontal gap defaults if we're using global styles.
100 if ( $blockVersion < 2 && isset( $settings['useGlobalStyle'] ) && $settings['useGlobalStyle'] && isset( $settings['globalStyleId'] ) && $settings['globalStyleId'] ) {
101 if ( (string) $settings['horizontalGap'] === (string) $defaults['gridContainer']['horizontalGap'] ) {
102 $settings['horizontalGap'] = '';
103 }
104 }
105
106 $css->set_selector( '.gb-grid-wrapper-' . $id );
107 $css->add_property( 'align-items', $settings['verticalAlignment'] );
108 $css->add_property( 'justify-content', $settings['horizontalAlignment'] );
109
110 if ( $settings['horizontalGap'] ) {
111 $css->add_property( 'margin-' . $gap_direction, '-' . $settings['horizontalGap'] . 'px' );
112 }
113
114 $css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' );
115 $css->add_property( 'padding-' . $gap_direction, $settings['horizontalGap'], 'px' );
116 $css->add_property( 'padding-bottom', $settings['verticalGap'], 'px' );
117
118 $tablet_css->set_selector( '.gb-grid-wrapper-' . $id );
119
120 if ( 'inherit' !== $settings['verticalAlignmentTablet'] ) {
121 $tablet_css->add_property( 'align-items', $settings['verticalAlignmentTablet'] );
122 }
123
124 if ( 'inherit' !== $settings['horizontalAlignmentTablet'] ) {
125 $tablet_css->add_property( 'justify-content', $settings['horizontalAlignmentTablet'] );
126 }
127
128 if ( $settings['horizontalGapTablet'] ) {
129 $tablet_css->add_property( 'margin-' . $gap_direction, '-' . $settings['horizontalGapTablet'] . 'px' );
130 } elseif ( 0 === $settings['horizontalGapTablet'] ) {
131 $tablet_css->add_property( 'margin-' . $gap_direction, $settings['horizontalGapTablet'] );
132 }
133
134 $tablet_css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' );
135 $tablet_css->add_property( 'padding-' . $gap_direction, $settings['horizontalGapTablet'], 'px' );
136 $tablet_css->add_property( 'padding-bottom', $settings['verticalGapTablet'], 'px' );
137
138 $mobile_css->set_selector( '.gb-grid-wrapper-' . $id );
139
140 if ( 'inherit' !== $settings['verticalAlignmentMobile'] ) {
141 $mobile_css->add_property( 'align-items', $settings['verticalAlignmentMobile'] );
142 }
143
144 if ( 'inherit' !== $settings['horizontalAlignmentMobile'] ) {
145 $mobile_css->add_property( 'justify-content', $settings['horizontalAlignmentMobile'] );
146 }
147
148 if ( $settings['horizontalGapMobile'] ) {
149 $mobile_css->add_property( 'margin-' . $gap_direction, '-' . $settings['horizontalGapMobile'] . 'px' );
150 } elseif ( 0 === $settings['horizontalGapMobile'] ) {
151 $mobile_css->add_property( 'margin-' . $gap_direction, $settings['horizontalGapMobile'] );
152 }
153
154 $mobile_css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' );
155 $mobile_css->add_property( 'padding-' . $gap_direction, $settings['horizontalGapMobile'], 'px' );
156 $mobile_css->add_property( 'padding-bottom', $settings['verticalGapMobile'], 'px' );
157
158 /**
159 * Do generateblocks_block_css_data hook
160 *
161 * @since 1.0
162 *
163 * @param string $name The name of our block.
164 * @param array $settings The settings for the current block.
165 * @param object $css Our desktop/main CSS data.
166 * @param object $desktop_css Our desktop only CSS data.
167 * @param object $tablet_css Our tablet CSS data.
168 * @param object $tablet_only_css Our tablet only CSS data.
169 * @param object $mobile_css Our mobile CSS data.
170 */
171 do_action(
172 'generateblocks_block_css_data',
173 $name,
174 $settings,
175 $css,
176 $desktop_css,
177 $tablet_css,
178 $tablet_only_css,
179 $mobile_css
180 );
181 }
182
183 if ( $css->css_output() ) {
184 $main_css_data[] = $css->css_output();
185 }
186
187 if ( $desktop_css->css_output() ) {
188 $desktop_css_data[] = $desktop_css->css_output();
189 }
190
191 if ( $tablet_css->css_output() ) {
192 $tablet_css_data[] = $tablet_css->css_output();
193 }
194
195 if ( $tablet_only_css->css_output() ) {
196 $tablet_only_css_data[] = $tablet_only_css->css_output();
197 }
198
199 if ( $mobile_css->css_output() ) {
200 $mobile_css_data[] = $mobile_css->css_output();
201 }
202 }
203
204 /**
205 * Get our Container block CSS.
206 *
207 * @since 0.1
208 */
209 if ( 'container' === $name ) {
210 if ( empty( $blockData ) ) {
211 continue;
212 }
213
214 $blocks_exist = true;
215
216 $css = new GenerateBlocks_Dynamic_CSS();
217 $desktop_css = new GenerateBlocks_Dynamic_CSS();
218 $tablet_css = new GenerateBlocks_Dynamic_CSS();
219 $tablet_only_css = new GenerateBlocks_Dynamic_CSS();
220 $mobile_css = new GenerateBlocks_Dynamic_CSS();
221
222 $css->set_selector( '.gb-container .wp-block-image img' );
223 $css->add_property( 'vertical-align', 'middle' );
224
225 $css->set_selector( '.gb-container .gb-shape' );
226 $css->add_property( 'position', 'absolute' );
227 $css->add_property( 'overflow', 'hidden' );
228 $css->add_property( 'pointer-events', 'none' );
229 $css->add_property( 'line-height', '0' );
230
231 $css->set_selector( '.gb-container .gb-shape svg' );
232 $css->add_property( 'fill', 'currentColor' );
233
234 foreach ( $blockData as $atts ) {
235 if ( ! isset( $atts['uniqueId'] ) ) {
236 continue;
237 }
238
239 $defaults = generateblocks_get_block_defaults();
240
241 $settings = wp_parse_args(
242 $atts,
243 $defaults['container']
244 );
245
246 $id = $atts['uniqueId'];
247 $blockVersion = ! empty( $settings['blockVersion'] ) ? $settings['blockVersion'] : 1;
248
249 // Use legacy settings if needed.
250 if ( $blockVersion < 2 ) {
251 $settings = GenerateBlocks_Legacy_Attributes::get_settings( '1.4.0', 'container', $settings, $atts );
252 }
253
254 $fontFamily = $settings['fontFamily'];
255
256 if ( $fontFamily && $settings['fontFamilyFallback'] ) {
257 $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback'];
258 }
259
260 if ( ! isset( $settings['bgOptions']['selector'] ) ) {
261 $settings['bgOptions']['selector'] = 'element';
262 }
263
264 $containerWidth = $settings['containerWidth'];
265
266 if ( isset( $settings['useGlobalStyle'] ) && $settings['useGlobalStyle'] ) {
267 if ( (string) $containerWidth === (string) $defaults['container']['containerWidth'] ) {
268 $containerWidth = '';
269 }
270 }
271
272 $backgroundImageValue = generateblocks_get_background_image_css( 'image', $settings );
273 $gradientValue = generateblocks_get_background_image_css( 'gradient', $settings );
274 $hasBgImage = $settings['bgImage'];
275
276 $css->set_selector( '.gb-container-' . $id );
277 $css->add_property( 'font-family', $fontFamily );
278 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
279 $css->add_property( 'font-weight', $settings['fontWeight'] );
280 $css->add_property( 'text-transform', $settings['textTransform'] );
281 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
282
283 if ( 'contained' === $settings['outerContainer'] && ! $settings['isGrid'] ) {
284 if ( ! empty( $containerWidth ) ) {
285 $css->add_property( 'max-width', absint( $containerWidth ), 'px' );
286 $css->add_property( 'margin-left', 'auto' );
287 $css->add_property( 'margin-right', 'auto' );
288 }
289 }
290
291 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
292 $css->add_property( 'color', $settings['textColor'] );
293
294 if ( $hasBgImage && 'element' === $settings['bgOptions']['selector'] && $backgroundImageValue ) {
295 $css->add_property( 'background-image', $backgroundImageValue );
296 $css->add_property( 'background-repeat', $settings['bgOptions']['repeat'] );
297 $css->add_property( 'background-position', $settings['bgOptions']['position'] );
298 $css->add_property( 'background-size', $settings['bgOptions']['size'] );
299 $css->add_property( 'background-attachment', $settings['bgOptions']['attachment'] );
300 } elseif ( $settings['gradient'] && 'element' === $settings['gradientSelector'] ) {
301 $css->add_property( 'background-image', $gradientValue );
302 }
303
304 if (
305 ( $hasBgImage && 'pseudo-element' === $settings['bgOptions']['selector'] ) ||
306 $settings['zindex'] ||
307 ( $settings['gradient'] && 'pseudo-element' === $settings['gradientSelector'] )
308 ) {
309 $css->add_property( 'position', 'relative' );
310 }
311
312 if (
313 ( $hasBgImage && 'pseudo-element' === $settings['bgOptions']['selector'] ) ||
314 ( $settings['gradient'] && 'pseudo-element' === $settings['gradientSelector'] )
315 ) {
316 $css->add_property( 'overflow', 'hidden' );
317 }
318
319 if ( $settings['zindex'] ) {
320 $css->add_property( 'z-index', $settings['zindex'] );
321 }
322
323 $css->add_property( 'border-radius', array( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'] ), $settings['borderRadiusUnit'] );
324 $css->add_property( 'border-width', array( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'] ), 'px' );
325 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
326 $css->add_property( 'min-height', $settings['minHeight'], $settings['minHeightUnit'] );
327
328 // Set flags so we don't duplicate this CSS in media queries.
329 $usingMinHeightFlex = false;
330 $usingMinHeightInnerWidth = false;
331
332 if ( $settings['minHeight'] && $settings['verticalAlignment'] && ! $settings['isGrid'] ) {
333 $css->add_property( 'display', 'flex' );
334 $css->add_property( 'flex-direction', 'row' );
335 $css->add_property( 'align-items', $settings['verticalAlignment'] );
336
337 $usingMinHeightFlex = true;
338 }
339
340 $css->add_property( 'text-align', $settings['alignment'] );
341
342 $innerZIndex = $settings['innerZindex'];
343
344 $css->set_selector( '.gb-container-' . $id . ':before' );
345
346 if ( $hasBgImage && 'pseudo-element' === $settings['bgOptions']['selector'] ) {
347 $css->add_property( 'content', '""' );
348 $css->add_property( 'background-image', $backgroundImageValue );
349 $css->add_property( 'background-repeat', $settings['bgOptions']['repeat'] );
350 $css->add_property( 'background-position', $settings['bgOptions']['position'] );
351 $css->add_property( 'background-size', $settings['bgOptions']['size'] );
352 $css->add_property( 'background-attachment', $settings['bgOptions']['attachment'] );
353 $css->add_property( 'z-index', '0' );
354 $css->add_property( 'position', 'absolute' );
355 $css->add_property( 'top', '0' );
356 $css->add_property( 'right', '0' );
357 $css->add_property( 'bottom', '0' );
358 $css->add_property( 'left', '0' );
359 $css->add_property( 'transition', 'inherit' );
360 $css->add_property( 'border-radius', array( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'] ), $settings['borderRadiusUnit'] );
361
362 if ( isset( $settings['bgOptions']['opacity'] ) && 1 !== $settings['bgOptions']['opacity'] ) {
363 $css->add_property( 'opacity', $settings['bgOptions']['opacity'] );
364 }
365
366 if ( $blockVersion < 2 && ! $innerZIndex ) {
367 $innerZIndex = 1;
368 }
369 }
370
371 if ( $settings['gradient'] && 'pseudo-element' === $settings['gradientSelector'] ) {
372 $css->set_selector( '.gb-container-' . $id . ':after' );
373 $css->add_property( 'content', '""' );
374 $css->add_property( 'background-image', $gradientValue );
375 $css->add_property( 'z-index', '0' );
376 $css->add_property( 'position', 'absolute' );
377 $css->add_property( 'top', '0' );
378 $css->add_property( 'right', '0' );
379 $css->add_property( 'bottom', '0' );
380 $css->add_property( 'left', '0' );
381
382 if ( $blockVersion < 2 && ! $innerZIndex ) {
383 $innerZIndex = 1;
384 }
385 }
386
387 $css->set_selector( '.gb-container-' . $id . ' > .gb-inside-container' );
388 $css->add_property( 'padding', array( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'] ), $settings['paddingUnit'] );
389
390 if ( 'contained' === $settings['innerContainer'] && ! $settings['isGrid'] ) {
391 if ( ! empty( $containerWidth ) ) {
392 $css->add_property( 'max-width', absint( $containerWidth ), 'px' );
393 $css->add_property( 'margin-left', 'auto' );
394 $css->add_property( 'margin-right', 'auto' );
395 }
396 }
397
398 if ( $usingMinHeightFlex ) {
399 $css->add_property( 'width', '100%' );
400
401 $usingMinHeightInnerWidth = true;
402 }
403
404 if ( $innerZIndex || 0 === $innerZIndex ) {
405 $css->add_property( 'z-index', $innerZIndex );
406 $css->add_property( 'position', 'relative' );
407 }
408
409 $css->set_selector( '.gb-container-' . $id . ' a, .gb-container-' . $id . ' a:visited' );
410 $css->add_property( 'color', $settings['linkColor'] );
411
412 $css->set_selector( '.gb-container-' . $id . ' a:hover' );
413 $css->add_property( 'color', $settings['linkColorHover'] );
414
415 if ( $settings['isGrid'] ) {
416 $css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id );
417 $css->add_property( 'width', $settings['width'], '%' );
418
419 $css->add_property( 'flex-grow', $settings['flexGrow'] );
420 $css->add_property( 'flex-shrink', $settings['flexShrink'] );
421
422 if ( is_numeric( $settings['flexBasis'] ) ) {
423 $css->add_property( 'flex-basis', $settings['flexBasis'], $settings['flexBasisUnit'] );
424 } else {
425 $css->add_property( 'flex-basis', $settings['flexBasis'] );
426 }
427 }
428
429 if ( $settings['removeVerticalGap'] ) {
430 $desktop_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
431 $desktop_css->add_property( 'padding-bottom', '0' );
432 }
433
434 $css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' );
435 $css->add_property( 'justify-content', $settings['verticalAlignment'] );
436
437 if ( ! empty( $settings['shapeDividers'] ) ) {
438 $css->set_selector( '.gb-container-' . $id );
439 $css->add_property( 'position', 'relative' );
440
441 $default_styles = generateblocks_get_default_styles();
442
443 foreach ( (array) $settings['shapeDividers'] as $index => $options ) {
444 $shapeNumber = $index + 1;
445
446 $shapeOptions = wp_parse_args(
447 $options,
448 $default_styles['container']['shapeDividers']
449 );
450
451 $shapeTransforms = array();
452
453 if ( 'top' === $shapeOptions['location'] ) {
454 $shapeTransforms[] = 'scaleY(-1)';
455 }
456
457 if ( $shapeOptions['flipHorizontally'] ) {
458 $shapeTransforms[] = 'scaleX(-1)';
459 }
460
461 $css->set_selector( '.gb-container-' . $id . ' > .gb-shapes .gb-shape-' . $shapeNumber );
462 $css->add_property( 'color', generateblocks_hex2rgba( $shapeOptions['color'], $shapeOptions['colorOpacity'] ) );
463 $css->add_property( 'z-index', $shapeOptions['zindex'] );
464
465 if ( 'top' === $shapeOptions['location'] || 'bottom' === $shapeOptions['location'] ) {
466 $css->add_property( 'left', '0' );
467 $css->add_property( 'right', '0' );
468 }
469
470 if ( 'bottom' === $shapeOptions['location'] ) {
471 $css->add_property( 'bottom', '-1px' );
472 }
473
474 if ( 'top' === $shapeOptions['location'] ) {
475 $css->add_property( 'top', '-1px' );
476 }
477
478 if ( ! empty( $shapeTransforms ) ) {
479 $css->add_property( 'transform', implode( ' ', $shapeTransforms ) );
480 }
481
482 $shapeWidth = $shapeOptions['width'] . '%';
483
484 if ( 100 === (int) $shapeOptions['width'] ) {
485 $shapeWidth = 'calc(' . $shapeWidth . ' + 1.3px)';
486 }
487
488 $css->set_selector( '.gb-container-' . $id . ' > .gb-shapes .gb-shape-' . $shapeNumber . ' svg' );
489 $css->add_property( 'height', $shapeOptions['height'], 'px' );
490 $css->add_property( 'width', $shapeWidth );
491
492 if ( 'top' === $shapeOptions['location'] || 'bottom' === $shapeOptions['location'] ) {
493 $css->add_property( 'position', 'relative' );
494 $css->add_property( 'left', '50%' );
495 $css->add_property( 'transform', 'translateX(-50%)' );
496 $css->add_property( 'min-width', '100%' );
497 }
498 }
499 }
500
501 $tablet_css->set_selector( '.gb-container-' . $id );
502 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
503 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
504 $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] );
505 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
506 $tablet_css->add_property( 'min-height', $settings['minHeightTablet'], $settings['minHeightUnitTablet'] );
507
508 if ( ! $settings['isGrid'] ) {
509 if ( ! $usingMinHeightFlex && $settings['minHeightTablet'] && 'inherit' !== $settings['verticalAlignmentTablet'] ) {
510 $tablet_css->add_property( 'display', 'flex' );
511 $tablet_css->add_property( 'flex-direction', 'row' );
512
513 $usingMinHeightFlex = true;
514 }
515
516 if ( $usingMinHeightFlex && 'inherit' !== $settings['verticalAlignmentTablet'] ) {
517 $tablet_css->add_property( 'align-items', $settings['verticalAlignmentTablet'] );
518 }
519 }
520
521 $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] );
522
523 $tablet_css->set_selector( '.gb-container-' . $id . ' > .gb-inside-container' );
524 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
525
526 $usingMinHeightInnerWidthBoxSizing = false;
527
528 if ( ! $settings['isGrid'] ) {
529 // Needs 100% width if it's a flex item.
530 if ( ! $usingMinHeightInnerWidth && $settings['minHeightTablet'] && 'inherit' !== $settings['verticalAlignmentTablet'] ) {
531 $tablet_css->add_property( 'width', '100%' );
532
533 $usingMinHeightInnerWidth = true;
534 } elseif ( $usingMinHeightInnerWidth ) {
535 if ( 'contained' === $settings['innerContainer'] && ! $settings['isGrid'] ) {
536 $tablet_css->add_property( 'box-sizing', 'border-box' );
537
538 $usingMinHeightInnerWidthBoxSizing = true;
539 }
540 }
541 }
542
543 $tablet_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id );
544
545 if ( ! $settings['autoWidthTablet'] ) {
546 $tablet_css->add_property( 'width', $settings['widthTablet'], '%' );
547 } else {
548 $tablet_css->add_property( 'width', 'auto' );
549 }
550
551 $tablet_css->add_property( 'flex-grow', $settings['flexGrowTablet'] );
552 $tablet_css->add_property( 'flex-shrink', $settings['flexShrinkTablet'] );
553
554 if ( is_numeric( $settings['flexBasisTablet'] ) ) {
555 $tablet_css->add_property( 'flex-basis', $settings['flexBasisTablet'], $settings['flexBasisUnit'] );
556 } else {
557 $tablet_css->add_property( 'flex-basis', $settings['flexBasisTablet'] );
558 }
559
560 if ( $settings['isGrid'] ) {
561 $tablet_css->add_property( 'order', $settings['orderTablet'] );
562 }
563
564 if ( $settings['removeVerticalGapTablet'] ) {
565 $tablet_only_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
566 $tablet_only_css->add_property( 'padding-bottom', '0' );
567 }
568
569 $tablet_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' );
570
571 if ( 'inherit' !== $settings['verticalAlignmentTablet'] ) {
572 $tablet_css->add_property( 'justify-content', $settings['verticalAlignmentTablet'] );
573 }
574
575 if ( $hasBgImage && 'pseudo-element' === $settings['bgOptions']['selector'] ) {
576 $tablet_css->set_selector( '.gb-container-' . $id . ':before' );
577 $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] );
578 }
579
580 if ( ! empty( $settings['shapeDividers'] ) ) {
581 $default_styles = generateblocks_get_default_styles();
582
583 foreach ( (array) $settings['shapeDividers'] as $index => $options ) {
584 $shapeNumber = $index + 1;
585
586 $shapeOptions = wp_parse_args(
587 $options,
588 $default_styles['container']['shapeDividers']
589 );
590
591 $tablet_css->set_selector( '.gb-container-' . $id . ' > .gb-shapes .gb-shape-' . $shapeNumber . ' svg' );
592 $tablet_css->add_property( 'height', $shapeOptions['heightTablet'], 'px' );
593 $tablet_css->add_property( 'width', $shapeOptions['widthTablet'], '%' );
594 }
595 }
596
597 $mobile_css->set_selector( '.gb-container-' . $id );
598 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
599 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
600 $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftMobile'], $settings['borderRadiusTopRightMobile'], $settings['borderRadiusBottomRightMobile'], $settings['borderRadiusBottomLeftMobile'] ), $settings['borderRadiusUnit'] );
601 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
602 $mobile_css->add_property( 'min-height', $settings['minHeightMobile'], $settings['minHeightUnitMobile'] );
603
604 if ( ! $settings['isGrid'] ) {
605 if ( ! $usingMinHeightFlex && $settings['minHeightMobile'] && 'inherit' !== $settings['verticalAlignmentMobile'] ) {
606 $mobile_css->add_property( 'display', 'flex' );
607 $mobile_css->add_property( 'flex-direction', 'row' );
608
609 $usingMinHeightFlex = true;
610 }
611
612 if ( $usingMinHeightFlex && 'inherit' !== $settings['verticalAlignmentMobile'] ) {
613 $mobile_css->add_property( 'align-items', $settings['verticalAlignmentMobile'] );
614 }
615 }
616
617 $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] );
618
619 $mobile_css->set_selector( '.gb-container-' . $id . ' > .gb-inside-container' );
620 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
621
622 if ( ! $settings['isGrid'] ) {
623 // Needs 100% width if it's a flex item.
624 if ( ! $usingMinHeightInnerWidth && $settings['minHeightMobile'] && 'inherit' !== $settings['verticalAlignmentMobile'] ) {
625 $mobile_css->add_property( 'width', '100%' );
626 } elseif ( $usingMinHeightInnerWidth && ! $usingMinHeightInnerWidthBoxSizing ) {
627 if ( 'contained' === $settings['innerContainer'] && ! $settings['isGrid'] ) {
628 $mobile_css->add_property( 'box-sizing', 'border-box' );
629 }
630 }
631 }
632
633 $mobile_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id );
634
635 if ( ! $settings['autoWidthMobile'] ) {
636 $mobile_css->add_property( 'width', $settings['widthMobile'], '%' );
637 }
638
639 if ( $settings['autoWidthMobile'] ) {
640 $mobile_css->add_property( 'width', 'auto' );
641 }
642
643 $mobile_css->add_property( 'flex-grow', $settings['flexGrowMobile'] );
644 $mobile_css->add_property( 'flex-shrink', $settings['flexShrinkMobile'] );
645
646 if ( is_numeric( $settings['flexBasisMobile'] ) ) {
647 $mobile_css->add_property( 'flex-basis', $settings['flexBasisMobile'], $settings['flexBasisUnit'] );
648 } else {
649 $mobile_css->add_property( 'flex-basis', $settings['flexBasisMobile'] );
650 }
651
652 if ( $settings['isGrid'] ) {
653 $mobile_css->add_property( 'order', $settings['orderMobile'] );
654 }
655
656 if ( $settings['removeVerticalGapMobile'] ) {
657 $mobile_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id );
658 $mobile_css->add_property( 'padding-bottom', '0' );
659 }
660
661 $mobile_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' );
662
663 if ( 'inherit' !== $settings['verticalAlignmentMobile'] ) {
664 $mobile_css->add_property( 'justify-content', $settings['verticalAlignmentMobile'] );
665 }
666
667 if ( $hasBgImage && 'pseudo-element' === $settings['bgOptions']['selector'] ) {
668 $mobile_css->set_selector( '.gb-container-' . $id . ':before' );
669 $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftMobile'], $settings['borderRadiusTopRightMobile'], $settings['borderRadiusBottomRightMobile'], $settings['borderRadiusBottomLeftMobile'] ), $settings['borderRadiusUnit'] );
670 }
671
672 if ( ! empty( $settings['shapeDividers'] ) ) {
673 $default_styles = generateblocks_get_default_styles();
674
675 foreach ( (array) $settings['shapeDividers'] as $index => $options ) {
676 $shapeNumber = $index + 1;
677
678 $shapeOptions = wp_parse_args(
679 $options,
680 $default_styles['container']['shapeDividers']
681 );
682
683 $mobile_css->set_selector( '.gb-container-' . $id . ' > .gb-shapes .gb-shape-' . $shapeNumber . ' svg' );
684 $mobile_css->add_property( 'height', $shapeOptions['heightMobile'], 'px' );
685 $mobile_css->add_property( 'width', $shapeOptions['widthMobile'], '%' );
686 }
687 }
688
689 if ( $hasBgImage && 'fixed' === $settings['bgOptions']['attachment'] ) {
690 if ( 'element' === $settings['bgOptions']['selector'] ) {
691 $mobile_css->set_selector( '.gb-container-' . $id );
692 }
693
694 if ( 'pseudo-element' === $settings['bgOptions']['selector'] ) {
695 $mobile_css->set_selector( '.gb-container-' . $id . ':before' );
696 }
697
698 $mobile_css->add_property( 'background-attachment', 'initial' );
699 }
700
701 /**
702 * Do generateblocks_block_css_data hook
703 *
704 * @since 1.0
705 *
706 * @param string $name The name of our block.
707 * @param array $settings The settings for the current block.
708 * @param object $css Our desktop/main CSS data.
709 * @param object $desktop_css Our desktop only CSS data.
710 * @param object $tablet_css Our tablet CSS data.
711 * @param object $tablet_only_css Our tablet only CSS data.
712 * @param object $mobile_css Our mobile CSS data.
713 */
714 do_action(
715 'generateblocks_block_css_data',
716 $name,
717 $settings,
718 $css,
719 $desktop_css,
720 $tablet_css,
721 $tablet_only_css,
722 $mobile_css
723 );
724 }
725
726 if ( $css->css_output() ) {
727 $main_css_data[] = $css->css_output();
728 }
729
730 if ( $desktop_css->css_output() ) {
731 $desktop_css_data[] = $desktop_css->css_output();
732 }
733
734 if ( $tablet_css->css_output() ) {
735 $tablet_css_data[] = $tablet_css->css_output();
736 }
737
738 if ( $tablet_only_css->css_output() ) {
739 $tablet_only_css_data[] = $tablet_only_css->css_output();
740 }
741
742 if ( $mobile_css->css_output() ) {
743 $mobile_css_data[] = $mobile_css->css_output();
744 }
745 }
746
747 /**
748 * Get our Button Container block CSS.
749 *
750 * @since 0.1
751 */
752 if ( 'button-container' === $name ) {
753 if ( empty( $blockData ) ) {
754 continue;
755 }
756
757 $blocks_exist = true;
758
759 $css = new GenerateBlocks_Dynamic_CSS();
760 $desktop_css = new GenerateBlocks_Dynamic_CSS();
761 $tablet_css = new GenerateBlocks_Dynamic_CSS();
762 $tablet_only_css = new GenerateBlocks_Dynamic_CSS();
763 $mobile_css = new GenerateBlocks_Dynamic_CSS();
764
765 $css->set_selector( '.gb-button-wrapper' );
766 $css->add_property( 'display', 'flex' );
767 $css->add_property( 'flex-wrap', 'wrap' );
768 $css->add_property( 'align-items', 'flex-start' );
769 $css->add_property( 'justify-content', 'flex-start' );
770 $css->add_property( 'clear', 'both' );
771
772 foreach ( $blockData as $atts ) {
773 if ( ! isset( $atts['uniqueId'] ) ) {
774 continue;
775 }
776
777 $defaults = generateblocks_get_block_defaults();
778
779 $settings = wp_parse_args(
780 $atts,
781 $defaults['buttonContainer']
782 );
783
784 $id = $atts['uniqueId'];
785 $blockVersion = ! empty( $settings['blockVersion'] ) ? $settings['blockVersion'] : 1;
786
787 $css->set_selector( '.gb-button-wrapper-' . $id );
788 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
789 $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
790
791 $stack_desktop = $desktop_css;
792 $stack_tablet_only = $tablet_only_css;
793
794 if ( $blockVersion < 2 ) {
795 $stack_desktop = $css;
796 $stack_tablet_only = $tablet_css;
797 }
798
799 if ( $settings['stack'] ) {
800 $stack_desktop->set_selector( '.gb-button-wrapper-' . $id );
801 $stack_desktop->add_property( 'flex-direction', 'column' );
802 $stack_desktop->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
803 }
804
805 if ( $settings['fillHorizontalSpace'] ) {
806 $stack_desktop->set_selector( '.gb-button-wrapper-' . $id . ' > .gb-button' );
807 $stack_desktop->add_property( 'flex', '1' );
808 }
809
810 if ( $settings['stack'] && $settings['fillHorizontalSpace'] ) {
811 $stack_desktop->add_property( 'width', '100%' );
812 $stack_desktop->add_property( 'box-sizing', 'border-box' );
813 }
814
815 $tablet_css->set_selector( '.gb-button-wrapper-' . $id );
816 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
817 $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
818
819 if ( $settings['stackTablet'] ) {
820 $stack_tablet_only->set_selector( '.gb-button-wrapper-' . $id );
821 $stack_tablet_only->add_property( 'flex-direction', 'column' );
822 $stack_tablet_only->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
823 }
824
825 if ( $settings['fillHorizontalSpaceTablet'] ) {
826 $stack_tablet_only->set_selector( '.gb-button-wrapper-' . $id . ' > .gb-button' );
827 $stack_tablet_only->add_property( 'flex', '1' );
828 }
829
830 if ( $settings['stackTablet'] && $settings['fillHorizontalSpaceTablet'] ) {
831 $stack_tablet_only->add_property( 'width', '100%' );
832 $stack_tablet_only->add_property( 'box-sizing', 'border-box' );
833 }
834
835 $mobile_css->set_selector( '.gb-button-wrapper-' . $id );
836 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
837 $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
838
839 if ( $settings['stackMobile'] ) {
840 $mobile_css->add_property( 'flex-direction', 'column' );
841 $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
842 }
843
844 if ( $settings['fillHorizontalSpaceMobile'] ) {
845 $mobile_css->set_selector( '.gb-button-wrapper-' . $id . ' > .gb-button' );
846 $mobile_css->add_property( 'flex', '1' );
847 }
848
849 if ( $settings['stackMobile'] && $settings['fillHorizontalSpaceMobile'] ) {
850 $mobile_css->add_property( 'width', '100%' );
851 $mobile_css->add_property( 'box-sizing', 'border-box' );
852 }
853
854 /**
855 * Do generateblocks_block_css_data hook
856 *
857 * @since 1.0
858 *
859 * @param string $name The name of our block.
860 * @param array $settings The settings for the current block.
861 * @param object $css Our desktop/main CSS data.
862 * @param object $desktop_css Our desktop only CSS data.
863 * @param object $tablet_css Our tablet CSS data.
864 * @param object $tablet_only_css Our tablet only CSS data.
865 * @param object $mobile_css Our mobile CSS data.
866 */
867 do_action(
868 'generateblocks_block_css_data',
869 $name,
870 $settings,
871 $css,
872 $desktop_css,
873 $tablet_css,
874 $tablet_only_css,
875 $mobile_css
876 );
877 }
878
879 if ( $css->css_output() ) {
880 $main_css_data[] = $css->css_output();
881 }
882
883 if ( $desktop_css->css_output() ) {
884 $desktop_css_data[] = $desktop_css->css_output();
885 }
886
887 if ( $tablet_css->css_output() ) {
888 $tablet_css_data[] = $tablet_css->css_output();
889 }
890
891 if ( $tablet_only_css->css_output() ) {
892 $tablet_only_css_data[] = $tablet_only_css->css_output();
893 }
894
895 if ( $mobile_css->css_output() ) {
896 $mobile_css_data[] = $mobile_css->css_output();
897 }
898 }
899
900 /**
901 * Get our Button block CSS.
902 *
903 * @since 0.1
904 */
905 if ( 'button' === $name ) {
906 if ( empty( $blockData ) ) {
907 continue;
908 }
909
910 $blocks_exist = true;
911
912 $css = new GenerateBlocks_Dynamic_CSS();
913 $desktop_css = new GenerateBlocks_Dynamic_CSS();
914 $tablet_css = new GenerateBlocks_Dynamic_CSS();
915 $tablet_only_css = new GenerateBlocks_Dynamic_CSS();
916 $mobile_css = new GenerateBlocks_Dynamic_CSS();
917
918 if ( ! $icon_css_added ) {
919 $css->set_selector( '.gb-icon' );
920 $css->add_property( 'display', 'inline-flex' );
921 $css->add_property( 'line-height', '0' );
922
923 $css->set_selector( '.gb-icon svg' );
924 $css->add_property( 'height', '1em' );
925 $css->add_property( 'width', '1em' );
926 $css->add_property( 'fill', 'currentColor' );
927
928 $icon_css_added = true;
929 }
930
931 $css->set_selector( '.gb-button-wrapper .gb-button' );
932 $css->add_property( 'display', 'inline-flex' );
933 $css->add_property( 'align-items', 'center' );
934 $css->add_property( 'justify-content', 'center' );
935 $css->add_property( 'text-align', 'center' );
936 $css->add_property( 'text-decoration', 'none' );
937 $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' );
938
939 $css->set_selector( '.gb-button-wrapper .gb-button .gb-icon' );
940 $css->add_property( 'align-items', 'center' );
941
942 foreach ( $blockData as $atts ) {
943 if ( ! isset( $atts['uniqueId'] ) ) {
944 continue;
945 }
946
947 $defaults = generateblocks_get_block_defaults();
948
949 $settings = wp_parse_args(
950 $atts,
951 $defaults['button']
952 );
953
954 $id = $atts['uniqueId'];
955 $blockVersion = ! empty( $settings['blockVersion'] ) ? $settings['blockVersion'] : 1;
956
957 // Use legacy settings if needed.
958 if ( $blockVersion < 2 ) {
959 $settings = GenerateBlocks_Legacy_Attributes::get_settings( '1.4.0', 'button', $settings, $atts );
960 }
961
962 $selector = 'a.gb-button-' . $id;
963
964 if ( isset( $atts['hasUrl'] ) && ! $atts['hasUrl'] ) {
965 $selector = '.gb-button-' . $id;
966 }
967
968 // Back-compatibility for when icon held a value.
969 if ( $settings['icon'] ) {
970 $settings['hasIcon'] = true;
971 }
972
973 $fontFamily = $settings['fontFamily'];
974
975 if ( $fontFamily && $settings['fontFamilyFallback'] ) {
976 $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback'];
977 }
978
979 $gradientColorStopOneValue = '';
980 $gradientColorStopTwoValue = '';
981
982 if ( $settings['gradient'] ) {
983 if ( $settings['gradientColorOne'] && '' !== $settings['gradientColorStopOne'] ) {
984 $gradientColorStopOneValue = ' ' . $settings['gradientColorStopOne'] . '%';
985 }
986
987 if ( $settings['gradientColorTwo'] && '' !== $settings['gradientColorStopTwo'] ) {
988 $gradientColorStopTwoValue = ' ' . $settings['gradientColorStopTwo'] . '%';
989 }
990 }
991
992 $css->set_selector( '.gb-button-wrapper ' . $selector . ',.gb-button-wrapper ' . $selector . ':visited' );
993 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
994 $css->add_property( 'color', $settings['textColor'] );
995
996 if ( $settings['gradient'] ) {
997 $css->add_property( 'background-image', 'linear-gradient(' . $settings['gradientDirection'] . 'deg, ' . generateblocks_hex2rgba( $settings['gradientColorOne'], $settings['gradientColorOneOpacity'] ) . $gradientColorStopOneValue . ', ' . generateblocks_hex2rgba( $settings['gradientColorTwo'], $settings['gradientColorTwoOpacity'] ) . $gradientColorStopTwoValue . ')' );
998 }
999
1000 $css->add_property( 'font-family', $fontFamily );
1001 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
1002 $css->add_property( 'font-weight', $settings['fontWeight'] );
1003 $css->add_property( 'text-transform', $settings['textTransform'] );
1004 $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' );
1005 $css->add_property( 'padding', array( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'] ), $settings['paddingUnit'] );
1006 $css->add_property( 'border-radius', array( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'] ), $settings['borderRadiusUnit'] );
1007 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
1008 $css->add_property( 'border-width', array( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'] ), 'px' );
1009 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
1010 $css->add_property( 'text-transform', $settings['textTransform'] );
1011
1012 if ( $settings['hasIcon'] ) {
1013 $css->add_property( 'display', 'inline-flex' );
1014 $css->add_property( 'align-items', 'center' );
1015 }
1016
1017 $css->set_selector( '.gb-button-wrapper ' . $selector . ':hover,.gb-button-wrapper ' . $selector . ':active,.gb-button-wrapper ' . $selector . ':focus' );
1018 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColorHover'], $settings['backgroundColorHoverOpacity'] ) );
1019 $css->add_property( 'color', $settings['textColorHover'] );
1020 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColorHover'], $settings['borderColorHoverOpacity'] ) );
1021
1022 if ( $settings['hasIcon'] ) {
1023 $css->set_selector( $selector . ' .gb-icon' );
1024 $css->add_property( 'font-size', $settings['iconSize'], $settings['iconSizeUnit'] );
1025
1026 if ( ! $settings['removeText'] ) {
1027 $css->add_property( 'padding', array( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'] ), $settings['iconPaddingUnit'] );
1028 }
1029 }
1030
1031 $tablet_css->set_selector( '.gb-button-wrapper ' . $selector );
1032 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
1033 $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' );
1034 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
1035 $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] );
1036 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
1037 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
1038
1039 if ( $settings['hasIcon'] ) {
1040 $tablet_css->set_selector( $selector . ' .gb-icon' );
1041 $tablet_css->add_property( 'font-size', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
1042
1043 if ( ! $settings['removeText'] ) {
1044 $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] );
1045 }
1046 }
1047
1048 $mobile_css->set_selector( '.gb-button-wrapper ' . $selector );
1049 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
1050 $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' );
1051 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
1052 $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftMobile'], $settings['borderRadiusTopRightMobile'], $settings['borderRadiusBottomRightMobile'], $settings['borderRadiusBottomLeftMobile'] ), $settings['borderRadiusUnit'] );
1053 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
1054 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
1055
1056 if ( $settings['hasIcon'] ) {
1057 $mobile_css->set_selector( $selector . ' .gb-icon' );
1058 $mobile_css->add_property( 'font-size', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
1059
1060 if ( ! $settings['removeText'] ) {
1061 $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] );
1062 }
1063 }
1064
1065 /**
1066 * Do generateblocks_block_css_data hook
1067 *
1068 * @since 1.0
1069 *
1070 * @param string $name The name of our block.
1071 * @param array $settings The settings for the current block.
1072 * @param object $css Our desktop/main CSS data.
1073 * @param object $desktop_css Our desktop only CSS data.
1074 * @param object $tablet_css Our tablet CSS data.
1075 * @param object $tablet_only_css Our tablet only CSS data.
1076 * @param object $mobile_css Our mobile CSS data.
1077 */
1078 do_action(
1079 'generateblocks_block_css_data',
1080 $name,
1081 $settings,
1082 $css,
1083 $desktop_css,
1084 $tablet_css,
1085 $tablet_only_css,
1086 $mobile_css
1087 );
1088 }
1089
1090 if ( $css->css_output() ) {
1091 $main_css_data[] = $css->css_output();
1092 }
1093
1094 if ( $desktop_css->css_output() ) {
1095 $desktop_css_data[] = $desktop_css->css_output();
1096 }
1097
1098 if ( $tablet_css->css_output() ) {
1099 $tablet_css_data[] = $tablet_css->css_output();
1100 }
1101
1102 if ( $tablet_only_css->css_output() ) {
1103 $tablet_only_css_data[] = $tablet_only_css->css_output();
1104 }
1105
1106 if ( $mobile_css->css_output() ) {
1107 $mobile_css_data[] = $mobile_css->css_output();
1108 }
1109 }
1110
1111 /**
1112 * Get our Headline block CSS.
1113 *
1114 * @since 0.1
1115 */
1116 if ( 'headline' === $name ) {
1117 if ( empty( $blockData ) ) {
1118 continue;
1119 }
1120
1121 $blocks_exist = true;
1122
1123 $css = new GenerateBlocks_Dynamic_CSS();
1124 $desktop_css = new GenerateBlocks_Dynamic_CSS();
1125 $tablet_css = new GenerateBlocks_Dynamic_CSS();
1126 $tablet_only_css = new GenerateBlocks_Dynamic_CSS();
1127 $mobile_css = new GenerateBlocks_Dynamic_CSS();
1128
1129 if ( ! $icon_css_added ) {
1130 $css->set_selector( '.gb-icon' );
1131 $css->add_property( 'display', 'inline-flex' );
1132 $css->add_property( 'line-height', '0' );
1133
1134 $css->set_selector( '.gb-icon svg' );
1135 $css->add_property( 'height', '1em' );
1136 $css->add_property( 'width', '1em' );
1137 $css->add_property( 'fill', 'currentColor' );
1138
1139 $icon_css_added = true;
1140 }
1141
1142 $css->set_selector( '.gb-highlight' );
1143 $css->add_property( 'background', 'none' );
1144 $css->add_property( 'color', 'unset' );
1145
1146 foreach ( $blockData as $atts ) {
1147 if ( ! isset( $atts['uniqueId'] ) ) {
1148 continue;
1149 }
1150
1151 $defaults = generateblocks_get_block_defaults();
1152
1153 $settings = wp_parse_args(
1154 $atts,
1155 $defaults['headline']
1156 );
1157
1158 $id = $atts['uniqueId'];
1159
1160 $selector = '.gb-headline-' . $id;
1161
1162 if ( apply_filters( 'generateblocks_headline_selector_tagname', true, $atts ) ) {
1163 $selector = $settings['element'] . $selector;
1164 }
1165
1166 // Back-compatibility for when icon held a value.
1167 if ( $settings['icon'] ) {
1168 $settings['hasIcon'] = true;
1169 }
1170
1171 $fontFamily = $settings['fontFamily'];
1172
1173 if ( $fontFamily && $settings['fontFamilyFallback'] ) {
1174 $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback'];
1175 }
1176
1177 if ( ! isset( $atts['hasWrapper'] ) ) {
1178 $css->set_selector( $selector );
1179 $css->add_property( 'font-family', $fontFamily );
1180 $css->add_property( 'text-align', $settings['alignment'] );
1181 $css->add_property( 'color', $settings['textColor'] );
1182 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
1183 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
1184 $css->add_property( 'font-weight', $settings['fontWeight'] );
1185 $css->add_property( 'text-transform', $settings['textTransform'] );
1186 $css->add_property( 'line-height', $settings['lineHeight'], $settings['lineHeightUnit'] );
1187 $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' );
1188 $css->add_property( 'padding', array( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'] ), $settings['paddingUnit'] );
1189 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
1190 $css->add_property( 'border-radius', array( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'] ), $settings['borderRadiusUnit'] );
1191 $css->add_property( 'border-width', array( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'] ), 'px' );
1192 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
1193
1194 if ( $settings['inlineWidth'] ) {
1195 if ( $settings['hasIcon'] ) {
1196 $css->add_property( 'display', 'inline-flex' );
1197 } else {
1198 $css->add_property( 'display', 'inline-block' );
1199 }
1200 }
1201
1202 if ( $settings['hasIcon'] ) {
1203 if ( ! $settings['inlineWidth'] ) {
1204 $css->add_property( 'display', 'flex' );
1205 }
1206
1207 if ( 'above' === $settings['iconLocation'] ) {
1208 $css->add_property( 'text-align', $settings['alignment'] );
1209 } else {
1210 $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
1211 }
1212
1213 if ( 'inline' === $settings['iconLocation'] ) {
1214 $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignment'] ) );
1215 }
1216
1217 if ( 'above' === $settings['iconLocation'] ) {
1218 $css->add_property( 'flex-direction', 'column' );
1219 }
1220 }
1221
1222 $css->set_selector( $selector . ' a' );
1223 $css->add_property( 'color', $settings['linkColor'] );
1224
1225 $css->set_selector( $selector . ' a:hover' );
1226 $css->add_property( 'color', $settings['linkColorHover'] );
1227
1228 if ( $settings['hasIcon'] ) {
1229 $css->set_selector( $selector . ' .gb-icon' );
1230 $css->add_property( 'color', generateblocks_hex2rgba( $settings['iconColor'], $settings['iconColorOpacity'] ) );
1231
1232 if ( ! $settings['removeText'] ) {
1233 $css->add_property( 'padding', array( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'] ), $settings['iconPaddingUnit'] );
1234 }
1235
1236 if ( 'above' === $settings['iconLocation'] ) {
1237 $css->add_property( 'display', 'inline' );
1238 }
1239
1240 $css->set_selector( $selector . ' .gb-icon svg' );
1241 $css->add_property( 'width', $settings['iconSize'], $settings['iconSizeUnit'] );
1242 $css->add_property( 'height', $settings['iconSize'], $settings['iconSizeUnit'] );
1243 }
1244
1245 if ( $settings['highlightTextColor'] ) {
1246 $css->set_selector( $selector . ' .gb-highlight' );
1247 $css->add_property( 'color', $settings['highlightTextColor'] );
1248 }
1249
1250 $tablet_css->set_selector( $selector );
1251 $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] );
1252 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
1253 $tablet_css->add_property( 'line-height', $settings['lineHeightTablet'], $settings['lineHeightUnit'] );
1254 $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' );
1255 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
1256 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
1257 $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] );
1258 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
1259
1260 if ( $settings['inlineWidthTablet'] ) {
1261 if ( $settings['hasIcon'] ) {
1262 $tablet_css->add_property( 'display', 'inline-flex' );
1263 } else {
1264 $tablet_css->add_property( 'display', 'inline-block' );
1265 }
1266 }
1267
1268 if ( $settings['hasIcon'] ) {
1269 $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
1270
1271 if ( 'inline' === $settings['iconLocationTablet'] ) {
1272 $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentTablet'] ) );
1273 }
1274
1275 if ( 'above' === $settings['iconLocationTablet'] ) {
1276 $tablet_css->add_property( 'flex-direction', 'column' );
1277 }
1278
1279 $tablet_css->set_selector( $selector . ' .gb-icon' );
1280
1281 if ( ! $settings['removeText'] ) {
1282 $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] );
1283 }
1284
1285 if ( 'above' === $settings['iconLocationTablet'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationTablet'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1286 $tablet_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
1287 }
1288
1289 if ( 'above' === $settings['iconLocationTablet'] ) {
1290 $tablet_css->add_property( 'display', 'inline' );
1291 }
1292
1293 $tablet_css->set_selector( $selector . ' .gb-icon svg' );
1294 $tablet_css->add_property( 'width', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
1295 $tablet_css->add_property( 'height', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
1296 }
1297
1298 $mobile_css->set_selector( $selector );
1299 $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] );
1300 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
1301 $mobile_css->add_property( 'line-height', $settings['lineHeightMobile'], $settings['lineHeightUnit'] );
1302 $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' );
1303 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
1304 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
1305 $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftMobile'], $settings['borderRadiusTopRightMobile'], $settings['borderRadiusBottomRightMobile'], $settings['borderRadiusBottomLeftMobile'] ), $settings['borderRadiusUnit'] );
1306 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
1307
1308 if ( $settings['inlineWidthMobile'] ) {
1309 if ( $settings['hasIcon'] ) {
1310 $mobile_css->add_property( 'display', 'inline-flex' );
1311 } else {
1312 $mobile_css->add_property( 'display', 'inline-block' );
1313 }
1314 }
1315
1316 if ( $settings['hasIcon'] ) {
1317 $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
1318
1319 if ( 'inline' === $settings['iconLocationMobile'] ) {
1320 $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentMobile'] ) );
1321 }
1322
1323 if ( 'above' === $settings['iconLocationMobile'] ) {
1324 $mobile_css->add_property( 'flex-direction', 'column' );
1325 }
1326
1327 $mobile_css->set_selector( $selector . ' .gb-icon' );
1328
1329 if ( ! $settings['removeText'] ) {
1330 $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] );
1331 }
1332
1333 if ( 'above' === $settings['iconLocationMobile'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationMobile'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1334 $mobile_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
1335 }
1336
1337 if ( 'above' === $settings['iconLocationMobile'] ) {
1338 $mobile_css->add_property( 'display', 'inline' );
1339 }
1340
1341 $mobile_css->set_selector( $selector . ' .gb-icon svg' );
1342 $mobile_css->add_property( 'width', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
1343 $mobile_css->add_property( 'height', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
1344 }
1345 } else {
1346 // The below CSS is for users using the old headline wrapper.
1347 $css->set_selector( '.gb-headline-wrapper' );
1348 $css->add_property( 'display', 'flex' );
1349
1350 $css->set_selector( '.gb-headline-wrapper > .gb-headline' );
1351 $css->add_property( 'margin', '0' );
1352 $css->add_property( 'padding', '0' );
1353
1354 $css->set_selector( '.gb-headline-' . $id );
1355 $css->add_property( 'font-family', $fontFamily );
1356 $css->add_property( 'text-align', $settings['alignment'] );
1357 $css->add_property( 'color', $settings['textColor'] );
1358
1359 if ( ! $settings['hasIcon'] ) {
1360 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
1361
1362 if ( $settings['inlineWidth'] ) {
1363 $css->add_property( 'display', 'inline-block' );
1364 }
1365
1366 $css->add_property( 'border-width', array( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'] ), 'px' );
1367 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
1368 }
1369
1370 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
1371 $css->add_property( 'font-weight', $settings['fontWeight'] );
1372 $css->add_property( 'text-transform', $settings['textTransform'] );
1373 $css->add_property( 'line-height', $settings['lineHeight'], $settings['lineHeightUnit'] );
1374 $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' );
1375
1376 if ( ! $settings['hasIcon'] ) {
1377 $css->add_property( 'padding', array( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'] ), $settings['paddingUnit'] );
1378 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
1379
1380 if ( function_exists( 'generate_get_default_fonts' ) && '' === $settings['marginBottom'] ) {
1381 $defaultBlockStyles = generateblocks_get_default_styles();
1382
1383 if ( isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) {
1384 $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
1385 }
1386 }
1387 }
1388
1389 $css->set_selector( '.gb-headline-' . $id . ' a, .gb-headline-' . $id . ' a:visited' );
1390 $css->add_property( 'color', $settings['linkColor'] );
1391
1392 $css->set_selector( '.gb-headline-' . $id . ' a:hover' );
1393 $css->add_property( 'color', $settings['linkColorHover'] );
1394
1395 if ( $settings['hasIcon'] ) {
1396 $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
1397
1398 if ( ! $settings['removeText'] ) {
1399 $css->add_property( 'padding', array( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'] ), $settings['iconPaddingUnit'] );
1400 }
1401
1402 $css->add_property( 'color', generateblocks_hex2rgba( $settings['iconColor'], $settings['iconColorOpacity'] ) );
1403
1404 if ( 'above' === $settings['iconLocation'] ) {
1405 $css->add_property( 'display', 'inline' );
1406 }
1407
1408 $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
1409 $css->add_property( 'width', $settings['iconSize'], $settings['iconSizeUnit'] );
1410 $css->add_property( 'height', $settings['iconSize'], $settings['iconSizeUnit'] );
1411
1412 $css->set_selector( '.gb-headline-wrapper-' . $id );
1413 $css->add_property( 'padding', array( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'] ), $settings['paddingUnit'] );
1414 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
1415
1416 $defaultBlockStyles = generateblocks_get_default_styles();
1417
1418 if ( '' === $settings['marginBottom'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) {
1419 $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
1420 }
1421
1422 if ( '' === $settings['fontSize'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'] ) ) {
1423 $css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
1424 } else {
1425 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
1426 }
1427
1428 if ( 'above' === $settings['iconLocation'] ) {
1429 $css->add_property( 'text-align', $settings['alignment'] );
1430 } else {
1431 $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
1432 }
1433
1434 if ( $settings['inlineWidth'] ) {
1435 $css->add_property( 'display', 'inline-flex' );
1436 }
1437
1438 if ( 'inline' === $settings['iconLocation'] ) {
1439 $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignment'] ) );
1440 }
1441
1442 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
1443 $css->add_property( 'color', $settings['textColor'] );
1444 $css->add_property( 'border-width', array( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'] ), 'px' );
1445 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
1446
1447 if ( 'above' === $settings['iconLocation'] ) {
1448 $css->add_property( 'flex-direction', 'column' );
1449 }
1450 }
1451
1452 if ( $settings['highlightTextColor'] ) {
1453 $css->set_selector( '.gb-headline-' . $id . ' .gb-highlight' );
1454 $css->add_property( 'color', $settings['highlightTextColor'] );
1455 }
1456
1457 $tablet_css->set_selector( '.gb-headline-' . $id );
1458 $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] );
1459 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
1460 $tablet_css->add_property( 'line-height', $settings['lineHeightTablet'], $settings['lineHeightUnit'] );
1461 $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' );
1462
1463 if ( ! $settings['hasIcon'] ) {
1464 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
1465 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
1466 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
1467
1468 if ( $settings['inlineWidthTablet'] ) {
1469 $tablet_css->add_property( 'display', 'inline-flex' );
1470 }
1471 }
1472
1473 if ( $settings['hasIcon'] ) {
1474 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
1475
1476 if ( ! $settings['removeText'] ) {
1477 $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] );
1478 }
1479
1480 if ( 'above' === $settings['iconLocationTablet'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationTablet'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1481 $tablet_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
1482 }
1483
1484 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
1485 $tablet_css->add_property( 'width', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
1486 $tablet_css->add_property( 'height', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
1487
1488 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id );
1489 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
1490 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
1491 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
1492 $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
1493
1494 $defaultBlockStyles = generateblocks_get_default_styles();
1495
1496 if ( '' === $settings['marginBottomTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) ) {
1497 $tablet_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
1498 }
1499
1500 if ( '' === $settings['fontSizeTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'] ) ) {
1501 $tablet_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
1502 } else {
1503 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
1504 }
1505
1506 if ( $settings['inlineWidthTablet'] ) {
1507 $tablet_css->add_property( 'display', 'inline-flex' );
1508 }
1509
1510 if ( 'inline' === $settings['iconLocationTablet'] ) {
1511 $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentTablet'] ) );
1512 }
1513
1514 if ( 'above' === $settings['iconLocationTablet'] ) {
1515 $tablet_css->add_property( 'flex-direction', 'column' );
1516 }
1517 }
1518
1519 $mobile_css->set_selector( '.gb-headline-' . $id );
1520 $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] );
1521 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
1522 $mobile_css->add_property( 'line-height', $settings['lineHeightMobile'], $settings['lineHeightUnit'] );
1523 $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' );
1524
1525 if ( ! $settings['hasIcon'] ) {
1526 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
1527 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
1528 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
1529
1530 if ( $settings['inlineWidthMobile'] ) {
1531 $mobile_css->add_property( 'display', 'inline-flex' );
1532 }
1533 }
1534
1535 if ( $settings['hasIcon'] ) {
1536 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
1537
1538 if ( ! $settings['removeText'] ) {
1539 $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] );
1540 }
1541
1542 if ( 'above' === $settings['iconLocationMobile'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationMobile'] ) || ( 'above' === $settings['iconLocationTablet'] && '' == $settings['iconLocationMobile'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1543 $mobile_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
1544 }
1545
1546 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
1547 $mobile_css->add_property( 'width', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
1548 $mobile_css->add_property( 'height', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
1549
1550 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id );
1551 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
1552 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
1553 $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
1554
1555 $defaultBlockStyles = generateblocks_get_default_styles();
1556
1557 if ( '' === $settings['marginBottomMobile'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) ) {
1558 $mobile_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
1559 }
1560
1561 if ( '' === $settings['fontSizeMobile'] && ! $settings['removeText'] && ! empty( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'] ) ) {
1562 $mobile_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
1563 } else {
1564 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
1565 }
1566
1567 if ( $settings['inlineWidthMobile'] ) {
1568 $mobile_css->add_property( 'display', 'inline-flex' );
1569 }
1570
1571 if ( 'inline' === $settings['iconLocationMobile'] ) {
1572 $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentMobile'] ) );
1573 }
1574
1575 if ( 'above' === $settings['iconLocationMobile'] ) {
1576 $mobile_css->add_property( 'flex-direction', 'column' );
1577 }
1578 }
1579 }
1580
1581 /**
1582 * Do generateblocks_block_css_data hook
1583 *
1584 * @since 1.0
1585 *
1586 * @param string $name The name of our block.
1587 * @param array $settings The settings for the current block.
1588 * @param object $css Our desktop/main CSS data.
1589 * @param object $desktop_css Our desktop only CSS data.
1590 * @param object $tablet_css Our tablet CSS data.
1591 * @param object $tablet_only_css Our tablet only CSS data.
1592 * @param object $mobile_css Our mobile CSS data.
1593 */
1594 do_action(
1595 'generateblocks_block_css_data',
1596 $name,
1597 $settings,
1598 $css,
1599 $desktop_css,
1600 $tablet_css,
1601 $tablet_only_css,
1602 $mobile_css
1603 );
1604 }
1605
1606 if ( $css->css_output() ) {
1607 $main_css_data[] = $css->css_output();
1608 }
1609
1610 if ( $desktop_css->css_output() ) {
1611 $desktop_css_data[] = $desktop_css->css_output();
1612 }
1613
1614 if ( $tablet_css->css_output() ) {
1615 $tablet_css_data[] = $tablet_css->css_output();
1616 }
1617
1618 if ( $tablet_only_css->css_output() ) {
1619 $tablet_only_css_data[] = $tablet_only_css->css_output();
1620 }
1621
1622 if ( $mobile_css->css_output() ) {
1623 $mobile_css_data[] = $mobile_css->css_output();
1624 }
1625 }
1626 }
1627
1628 if ( ! $blocks_exist ) {
1629 return false;
1630 }
1631
1632 return apply_filters(
1633 'generateblocks_css_device_data',
1634 array(
1635 'main' => $main_css_data,
1636 'desktop' => $desktop_css_data,
1637 'tablet' => $tablet_css_data,
1638 'tablet_only' => $tablet_only_css_data,
1639 'mobile' => $mobile_css_data,
1640 ),
1641 $settings
1642 );
1643 }
1644
1645 /**
1646 * Turn our CSS array into plain CSS.
1647 *
1648 * @since 1.0
1649 *
1650 * @param array $data Our CSS data.
1651 */
1652 function generateblocks_get_parsed_css( $data ) {
1653 $output = '';
1654
1655 foreach ( $data as $device => $selectors ) {
1656 foreach ( $selectors as $selector => $properties ) {
1657 if ( ! count( $properties ) ) {
1658 continue;
1659 }
1660
1661 $temporary_output = $selector . '{';
1662 $elements_added = 0;
1663
1664 foreach ( $properties as $key => $value ) {
1665 if ( empty( $value ) ) {
1666 continue;
1667 }
1668
1669 $elements_added++;
1670 $temporary_output .= $value;
1671 }
1672
1673 $temporary_output .= '}';
1674
1675 if ( $elements_added > 0 ) {
1676 $output .= $temporary_output;
1677 }
1678 }
1679 }
1680
1681 return $output;
1682 }
1683
1684 /**
1685 * Print our CSS for each block.
1686 *
1687 * @since 0.1
1688 */
1689 function generateblocks_get_frontend_block_css() {
1690 if ( ! function_exists( 'has_blocks' ) ) {
1691 return;
1692 }
1693
1694 $content = generateblocks_get_parsed_content();
1695
1696 if ( ! $content ) {
1697 return;
1698 }
1699
1700 $data = generateblocks_get_dynamic_css( $content );
1701
1702 if ( ! $data ) {
1703 return;
1704 }
1705
1706 $css = '';
1707
1708 $css .= generateblocks_get_parsed_css( $data['main'] );
1709
1710 if ( ! empty( $data['desktop'] ) ) {
1711 $css .= sprintf(
1712 '@media %1$s {%2$s}',
1713 generateblocks_get_media_query( 'desktop' ),
1714 generateblocks_get_parsed_css( $data['desktop'] )
1715 );
1716 }
1717
1718 if ( ! empty( $data['tablet'] ) ) {
1719 $css .= sprintf(
1720 '@media %1$s {%2$s}',
1721 generateblocks_get_media_query( 'tablet' ),
1722 generateblocks_get_parsed_css( $data['tablet'] )
1723 );
1724 }
1725
1726 if ( ! empty( $data['tablet_only'] ) ) {
1727 $css .= sprintf(
1728 '@media %1$s {%2$s}',
1729 generateblocks_get_media_query( 'tablet_only' ),
1730 generateblocks_get_parsed_css( $data['tablet_only'] )
1731 );
1732 }
1733
1734 if ( ! empty( $data['mobile'] ) ) {
1735 $css .= sprintf(
1736 '@media %1$s {%2$s}',
1737 generateblocks_get_media_query( 'mobile' ),
1738 generateblocks_get_parsed_css( $data['mobile'] )
1739 );
1740 }
1741
1742 return apply_filters( 'generateblocks_css_output', $css );
1743 }
1744