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