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