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