PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.0
GenerateBlocks v1.8.0
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 / blocks / class-headline.php
generateblocks / includes / blocks Last commit date
class-button-container.php 2 years ago class-button.php 2 years ago class-container.php 2 years ago class-grid.php 3 years ago class-headline.php 2 years ago class-image.php 2 years ago class-query-loop.php 3 years ago
class-headline.php
822 lines
1 <?php
2 /**
3 * Handles the Headline block.
4 *
5 * @package GenerateBlocks
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Add Headline related functions.
14 */
15 class GenerateBlocks_Block_Headline {
16 /**
17 * Keep track of all blocks of this type on the page.
18 *
19 * @var array $block_ids The current block id.
20 */
21 private static $block_ids = [];
22
23 /**
24 * Keep track of CSS we want to output once per block type.
25 *
26 * @var boolean
27 */
28 private static $singular_css_added = false;
29
30 /**
31 * Block defaults.
32 */
33 public static function defaults() {
34 return [
35 'element' => 'h2',
36 'cssClasses' => '',
37 'backgroundColor' => '',
38 'textColor' => '',
39 'linkColor' => '',
40 'linkColorHover' => '',
41 'highlightTextColor' => '',
42 'fontFamilyFallback' => '',
43 'googleFont' => false,
44 'googleFontVariants' => '',
45 'icon' => '',
46 'hasIcon' => false,
47 'iconColor' => '',
48 'iconLocation' => 'inline',
49 'iconLocationTablet' => '',
50 'iconLocationMobile' => '',
51 'removeText' => false,
52 'ariaLabel' => '',
53 // Deprecated attributes.
54 'backgroundColorOpacity' => 1,
55 'borderColorOpacity' => 1,
56 'iconColorOpacity' => 1,
57 'fontSize' => '',
58 'fontSizeTablet' => '',
59 'fontSizeMobile' => '',
60 'fontSizeUnit' => 'px',
61 'lineHeight' => '',
62 'lineHeightTablet' => '',
63 'lineHeightMobile' => '',
64 'lineHeightUnit' => 'em',
65 'letterSpacing' => '',
66 'letterSpacingTablet' => '',
67 'letterSpacingMobile' => '',
68 'fontWeight' => '',
69 'textTransform' => '',
70 'alignment' => '',
71 'alignmentTablet' => '',
72 'alignmentMobile' => '',
73 'iconVerticalAlignment' => 'center',
74 'iconVerticalAlignmentTablet' => '',
75 'iconVerticalAlignmentMobile' => '',
76 'inlineWidth' => false,
77 'inlineWidthTablet' => false,
78 'inlineWidthMobile' => false,
79 'fontFamily' => '',
80 'borderColor' => '',
81 'iconPaddingTop' => '',
82 'iconPaddingRight' => '0.5',
83 'iconPaddingBottom' => '',
84 'iconPaddingLeft' => '',
85 'iconPaddingTopTablet' => '',
86 'iconPaddingRightTablet' => '',
87 'iconPaddingBottomTablet' => '',
88 'iconPaddingLeftTablet' => '',
89 'iconPaddingTopMobile' => '',
90 'iconPaddingRightMobile' => '',
91 'iconPaddingBottomMobile' => '',
92 'iconPaddingLeftMobile' => '',
93 'iconPaddingUnit' => 'em',
94 'iconSize' => 1,
95 'iconSizeTablet' => '',
96 'iconSizeMobile' => '',
97 'iconSizeUnit' => 'em',
98 ];
99 }
100
101 /**
102 * Store our block ID in memory.
103 *
104 * @param string $id The block ID to store.
105 */
106 public static function store_block_id( $id ) {
107 self::$block_ids[] = $id;
108 }
109
110 /**
111 * Check if our block ID exists.
112 *
113 * @param string $id The block ID to store.
114 */
115 public static function block_id_exists( $id ) {
116 return in_array( $id, (array) self::$block_ids );
117 }
118
119 /**
120 * Compile our CSS data based on our block attributes.
121 *
122 * @param array $attributes Our block attributes.
123 */
124 public static function get_css_data( $attributes ) {
125 $css = new GenerateBlocks_Dynamic_CSS();
126 $desktop_css = new GenerateBlocks_Dynamic_CSS();
127 $tablet_css = new GenerateBlocks_Dynamic_CSS();
128 $tablet_only_css = new GenerateBlocks_Dynamic_CSS();
129 $mobile_css = new GenerateBlocks_Dynamic_CSS();
130 $css_data = [];
131
132 $defaults = generateblocks_get_block_defaults();
133
134 $settings = wp_parse_args(
135 $attributes,
136 $defaults['headline']
137 );
138
139 $id = $attributes['uniqueId'];
140 $blockVersion = ! empty( $settings['blockVersion'] ) ? $settings['blockVersion'] : 1;
141
142 // Map deprecated settings.
143 $settings = GenerateBlocks_Map_Deprecated_Attributes::map_attributes( $settings );
144
145 $selector = generateblocks_get_css_selector( 'headline', $attributes );
146
147 // Back-compatibility for when icon held a value.
148 if ( $settings['icon'] ) {
149 $settings['hasIcon'] = true;
150 }
151
152 // Only add this CSS once.
153 if ( ! self::$singular_css_added ) {
154 $css->set_selector( '.gb-icon svg' );
155 $css->add_property( 'fill', 'currentColor' );
156
157 $css->set_selector( '.gb-highlight' );
158 $css->add_property( 'background', 'none' );
159 $css->add_property( 'color', 'unset' );
160
161 do_action(
162 'generateblocks_block_one_time_css_data',
163 'headline',
164 $settings,
165 $css
166 );
167
168 self::$singular_css_added = true;
169 }
170
171 if ( ! isset( $attributes['hasWrapper'] ) ) {
172 $css->set_selector( $selector );
173 generateblocks_add_layout_css( $css, $settings );
174 generateblocks_add_sizing_css( $css, $settings );
175 generateblocks_add_flex_child_css( $css, $settings );
176 generateblocks_add_typography_css( $css, $settings );
177 generateblocks_add_spacing_css( $css, $settings );
178 generateblocks_add_border_css( $css, $settings );
179 $css->add_property( 'color', $settings['textColor'] );
180 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
181
182 if ( $blockVersion < 2 && $settings['inlineWidth'] ) {
183 if ( $settings['hasIcon'] ) {
184 $css->add_property( 'display', 'inline-flex' );
185 } else {
186 $css->add_property( 'display', 'inline-block' );
187 }
188 }
189
190 if ( $blockVersion < 2 && $settings['hasIcon'] ) {
191 if ( ! $settings['inlineWidth'] ) {
192 $css->add_property( 'display', 'flex' );
193 }
194
195 if ( 'above' === $settings['iconLocation'] ) {
196 $css->add_property( 'text-align', $settings['alignment'] );
197 } else {
198 $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
199 }
200
201 if ( 'inline' === $settings['iconLocation'] ) {
202 $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignment'] ) );
203 }
204
205 if ( 'above' === $settings['iconLocation'] ) {
206 $css->add_property( 'flex-direction', 'column' );
207 }
208 }
209
210 $css->set_selector( $selector . ' a' );
211 $css->add_property( 'color', $settings['linkColor'] );
212
213 $css->set_selector( $selector . ' a:hover' );
214 $css->add_property( 'color', $settings['linkColorHover'] );
215
216 if ( $settings['hasIcon'] ) {
217 $css->set_selector( $selector . ' .gb-icon' );
218 $css->add_property( 'line-height', '0' );
219 $css->add_property( 'color', generateblocks_hex2rgba( $settings['iconColor'], $settings['iconColorOpacity'] ) );
220
221 if ( ! $settings['removeText'] ) {
222 if ( $blockVersion < 3 ) {
223 // Need to check for blockVersion here instead of mapping as iconPaddingRight has a default.
224 $css->add_property( 'padding', array( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'] ), $settings['iconPaddingUnit'] );
225 } else {
226 $css->add_property(
227 'padding',
228 array(
229 generateblocks_get_array_attribute_value( 'paddingTop', $settings['iconStyles'] ),
230 generateblocks_get_array_attribute_value( 'paddingRight', $settings['iconStyles'] ),
231 generateblocks_get_array_attribute_value( 'paddingBottom', $settings['iconStyles'] ),
232 generateblocks_get_array_attribute_value( 'paddingLeft', $settings['iconStyles'] ),
233 )
234 );
235 }
236 }
237
238 if ( $blockVersion < 2 ) {
239 if ( 'above' === $settings['iconLocation'] ) {
240 $css->add_property( 'display', 'inline' );
241 } else {
242 $css->add_property( 'display', 'inline-flex' );
243 }
244 }
245
246 $css->set_selector( $selector . ' .gb-icon svg' );
247
248 if ( $blockVersion < 3 ) {
249 $css->add_property( 'width', $settings['iconSize'], $settings['iconSizeUnit'] );
250 $css->add_property( 'height', $settings['iconSize'], $settings['iconSizeUnit'] );
251 }
252
253 $css->add_property( 'width', generateblocks_get_array_attribute_value( 'width', $settings['iconStyles'] ) );
254 $css->add_property( 'height', generateblocks_get_array_attribute_value( 'height', $settings['iconStyles'] ) );
255 }
256
257 if ( $settings['highlightTextColor'] ) {
258 $css->set_selector( $selector . ' .gb-highlight' );
259 $css->add_property( 'color', $settings['highlightTextColor'] );
260 }
261
262 $tablet_css->set_selector( $selector );
263 generateblocks_add_layout_css( $tablet_css, $settings, 'Tablet' );
264 generateblocks_add_sizing_css( $tablet_css, $settings, 'Tablet' );
265 generateblocks_add_flex_child_css( $tablet_css, $settings, 'Tablet' );
266 generateblocks_add_typography_css( $tablet_css, $settings, 'Tablet' );
267 generateblocks_add_spacing_css( $tablet_css, $settings, 'Tablet' );
268 generateblocks_add_border_css( $tablet_css, $settings, 'Tablet' );
269
270 if ( $blockVersion < 2 && $settings['inlineWidthTablet'] ) {
271 if ( $settings['hasIcon'] ) {
272 $tablet_css->add_property( 'display', 'inline-flex' );
273 } else {
274 $tablet_css->add_property( 'display', 'inline-block' );
275 }
276 }
277
278 if ( $settings['hasIcon'] ) {
279 if ( $blockVersion < 2 ) {
280 $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
281
282 if ( 'inline' === $settings['iconLocationTablet'] ) {
283 $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentTablet'] ) );
284 }
285
286 if ( 'above' === $settings['iconLocationTablet'] ) {
287 $tablet_css->add_property( 'flex-direction', 'column' );
288 }
289 }
290
291 $tablet_css->set_selector( $selector . ' .gb-icon' );
292
293 if ( ! $settings['removeText'] ) {
294 if ( $blockVersion < 3 ) {
295 $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] );
296 } else {
297 $tablet_css->add_property(
298 'padding',
299 array(
300 generateblocks_get_array_attribute_value( 'paddingTopTablet', $settings['iconStyles'] ),
301 generateblocks_get_array_attribute_value( 'paddingRightTablet', $settings['iconStyles'] ),
302 generateblocks_get_array_attribute_value( 'paddingBottomTablet', $settings['iconStyles'] ),
303 generateblocks_get_array_attribute_value( 'paddingLeftTablet', $settings['iconStyles'] ),
304 )
305 );
306 }
307 }
308
309 if ( $blockVersion < 2 ) {
310 if ( 'above' === $settings['iconLocationTablet'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationTablet'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
311 $tablet_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
312 }
313
314 if ( 'above' === $settings['iconLocationTablet'] ) {
315 $tablet_css->add_property( 'display', 'inline' );
316 }
317 }
318
319 $tablet_css->set_selector( $selector . ' .gb-icon svg' );
320
321 if ( $blockVersion < 3 ) {
322 $tablet_css->add_property( 'width', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
323 $tablet_css->add_property( 'height', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
324 }
325
326 $tablet_css->add_property( 'width', generateblocks_get_array_attribute_value( 'widthTablet', $settings['iconStyles'] ) );
327 $tablet_css->add_property( 'height', generateblocks_get_array_attribute_value( 'heightTablet', $settings['iconStyles'] ) );
328 }
329
330 $mobile_css->set_selector( $selector );
331 generateblocks_add_layout_css( $mobile_css, $settings, 'Mobile' );
332 generateblocks_add_sizing_css( $mobile_css, $settings, 'Mobile' );
333 generateblocks_add_flex_child_css( $mobile_css, $settings, 'Mobile' );
334 generateblocks_add_typography_css( $mobile_css, $settings, 'Mobile' );
335 generateblocks_add_spacing_css( $mobile_css, $settings, 'Mobile' );
336 generateblocks_add_border_css( $mobile_css, $settings, 'Mobile' );
337
338 if ( $blockVersion < 2 && $settings['inlineWidthMobile'] ) {
339 if ( $settings['hasIcon'] ) {
340 $mobile_css->add_property( 'display', 'inline-flex' );
341 } else {
342 $mobile_css->add_property( 'display', 'inline-block' );
343 }
344 }
345
346 if ( $settings['hasIcon'] ) {
347 if ( $blockVersion < 2 ) {
348 $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
349
350 if ( 'inline' === $settings['iconLocationMobile'] ) {
351 $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentMobile'] ) );
352 }
353
354 if ( 'above' === $settings['iconLocationMobile'] ) {
355 $mobile_css->add_property( 'flex-direction', 'column' );
356 }
357 }
358
359 $mobile_css->set_selector( $selector . ' .gb-icon' );
360
361 if ( ! $settings['removeText'] ) {
362 if ( $blockVersion < 3 ) {
363 $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] );
364 } else {
365 $mobile_css->add_property(
366 'padding',
367 array(
368 generateblocks_get_array_attribute_value( 'paddingTopMobile', $settings['iconStyles'] ),
369 generateblocks_get_array_attribute_value( 'paddingRightMobile', $settings['iconStyles'] ),
370 generateblocks_get_array_attribute_value( 'paddingBottomMobile', $settings['iconStyles'] ),
371 generateblocks_get_array_attribute_value( 'paddingLeftMobile', $settings['iconStyles'] ),
372 )
373 );
374 }
375 }
376
377 if ( $blockVersion < 2 ) {
378 if ( 'above' === $settings['iconLocationMobile'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationMobile'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
379 $mobile_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
380 }
381
382 if ( 'above' === $settings['iconLocationMobile'] ) {
383 $mobile_css->add_property( 'display', 'inline' );
384 }
385 }
386
387 $mobile_css->set_selector( $selector . ' .gb-icon svg' );
388
389 if ( $blockVersion < 3 ) {
390 $mobile_css->add_property( 'width', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
391 $mobile_css->add_property( 'height', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
392 }
393
394 $mobile_css->add_property( 'width', generateblocks_get_array_attribute_value( 'widthMobile', $settings['iconStyles'] ) );
395 $mobile_css->add_property( 'height', generateblocks_get_array_attribute_value( 'heightMobile', $settings['iconStyles'] ) );
396 }
397 } else {
398 // The below CSS is for users using the old headline wrapper.
399 $css->set_selector( '.gb-headline-wrapper' );
400 $css->add_property( 'display', 'flex' );
401
402 $css->set_selector( '.gb-headline-wrapper > .gb-headline' );
403 $css->add_property( 'margin', '0' );
404 $css->add_property( 'padding', '0' );
405
406 $css->set_selector( '.gb-headline-' . $id );
407 $css->add_property( 'font-family', $fontFamily );
408 $css->add_property( 'text-align', $settings['alignment'] );
409 $css->add_property( 'color', $settings['textColor'] );
410
411 if ( ! $settings['hasIcon'] ) {
412 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
413
414 if ( $settings['inlineWidth'] ) {
415 $css->add_property( 'display', 'inline-block' );
416 }
417
418 $css->add_property( 'border-width', array( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'] ), 'px' );
419 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
420 }
421
422 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
423 $css->add_property( 'font-weight', $settings['fontWeight'] );
424 $css->add_property( 'text-transform', $settings['textTransform'] );
425 $css->add_property( 'line-height', $settings['lineHeight'], $settings['lineHeightUnit'] );
426 $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' );
427
428 if ( ! $settings['hasIcon'] ) {
429 $css->add_property( 'padding', array( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'] ), $settings['paddingUnit'] );
430 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
431
432 if ( function_exists( 'generate_get_default_fonts' ) && '' === $settings['marginBottom'] ) {
433 $defaultBlockStyles = generateblocks_get_default_styles();
434
435 if ( isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) {
436 $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
437 }
438 }
439 }
440
441 $css->set_selector( '.gb-headline-' . $id . ' a, .gb-headline-' . $id . ' a:visited' );
442 $css->add_property( 'color', $settings['linkColor'] );
443
444 $css->set_selector( '.gb-headline-' . $id . ' a:hover' );
445 $css->add_property( 'color', $settings['linkColorHover'] );
446
447 if ( $settings['hasIcon'] ) {
448 $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
449 $css->add_property( 'line-height', '0' );
450
451 if ( ! $settings['removeText'] ) {
452 $css->add_property( 'padding', array( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'] ), $settings['iconPaddingUnit'] );
453 }
454
455 $css->add_property( 'color', generateblocks_hex2rgba( $settings['iconColor'], $settings['iconColorOpacity'] ) );
456
457 if ( 'above' === $settings['iconLocation'] ) {
458 $css->add_property( 'display', 'inline' );
459 }
460
461 $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
462 $css->add_property( 'width', $settings['iconSize'], $settings['iconSizeUnit'] );
463 $css->add_property( 'height', $settings['iconSize'], $settings['iconSizeUnit'] );
464
465 $css->set_selector( '.gb-headline-wrapper-' . $id );
466 $css->add_property( 'padding', array( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'] ), $settings['paddingUnit'] );
467 $css->add_property( 'margin', array( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'] ), $settings['marginUnit'] );
468
469 $defaultBlockStyles = generateblocks_get_default_styles();
470
471 if ( '' === $settings['marginBottom'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) {
472 $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
473 }
474
475 if ( '' === $settings['fontSize'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'] ) ) {
476 $css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
477 } else {
478 $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] );
479 }
480
481 if ( 'above' === $settings['iconLocation'] ) {
482 $css->add_property( 'text-align', $settings['alignment'] );
483 } else {
484 $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) );
485 }
486
487 if ( $settings['inlineWidth'] ) {
488 $css->add_property( 'display', 'inline-flex' );
489 }
490
491 if ( 'inline' === $settings['iconLocation'] ) {
492 $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignment'] ) );
493 }
494
495 $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) );
496 $css->add_property( 'color', $settings['textColor'] );
497 $css->add_property( 'border-width', array( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'] ), 'px' );
498 $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) );
499
500 if ( 'above' === $settings['iconLocation'] ) {
501 $css->add_property( 'flex-direction', 'column' );
502 }
503 }
504
505 if ( $settings['highlightTextColor'] ) {
506 $css->set_selector( '.gb-headline-' . $id . ' .gb-highlight' );
507 $css->add_property( 'color', $settings['highlightTextColor'] );
508 }
509
510 $tablet_css->set_selector( '.gb-headline-' . $id );
511 $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] );
512 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
513 $tablet_css->add_property( 'line-height', $settings['lineHeightTablet'], $settings['lineHeightUnit'] );
514 $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' );
515
516 if ( ! $settings['hasIcon'] ) {
517 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
518 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
519 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
520
521 if ( $settings['inlineWidthTablet'] ) {
522 $tablet_css->add_property( 'display', 'inline-flex' );
523 }
524 }
525
526 if ( $settings['hasIcon'] ) {
527 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
528
529 if ( ! $settings['removeText'] ) {
530 $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] );
531 }
532
533 if ( 'above' === $settings['iconLocationTablet'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationTablet'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
534 $tablet_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
535 }
536
537 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
538 $tablet_css->add_property( 'width', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
539 $tablet_css->add_property( 'height', $settings['iconSizeTablet'], $settings['iconSizeUnit'] );
540
541 $tablet_css->set_selector( '.gb-headline-wrapper-' . $id );
542 $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] );
543 $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] );
544 $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' );
545 $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) );
546
547 $defaultBlockStyles = generateblocks_get_default_styles();
548
549 if ( '' === $settings['marginBottomTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) ) {
550 $tablet_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
551 }
552
553 if ( '' === $settings['fontSizeTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'] ) ) {
554 $tablet_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
555 } else {
556 $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] );
557 }
558
559 if ( $settings['inlineWidthTablet'] ) {
560 $tablet_css->add_property( 'display', 'inline-flex' );
561 }
562
563 if ( 'inline' === $settings['iconLocationTablet'] ) {
564 $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentTablet'] ) );
565 }
566
567 if ( 'above' === $settings['iconLocationTablet'] ) {
568 $tablet_css->add_property( 'flex-direction', 'column' );
569 }
570 }
571
572 $mobile_css->set_selector( '.gb-headline-' . $id );
573 $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] );
574 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
575 $mobile_css->add_property( 'line-height', $settings['lineHeightMobile'], $settings['lineHeightUnit'] );
576 $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' );
577
578 if ( ! $settings['hasIcon'] ) {
579 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
580 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
581 $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' );
582
583 if ( $settings['inlineWidthMobile'] ) {
584 $mobile_css->add_property( 'display', 'inline-flex' );
585 }
586 }
587
588 if ( $settings['hasIcon'] ) {
589 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' );
590
591 if ( ! $settings['removeText'] ) {
592 $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] );
593 }
594
595 if ( 'above' === $settings['iconLocationMobile'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationMobile'] ) || ( 'above' === $settings['iconLocationTablet'] && '' == $settings['iconLocationMobile'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
596 $mobile_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
597 }
598
599 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' );
600 $mobile_css->add_property( 'width', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
601 $mobile_css->add_property( 'height', $settings['iconSizeMobile'], $settings['iconSizeUnit'] );
602
603 $mobile_css->set_selector( '.gb-headline-wrapper-' . $id );
604 $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] );
605 $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] );
606 $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) );
607
608 $defaultBlockStyles = generateblocks_get_default_styles();
609
610 if ( '' === $settings['marginBottomMobile'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) ) {
611 $mobile_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] );
612 }
613
614 if ( '' === $settings['fontSizeMobile'] && ! $settings['removeText'] && ! empty( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'] ) ) {
615 $mobile_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] );
616 } else {
617 $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] );
618 }
619
620 if ( $settings['inlineWidthMobile'] ) {
621 $mobile_css->add_property( 'display', 'inline-flex' );
622 }
623
624 if ( 'inline' === $settings['iconLocationMobile'] ) {
625 $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentMobile'] ) );
626 }
627
628 if ( 'above' === $settings['iconLocationMobile'] ) {
629 $mobile_css->add_property( 'flex-direction', 'column' );
630 }
631 }
632 }
633
634 // Store this block ID in memory.
635 self::store_block_id( $id );
636
637 /**
638 * Do generateblocks_block_css_data hook
639 *
640 * @since 1.0
641 *
642 * @param string $name The name of our block.
643 * @param array $settings The settings for the current block.
644 * @param object $css Our desktop/main CSS data.
645 * @param object $desktop_css Our desktop only CSS data.
646 * @param object $tablet_css Our tablet CSS data.
647 * @param object $tablet_only_css Our tablet only CSS data.
648 * @param object $mobile_css Our mobile CSS data.
649 */
650 do_action(
651 'generateblocks_block_css_data',
652 'headline',
653 $settings,
654 $css,
655 $desktop_css,
656 $tablet_css,
657 $tablet_only_css,
658 $mobile_css
659 );
660
661 return [
662 'main' => $css->css_output(),
663 'desktop' => $desktop_css->css_output(),
664 'tablet' => $tablet_css->css_output(),
665 'tablet_only' => $tablet_only_css->css_output(),
666 'mobile' => $mobile_css->css_output(),
667 ];
668 }
669
670 /**
671 * Wrapper function for our dynamic buttons.
672 *
673 * @since 1.6.0
674 * @param array $attributes The block attributes.
675 * @param string $content The dynamic text to display.
676 * @param WP_Block $block Block instance.
677 */
678 public static function render_block( $attributes, $content, $block ) {
679 if ( strpos( trim( $content ), '<div class="gb-headline-wrapper' ) === 0 ) {
680 $attributes['hasWrapper'] = true;
681 }
682
683 if ( ! isset( $attributes['useDynamicData'] ) || ! $attributes['useDynamicData'] ) {
684 // Add styles to this block if needed.
685 $content = generateblocks_maybe_add_block_css(
686 $content,
687 [
688 'class_name' => 'GenerateBlocks_Block_Headline',
689 'attributes' => $attributes,
690 'block_ids' => self::$block_ids,
691 ]
692 );
693
694 return $content;
695 }
696
697 $allow_empty_content = false;
698
699 if ( empty( $attributes['dynamicContentType'] ) ) {
700 $dynamic_content = GenerateBlocks_Dynamic_Content::get_static_content( $content );
701
702 if ( ! empty( $attributes['hasIcon'] ) && ! empty( $attributes['removeText'] ) ) {
703 // Allow icon-only items to continue.
704 $allow_empty_content = true;
705 }
706 } else {
707 $dynamic_content = GenerateBlocks_Dynamic_Content::get_content( $attributes, $block );
708 }
709
710 if ( ! $dynamic_content && '0' !== $dynamic_content && ! $allow_empty_content ) {
711 return '';
712 }
713
714 $defaults = generateblocks_get_block_defaults();
715
716 $settings = wp_parse_args(
717 $attributes,
718 $defaults['headline']
719 );
720
721 $classNames = array(
722 'gb-headline',
723 'gb-headline-' . $settings['uniqueId'],
724 );
725
726 if ( ! empty( $settings['className'] ) ) {
727 $classNames[] = $settings['className'];
728 }
729
730 if ( empty( $settings['hasIcon'] ) ) {
731 $classNames[] = 'gb-headline-text';
732 }
733
734 $tagName = apply_filters(
735 'generateblocks_dynamic_headline_tagname',
736 $settings['element'],
737 $attributes,
738 $block
739 );
740
741 $allowedTagNames = apply_filters(
742 'generateblocks_dynamic_headline_allowed_tagnames',
743 array(
744 'h1',
745 'h2',
746 'h3',
747 'h4',
748 'h5',
749 'h6',
750 'div',
751 'p',
752 'figcaption',
753 ),
754 $attributes,
755 $block
756 );
757
758 if ( ! in_array( $tagName, $allowedTagNames ) ) {
759 $tagName = 'div';
760 }
761
762 // Add styles to this block if needed.
763 $output = generateblocks_maybe_add_block_css(
764 '',
765 [
766 'class_name' => 'GenerateBlocks_Block_Headline',
767 'attributes' => $attributes,
768 'block_ids' => self::$block_ids,
769 ]
770 );
771
772 $output .= sprintf(
773 '<%1$s %2$s>',
774 $tagName,
775 generateblocks_attr(
776 'dynamic-headline',
777 array(
778 'id' => isset( $settings['anchor'] ) ? $settings['anchor'] : null,
779 'class' => implode( ' ', $classNames ),
780 ),
781 $settings,
782 $block
783 )
784 );
785
786 $icon_html = '';
787
788 // Extract our icon from the static HTML.
789 if ( $settings['hasIcon'] ) {
790 $icon_html = GenerateBlocks_Dynamic_Content::get_icon_html( $content );
791
792 if ( $icon_html ) {
793 $output .= $icon_html;
794 $output .= '<span class="gb-headline-text">';
795 }
796 }
797
798 $dynamic_link = GenerateBlocks_Dynamic_Content::get_dynamic_url( $attributes, $block );
799
800 if ( $dynamic_link ) {
801 $dynamic_content = sprintf(
802 '<a href="%s">%s</a>',
803 $dynamic_link,
804 $dynamic_content
805 );
806 }
807
808 $output .= $dynamic_content;
809
810 if ( $icon_html ) {
811 $output .= '</span>';
812 }
813
814 $output .= sprintf(
815 '</%s>',
816 $tagName
817 );
818
819 return $output;
820 }
821 }
822