has_style ) { if ( ! wp_style_is( 'kadence-blocks-' . $this->block_name, 'enqueued' ) ) { $this->enqueue_style( 'kadence-blocks-' . $this->block_name ); if ( $inline ) { $this->should_render_inline_stylesheet( 'kadence-blocks-' . $this->block_name ); } } } if ( isset( $attributes['type'] ) && ( 'carousel' === $attributes['type'] || 'fluidcarousel' === $attributes['type'] || 'slider' === $attributes['type'] || 'thumbslider' === $attributes['type'] ) ) { $this->enqueue_style( 'kadence-blocks-splide' ); $this->should_render_inline_stylesheet( 'kadence-blocks-splide' ); $this->enqueue_script( 'kadence-blocks-splide-init' ); } elseif ( ! isset( $attributes['type'] ) || ( isset( $attributes['type'] ) && 'masonry' === $attributes['type'] ) ) { $this->enqueue_script( 'kadence-blocks-masonry-init' ); } if ( isset( $attributes['type'] ) && ( 'tiles' === $attributes['type'] || 'thumbslider' === $attributes['type'] ) ) { if ( wp_style_is( 'kadence-blocks-gallery-pro', 'registered' ) ) { $this->enqueue_style( 'kadence-blocks-gallery-pro' ); $this->should_render_inline_stylesheet( 'kadence-blocks-gallery-pro' ); } } if ( isset( $attributes['linkTo'] ) && 'media' == isset( $attributes['linkTo'] ) && isset( $attributes['lightbox'] ) && 'magnific' === $attributes['lightbox'] ) { $this->enqueue_style( 'kadence-glightbox' ); $this->should_render_inline_stylesheet( 'kadence-glightbox' ); $this->enqueue_script( 'kadence-blocks-glight-init' ); } } /** * Builds CSS for block. * * @param array $attributes the blocks attributes. * @param Kadence_Blocks_CSS $css the css class for blocks. * @param string $unique_id the blocks attr ID. * @param string $unique_style_id the blocks alternate ID for queries. */ public function build_css( $attributes, $css, $unique_id, $unique_style_id ) { $updated_version = ! empty( $attributes['kbVersion'] ) && $attributes['kbVersion'] > 1 ? true : false; $css->set_style_id( 'kb-' . $this->block_name . $unique_style_id ); $gallery_type = ! empty( $attributes['type'] ) ? $attributes['type'] : 'masonry'; $css->set_selector('.wp-block-kadence-advancedgallery.kb-gallery-wrap-id-' . $unique_id ); if ( isset( $attributes['margin'][0] ) ) { // Fix for this margin unit being in a non-standard locaiton in array, should be updated. $margin_unit = ( ! empty( $attributes['marginUnit'] ) ? $attributes['marginUnit'] : 'px' ); $css->render_measure_output( array_merge( $attributes['margin'][0], array( 'marginType' => $margin_unit ) ), 'margin', 'margin', array( 'desktop_key' => 'desk', 'tablet_key' => 'tablet', 'mobile_key' => 'mobile', ) ); } $css->render_measure_output( $attributes, 'padding', 'padding', array( 'unit_key' => 'paddingUnit', ) ); if ( isset( $attributes['type'] ) && 'carousel' === $attributes['type'] ) { $css->set_selector('.wp-block-kadence-advancedgallery.kb-gallery-wrap-id-' . $unique_id ); $css->add_property( 'overflow', 'hidden' ); } $desk_gutter = ( $css->is_number( $attributes['gutter'][0] ) ? $attributes['gutter'][0] : 10 ); $gutter_unit = ! empty( $attributes['gutterUnit'] ) ? $attributes['gutterUnit'] : 'px'; // Masonry. if ( 'masonry' === $gallery_type ) { $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-masonry.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $desk_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-masonry.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $desk_gutter / 2 ) . $gutter_unit ); } else if ( 'grid' === $gallery_type ) { // Grid. $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-grid.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $desk_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-grid.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $desk_gutter / 2 ) . $gutter_unit ); } else if ( 'tiles' === $gallery_type ) { // Tiles. $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-tiles.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $desk_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-tiles.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $desk_gutter / 2 ) . $gutter_unit ); } else if ( 'thumbslider' === $gallery_type ) { if ( $updated_version ) { // Thumbnail. $css->set_selector('.kb-gallery-type-thumbslider.kb-gallery-id-' . $unique_id . ' .kt-blocks-carousel-init '); $css->add_property('margin-bottom', $desk_gutter . $gutter_unit ); } } if ( $css->is_number( $attributes['gutter'][1] ) ) { $tablet_gutter = $attributes['gutter'][1]; $css->set_media_state( 'tablet'); // Masonry. if ( 'masonry' === $gallery_type ) { $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-masonry.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $tablet_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-masonry.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $tablet_gutter / 2 ) . $gutter_unit ); } else if ( 'grid' === $gallery_type ) { // Grid. $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-grid.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $tablet_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-grid.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $tablet_gutter / 2 ) . $gutter_unit ); } else if ( 'tiles' === $gallery_type ) { // Tiles. $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-tiles.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $tablet_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-tiles.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $tablet_gutter / 2 ) . $gutter_unit ); } else if ( 'thumbslider' === $gallery_type ) { if ( $updated_version ) { // Thumbnail. $css->set_selector('.kb-gallery-type-thumbslider.kb-gallery-id-' . $unique_id . ' .kt-blocks-carousel-init '); $css->add_property('margin-bottom', $tablet_gutter . $gutter_unit ); } } $css->set_media_state( 'desktop'); } if ( isset( $attributes['gutter'] ) && is_array( $attributes['gutter'] ) && isset( $attributes['gutter'][2] ) && is_numeric( $attributes['gutter'][2] ) ) { $css->set_media_state( 'mobile'); $mobile_gutter = $attributes['gutter'][2]; // Masonry. if ( 'masonry' === $gallery_type ) { $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-masonry.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $mobile_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-masonry.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $mobile_gutter / 2 ) . $gutter_unit ); } else if ( 'grid' === $gallery_type ) { // Grid. $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-grid.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $mobile_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-grid.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $mobile_gutter / 2 ) . $gutter_unit ); } else if ( 'tiles' === $gallery_type ) { // Tiles. $css->set_selector('.wp-block-kadence-advancedgallery .kb-gallery-type-tiles.kb-gallery-id-' . $unique_id ); $css->add_property('margin','-' . ( $mobile_gutter / 2 ) . $gutter_unit ); $css->set_selector('.kb-gallery-type-tiles.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item' ); $css->add_property('padding', ( $mobile_gutter / 2 ) . $gutter_unit ); } else if ( 'thumbslider' === $gallery_type ) { if ( $updated_version ) { // Thumbnail. $css->set_selector('.kb-gallery-type-thumbslider.kb-gallery-id-' . $unique_id . ' .kt-blocks-carousel-init '); $css->add_property('margin-bottom', $mobile_gutter . $gutter_unit ); } } $css->set_media_state( 'desktop'); } if ( isset( $attributes['type'] ) && 'fluidcarousel' === $attributes['type'] && isset( $attributes['carouselHeight'] ) && is_array( $attributes['carouselHeight'] ) ) { if ( isset( $attributes['carouselHeight'][0] ) && is_numeric( $attributes['carouselHeight'][0] ) ) { $css->set_selector('.kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-fluidcarousel .kt-blocks-carousel figure .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-fluidcarousel .kt-blocks-carousel figure .kb-gal-image-radius img' ); $css->add_property('height', $attributes['carouselHeight'][0] . 'px' ); } if ( isset( $attributes['carouselHeight'][1] ) && is_numeric( $attributes['carouselHeight'][1] ) ) { $css->set_media_state( 'tablet' ); $css->set_selector('.kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-fluidcarousel .kt-blocks-carousel figure .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-fluidcarousel .kt-blocks-carousel figure .kb-gal-image-radius img' ); $css->add_property('height', $attributes['carouselHeight'][1] . 'px' ); } if ( isset( $attributes['carouselHeight'][2] ) && is_numeric( $attributes['carouselHeight'][2] ) ) { $css->set_media_state( 'mobile'); $css->set_selector('.kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-fluidcarousel .kt-blocks-carousel figure .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-fluidcarousel .kt-blocks-carousel figure .kb-gal-image-radius img' ); $css->add_property('height', $attributes['carouselHeight'][2] . 'px' ); } $css->set_media_state( 'desktop'); } if ( isset( $attributes['type'] ) && 'tiles' === $attributes['type'] && isset( $attributes['carouselHeight'] ) && is_array( $attributes['carouselHeight'] ) ) { if ( isset( $attributes['carouselHeight'][0] ) && is_numeric( $attributes['carouselHeight'][0] ) ) { $css->set_selector('.kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-tiles .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner img, .kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-tiles > .kadence-blocks-gallery-item' ); $css->add_property('height', $attributes['carouselHeight'][0] . 'px' ); } if ( isset( $attributes['carouselHeight'][1] ) && is_numeric( $attributes['carouselHeight'][1] ) ) { $css->set_media_state( 'tablet' ); $css->set_selector('.kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-tiles .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner img, .kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-tiles > .kadence-blocks-gallery-item' ); $css->add_property('height', $attributes['carouselHeight'][1] . 'px' ); } if ( isset( $attributes['carouselHeight'][2] ) && is_numeric( $attributes['carouselHeight'][2] ) ) { $css->set_media_state('mobile'); $css->set_selector('.kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-tiles .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner img, .kb-gallery-id-' . $unique_id . '.kb-gallery-ul.kb-gallery-type-tiles > .kadence-blocks-gallery-item' ); $css->add_property('height', $attributes['carouselHeight'][2] . 'px' ); } $css->set_media_state( 'desktop'); } $imageRadiusUnit = isset($attributes['imageRadiusUnit']) ? $attributes['imageRadiusUnit'] : 'px'; if ( isset( $attributes['imageRadius'] ) && is_array( $attributes['imageRadius'] ) && isset( $attributes['imageRadius'][0] ) && is_numeric( $attributes['imageRadius'][0] ) ) { $css->set_selector('.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . ' .kb-slide-item .kb-gal-image-radius img' ); $css->add_property('border-radius', $attributes['imageRadius'][0] . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['imageRadius'][1] ) ? $attributes['imageRadius'][1] : 0 ) . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['imageRadius'][2] ) ? $attributes['imageRadius'][2] : 0 ) . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['imageRadius'][3] ) ? $attributes['imageRadius'][3] : 0 ) . $imageRadiusUnit . ';' ); } if ( isset( $attributes['tabletImageRadius'] ) && is_array( $attributes['tabletImageRadius'] ) && isset( $attributes['tabletImageRadius'][0] ) && is_numeric( $attributes['tabletImageRadius'][0] ) ) { $css->set_media_state( 'tablet' ); $css->set_selector('.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . ' .kb-slide-item .kb-gal-image-radius img' ); $css->add_property('border-radius', $attributes['tabletImageRadius'][0] . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['tabletImageRadius'][1] ) ? $attributes['tabletImageRadius'][1] : 0 ) . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['tabletImageRadius'][2] ) ? $attributes['tabletImageRadius'][2] : 0 ) . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['tabletImageRadius'][3] ) ? $attributes['tabletImageRadius'][3] : 0 ) . $imageRadiusUnit . ';' ); } if ( isset( $attributes['mobileImageRadius'] ) && is_array( $attributes['mobileImageRadius'] ) && isset( $attributes['mobileImageRadius'][0] ) && is_numeric( $attributes['mobileImageRadius'][0] ) ) { $css->set_media_state( 'mobile' ); $css->set_selector('.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . ' .kb-slide-item .kb-gal-image-radius img' ); $css->add_property('border-radius', $attributes['mobileImageRadius'][0] . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['mobileImageRadius'][1] ) ? $attributes['mobileImageRadius'][1] : 0 ) . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['mobileImageRadius'][2] ) ? $attributes['mobileImageRadius'][2] : 0 ) . $imageRadiusUnit . ' ' . ( is_numeric( $attributes['mobileImageRadius'][3] ) ? $attributes['mobileImageRadius'][3] : 0 ) . $imageRadiusUnit . ';' ); } $css->set_media_state( 'desktop' ); if ( isset( $attributes['displayShadow'] ) && ! empty( $attributes['displayShadow'] ) && true === $attributes['displayShadow'] && ( (isset( $attributes['type'] ) && $attributes['type'] !== 'mosaic') || ! isset( $attributes['type'] ) ) ) { $css->set_selector('.wp-block-kadence-advancedgallery.kb-gallery-wrap-id-' . $unique_id ); $css->add_property('overflow', 'visible' ); if ( ! isset( $attributes['shadow'] ) ) { $attributes['shadow'] = array(); $attributes['shadow'][0] = array( 'hOffset' => 4, 'vOffset'=> 2, 'blur' => 14, 'spread' => 0, 'color' => '#000000', 'opacity' => 0.2 ); } if ( isset( $attributes['shadow'] ) && is_array( $attributes['shadow'] ) && is_array( $attributes['shadow'][ 0 ] ) ) { $shadow = $attributes['shadow'][ 0 ]; $css->set_selector('.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-thumb-item .kb-gal-image-radius' ); $css->add_property('box-shadow', $shadow['hOffset'] . 'px ' . $shadow['vOffset'] . 'px ' . $shadow['blur'] . 'px ' . $shadow['spread'] . 'px ' . $css->render_color( $shadow['color'], $shadow['opacity'] ) ); } if ( isset( $attributes['shadowHover'] ) && is_array( $attributes['shadowHover'] ) && is_array( $attributes['shadowHover'][ 0 ] ) ) { $shadow_hover = $attributes['shadowHover'][ 0 ]; $css->set_selector('.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item:hover .kb-gal-image-radius, .kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-thumb-item:hover .kb-gal-image-radius' ); $css->add_property('box-shadow', $shadow_hover['hOffset'] . 'px ' . $shadow_hover['vOffset'] . 'px ' . $shadow_hover['blur'] . 'px ' . $shadow_hover['spread'] . 'px ' . $css->render_color( $shadow_hover['color'], $shadow_hover['opacity'] ) ); } else { $css->set_selector('.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item:hover .kb-gal-image-radius' ); $css->add_property('box-shadow', '4px 2px 14px 0px rgba(0,0,0,0.2)' ); } } if ( isset( $attributes['showCaption'] ) && true === $attributes['showCaption'] && isset( $attributes['captionStyles'] ) && is_array( $attributes['captionStyles'] ) && is_array( $attributes['captionStyles'][0] ) ) { $caption_font = [ 'caption' => $attributes['captionStyles'][0] ]; $css->set_selector('.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner .kadence-blocks-gallery-item__caption' ); $css->render_typography( $caption_font, 'caption'); if ( isset( $caption_font['caption']['background'] ) && ! empty( $caption_font['caption']['background'] ) ) { // Caption background color if( empty( $attributes['captionStyle'] ) || ( ! empty( $attributes['captionStyle'] ) && ( 'bottom' === $attributes['captionStyle'] || 'bottom-hover' === $attributes['captionStyle'] ) ) ) { $css->set_selector('.kb-gallery-caption-style-bottom.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner .kadence-blocks-gallery-item__caption, .kb-gallery-caption-style-bottom-hover.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner .kadence-blocks-gallery-item__caption' ); $css->add_property('background', 'linear-gradient(0deg, '. $css->render_color( $caption_font['caption']['background'], ( isset( $caption_font['caption']['backgroundOpacity'] ) && is_numeric( $caption_font['caption']['backgroundOpacity'] ) ) ? $caption_font['caption']['backgroundOpacity'] : '0.8' ) .' 0, rgba(0, 0, 0, 0) 100%)'); } else { $css->set_selector('.kb-gallery-caption-style-cover-hover.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner .kadence-blocks-gallery-item__caption, .kb-gallery-caption-style-below.kb-gallery-id-' . $unique_id . ' .kadence-blocks-gallery-item .kadence-blocks-gallery-item-inner .kadence-blocks-gallery-item__caption' ); $css->add_property('background', $css->render_color( $caption_font['caption']['background'], ( isset( $caption_font['caption']['backgroundOpacity'] ) && is_numeric( $caption_font['caption']['backgroundOpacity'] ) ) ? $caption_font['caption']['backgroundOpacity'] : '0.8' ) ); } } } $gallery_type = ! empty( $attributes['type'] ) ? $attributes['type'] : 'masonry'; // Add CSS for the grid-pattern-container class. if ( 'mosaic' === $gallery_type ) { $css->set_selector('.kb-gallery-wrap-id-' . $unique_id . ' .kb-gallery-ul.kb-gallery-type-mosaic .grid-pattern-container'); $css->render_responsive_range( $attributes, 'mosaicRowHeight', 'grid-auto-rows', 'mosaicRowHeightUnit', ); $css->render_responsive_range( $attributes, 'gutter', 'grid-gap', 'gutterUnit', ); $css->render_responsive_range( $attributes, 'gutter', 'gap', 'gutterUnit', ); } // Overflow for carousel if ( 'carousel' === $gallery_type && ( isset( $attributes['overflow'] ) && $attributes['overflow'] ) ) { $css->set_selector('.kb-gallery-wrap-id-' . $unique_id . '.wp-block-kadence-advancedgallery'); $css->add_property('overflow', 'visible' ); $css->set_selector('.kb-gallery-wrap-id-' . $unique_id . '.wp-block-kadence-advancedgallery .kt-blocks-carousel'); $css->add_property('overflow', 'visible' ); $css->set_selector('.kb-gallery-wrap-id-' . $unique_id . '.wp-block-kadence-advancedgallery .kt-blocks-carousel .splide__track'); $css->add_property('overflow', 'visible' ); $css->set_selector('.kb-gallery-wrap-id-' . $unique_id . '.wp-block-kadence-advancedgallery .kt-blocks-carousel .splide__pagination'); $css->add_property('overflow', 'hidden' ); } if ( 'carousel' === $gallery_type || 'fluidcarousel' === $gallery_type || 'slider' === $gallery_type ) { $css->set_selector('.kb-gallery-wrap-id-' . $unique_id . '.wp-block-kadence-advancedgallery'); $css->add_property('overflow', 'visible' ); $css->set_selector('.kb-gallery-wrap-id-' . $unique_id . '.wp-block-kadence-advancedgallery .kt-blocks-carousel'); $css->add_property('overflow', 'visible' ); if ( 'fluidcarousel' === $gallery_type ) { $css->add_property('max-width', '100%' ); } } // Pro Arrow Settings if ( ! empty( $attributes['arrowSize'][0] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__arrow' ); $css->add_property( 'font-size', $css->get_font_size( $attributes['arrowSize'][0], ( ! empty( $attributes['arrowSizeUnit'] ) ? $attributes['arrowSizeUnit'] : 'px' ) ) ); } if ( ! empty( $attributes['arrowSize'][1] ) ) { $css->set_media_state( 'tablet' ); $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__arrow' ); $css->add_property( 'font-size', $css->get_font_size( $attributes['arrowSize'][1], ( ! empty( $attributes['arrowSizeUnit'] ) ? $attributes['arrowSizeUnit'] : 'px' ) ) ); } if ( ! empty( $attributes['arrowSize'][2] ) ) { $css->set_media_state( 'mobile' ); $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__arrow' ); $css->add_property( 'font-size', $css->get_font_size( $attributes['arrowSize'][2], ( ! empty( $attributes['arrowSizeUnit'] ) ? $attributes['arrowSizeUnit'] : 'px' ) ) ); } if ( ! empty( $attributes['arrowPosition'] ) && 'center' !== $attributes['arrowPosition'] && 'outside-top' !== $attributes['arrowPosition'] && 'outside-bottom' !== $attributes['arrowPosition'] ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__arrows' ); } else { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__arrow' ); } $css->render_measure_output( $attributes, 'arrowMargin', 'margin', array( 'unit_key' => 'arrowMarginUnit' ) ); $is_carousel = ( isset( $attributes['type'] ) && ( 'carousel' === $attributes['type'] || 'fluidcarousel' === $attributes['type'] || 'slider' === $attributes['type'] || 'thumbslider' === $attributes['type'] ) ); // Arrow Custom Color if ( ! empty( $attributes['arrowCustomColor'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow' ); $css->add_property( 'color', $css->render_color( $attributes['arrowCustomColor'] ) ); } if ( ! empty( $attributes['arrowCustomColorHover'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow:hover' ); $css->add_property( 'color', $css->render_color( $attributes['arrowCustomColorHover'] ) ); } if ( ! empty( $attributes['arrowCustomColorActive'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow:active' ); $css->add_property( 'color', $css->render_color( $attributes['arrowCustomColorActive'] ) ); } if ( ! empty( $attributes['arrowCustomColorBackground'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow' ); $css->add_property( 'background-color', $css->render_color( $attributes['arrowCustomColorBackground'] ) ); } if ( ! empty( $attributes['arrowCustomColorBackgroundHover'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow:hover' ); $css->add_property( 'background-color', $css->render_color( $attributes['arrowCustomColorBackgroundHover'] ) ); } if ( ! empty( $attributes['arrowCustomColorBackgroundActive'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow:active' ); $css->add_property( 'background-color', $css->render_color( $attributes['arrowCustomColorBackgroundActive'] ) ); } if ( ! empty( $attributes['arrowCustomColorBorder'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow' ); $css->add_property( 'border-color', $css->render_color( $attributes['arrowCustomColorBorder'] ) ); } if ( ! empty( $attributes['arrowCustomColorBorderHover'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow:hover' ); $css->add_property( 'border-color', $css->render_color( $attributes['arrowCustomColorBorderHover'] ) ); } if ( ! empty( $attributes['arrowCustomColorBorderActive'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow:active' ); $css->add_property( 'border-color', $css->render_color( $attributes['arrowCustomColorBorderActive'] ) ); } if ( ! empty( $attributes['arrowCustomBorderWidth'] ) && $is_carousel ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide .splide__arrow' ); $css->add_property( 'border-width', $attributes['arrowCustomBorderWidth'] . 'px' ); } // Apply same custom arrow styles to pause button when arrowStyle is 'custom' if ( ! empty( $attributes['arrowStyle'] ) && 'custom' === $attributes['arrowStyle'] && $is_carousel ) { // Pause button color styles if ( ! empty( $attributes['arrowCustomColor'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button' ); $css->add_property( 'color', $css->render_color( $attributes['arrowCustomColor'] ) ); } if ( ! empty( $attributes['arrowCustomColorHover'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button:hover' ); $css->add_property( 'color', $css->render_color( $attributes['arrowCustomColorHover'] ) ); } if ( ! empty( $attributes['arrowCustomColorActive'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button:active' ); $css->add_property( 'color', $css->render_color( $attributes['arrowCustomColorActive'] ) ); } // Pause button background styles if ( ! empty( $attributes['arrowCustomColorBackground'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button' ); $css->add_property( 'background-color', $css->render_color( $attributes['arrowCustomColorBackground'] ) ); } if ( ! empty( $attributes['arrowCustomColorBackgroundHover'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button:hover' ); $css->add_property( 'background-color', $css->render_color( $attributes['arrowCustomColorBackgroundHover'] ) ); } if ( ! empty( $attributes['arrowCustomColorBackgroundActive'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button:active' ); $css->add_property( 'background-color', $css->render_color( $attributes['arrowCustomColorBackgroundActive'] ) ); } // Pause button border styles if ( ! empty( $attributes['arrowCustomColorBorder'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button' ); $css->add_property( 'border-color', $css->render_color( $attributes['arrowCustomColorBorder'] ) ); } if ( ! empty( $attributes['arrowCustomColorBorderHover'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button:hover' ); $css->add_property( 'border-color', $css->render_color( $attributes['arrowCustomColorBorderHover'] ) ); } if ( ! empty( $attributes['arrowCustomColorBorderActive'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button:active' ); $css->add_property( 'border-color', $css->render_color( $attributes['arrowCustomColorBorderActive'] ) ); } if ( ! empty( $attributes['arrowCustomBorderWidth'] ) ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .kb-gallery-pause-button' ); $css->add_property( 'border-width', $attributes['arrowCustomBorderWidth'] . 'px' ); $css->add_property( 'border-style', 'solid' ); } } // Dot Style - Built-in styles (light, outlinedark, outlinelight, dark) $dot_style = ( ! empty( $attributes['dotStyle'] ) ? $attributes['dotStyle'] : 'dark' ); if ( 'custom' !== $dot_style && $is_carousel ) { if ( 'light' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide.kt-carousel-dotstyle-light .splide__pagination__page, .kb-gallery-id-' . $unique_id . ' .splide.kt-carousel-dotstyle-light .splide__pagination__page.is-active' ); $css->add_property( 'background-color', '#fff' ); } elseif ( 'outlinedark' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide.kt-carousel-dotstyle-outlinedark .splide__pagination__page' ); $css->add_property( 'background-color', 'transparent' ); $css->add_property( 'box-shadow', 'inset 0 0 0 1px #000' ); $css->add_property( 'transition', 'box-shadow 0.3s ease' ); $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide.kt-carousel-dotstyle-outlinedark .splide__pagination__page.is-active' ); $css->add_property( 'background-color', 'transparent' ); $css->add_property( 'box-shadow', 'inset 0 0 0 8px #000' ); } elseif ( 'outlinelight' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide.kt-carousel-dotstyle-outlinelight .splide__pagination__page' ); $css->add_property( 'background-color', 'transparent' ); $css->add_property( 'box-shadow', 'inset 0 0 0 1px #fff' ); $css->add_property( 'transition', 'box-shadow 0.3s ease' ); $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide.kt-carousel-dotstyle-outlinelight .splide__pagination__page.is-active' ); $css->add_property( 'background-color', 'transparent' ); $css->add_property( 'box-shadow', 'inset 0 0 0 8px #fff' ); } // Dark is the default, so no special CSS needed } // Dot Custom Color if ( ! empty( $attributes['dotCustomColor'] ) && $is_carousel && 'custom' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__pagination__page' ); $css->add_property( 'background-color', $css->render_color( $attributes['dotCustomColor'] ) ); } if ( ! empty( $attributes['dotCustomColorHover'] ) && $is_carousel && 'custom' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__pagination__page:hover' ); $css->add_property( 'background-color', $css->render_color( $attributes['dotCustomColorHover'] ) ); } if ( ! empty( $attributes['dotCustomColorActive'] ) && $is_carousel && 'custom' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__pagination__page.is-active' ); $css->add_property( 'background-color', $css->render_color( $attributes['dotCustomColorActive'] ) ); } if ( ! empty( $attributes['dotCustomColorBorder'] ) && $is_carousel && 'custom' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__pagination__page' ); $css->add_property( 'border-color', $css->render_color( $attributes['dotCustomColorBorder'] ) ); } if ( ! empty( $attributes['dotCustomColorBorderHover'] ) && $is_carousel && 'custom' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__pagination__page:hover' ); $css->add_property( 'border-color', $css->render_color( $attributes['dotCustomColorBorderHover'] ) ); } if ( ! empty( $attributes['dotCustomColorBorderActive'] ) && $is_carousel && 'custom' === $dot_style ) { $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__pagination__page.is-active' ); $css->add_property( 'border-color', $css->render_color( $attributes['dotCustomColorBorderActive'] ) ); } $css->set_selector( '.kb-gallery-id-' . $unique_id . ' .splide__pagination__page' ); if ( ! empty( $attributes['dotCustomBorderWidth'] ) && $is_carousel && 'custom' === $dot_style ) { $css->add_property( 'border-width', $attributes['dotCustomBorderWidth'] . 'px' ); $css->add_property( 'border-style', 'solid' ); } elseif ( ( !empty( $attributes['dotCustomColorBorder'] ) || !empty( $attributes['dotCustomColorBorderHover'] ) || !empty( $attributes['dotCustomColorBorderActive'] ) ) && $is_carousel && 'custom' === $dot_style ) { $css->add_property( 'border-width', '2px' ); $css->add_property( 'border-style', 'solid'); } return $css->css_output(); } /** * Parse images from saved HTML content. * * This extracts image data from the block's saved HTML when the images attribute * is not available (due to source-based attribute parsing only working in the editor). * * @param string $content The saved HTML content of the block. * @return array Array of image data extracted from the HTML. */ public function parse_images_from_content( $content ) { $images = array(); if ( empty( $content ) ) { return $images; } $doc = new \DOMDocument(); // Suppress warnings for malformed HTML and load with UTF-8 encoding. libxml_use_internal_errors( true ); $doc->loadHTML( '' . $content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD ); libxml_clear_errors(); $xpath = new \DOMXPath( $doc ); // Find all gallery items (use word boundary matching to exclude kadence-blocks-gallery-item-inner, etc.). $gallery_items = $xpath->query( "//*[contains(concat(' ', normalize-space(@class), ' '), ' kadence-blocks-gallery-item ')]" ); foreach ( $gallery_items as $item ) { // Find the img element within this gallery item. $img_nodes = $xpath->query( ".//img", $item ); if ( $img_nodes->length === 0 ) { continue; } $img = $img_nodes->item( 0 ); // Extract image data from attributes. $image_data = array( 'url' => $img->getAttribute( 'data-full-image' ) ?: '', 'thumbUrl' => $img->getAttribute( 'src' ) ?: '', 'lightUrl' => $img->getAttribute( 'data-light-image' ) ?: '', 'link' => $img->getAttribute( 'data-link' ) ?: '', 'customLink' => $img->getAttribute( 'data-custom-link' ) ?: '', 'linkTarget' => $img->getAttribute( 'data-custom-link-target' ) ?: '', 'width' => $img->getAttribute( 'width' ) ?: '', 'height' => $img->getAttribute( 'height' ) ?: '', 'alt' => $img->getAttribute( 'alt' ) ?: '', 'id' => $img->getAttribute( 'data-id' ) ?: '', 'linkSponsored' => $img->getAttribute( 'data-sponsored' ) ?: '', 'caption' => '', ); // Find caption element within this gallery item. $caption_nodes = $xpath->query( ".//*[contains(@class, 'kadence-blocks-gallery-item__caption')]", $item ); if ( $caption_nodes->length > 0 ) { $caption_node = $caption_nodes->item( 0 ); // Get inner HTML of caption. $inner_html = ''; foreach ( $caption_node->childNodes as $child ) { $inner_html .= $doc->saveHTML( $child ); } $image_data['caption'] = trim( $inner_html ); } $images[] = $image_data; } return $images; } /** * Build HTML for dynamic blocks * * @param $attributes * @param $unique_id * @param $content * @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered. * * @return mixed */ public function build_html( $attributes, $unique_id, $content, $block_instance ) { if ( empty( $attributes['kbVersion'] ) || $attributes['kbVersion'] < 2 ) { if ( strpos( $content, 'data-columns-ss' ) === false && strpos( $content, 'kb-gallery-type-grid' ) !== false ) { $content = str_replace( 'data-columns-xs="1"', 'data-columns-xs="1" data-columns-ss="1"', $content ); } // Parse images from content if imagesDynamic is not set. // The 'images' attribute uses source-based parsing which only works in the editor, // so we need to extract image data from the saved HTML content for frontend rendering. if ( empty( $attributes['imagesDynamic'] ) ) { $parsed_images = $this->parse_images_from_content( $content ); if ( ! empty( $parsed_images ) ) { $attributes['imagesDynamic'] = $parsed_images; } } } $images = ( ! empty( $attributes['imagesDynamic'] ) ? $attributes['imagesDynamic'] : false ); if ( ! $images ) { return $content; } $unique_id = ( ! empty( $attributes['uniqueID'] ) ? $attributes['uniqueID'] : 'dynamic' ); $type = ( ! empty( $attributes['type'] ) ? $attributes['type'] : 'masonry' ); $slider_fade = ( ! empty( $attributes['slideType'] ) && 'fade' == $attributes['slideType'] ); $image_filter = ( ! empty( $attributes['imageFilter'] ) ? $attributes['imageFilter'] : 'none' ); $dot_style = ( ! empty( $attributes['dotStyle'] ) ? $attributes['dotStyle'] : 'dark' ); $arrow_style = ( ! empty( $attributes['arrowStyle'] ) ? $attributes['arrowStyle'] : 'dark' ); $arrow_position = ! empty( $attributes['arrowPosition'] ) ? $attributes['arrowPosition'] : 'center'; $link_to = ( ! empty( $attributes['linkTo'] ) ? $attributes['linkTo'] : 'none' ); $lightbox = ( ! empty( $attributes['lightbox'] ) ? $attributes['lightbox'] : 'none' ); $lightbox_cap = ( ! empty( $attributes['lightboxCaption'] ) && $attributes['lightboxCaption'] ? true : false ); $autoplay = ( ! empty( $attributes['autoPlay'] ) && $attributes['autoPlay'] ? true : false ); $trans_speed = ( ! empty( $attributes['transSpeed'] ) ? $attributes['transSpeed'] : 400 ); $auto_speed = ( ! empty( $attributes['autoSpeed'] ) ? $attributes['autoSpeed'] : 7000 ); $slides_sc = ( ! empty( $attributes['slidesScroll'] ) ? $attributes['slidesScroll'] : '1' ); $columns_xxl = ( ! empty( $attributes['columns'][0] ) ? $attributes['columns'][0] : '3' ); $columns_xl = ( ! empty( $attributes['columns'][1] ) ? $attributes['columns'][1] : '3' ); $columns_md = ( ! empty( $attributes['columns'][2] ) ? $attributes['columns'][2] : '3' ); $columns_sm = ( ! empty( $attributes['columns'][3] ) ? $attributes['columns'][3] : '2' ); $columns_xs = ( ! empty( $attributes['columns'][4] ) ? $attributes['columns'][4] : '1' ); $columns_ss = ( ! empty( $attributes['columns'][5] ) ? $attributes['columns'][5] : '1' ); $tcolumns_xxl = ( ! empty( $attributes['thumbnailColumns'][0] ) ? $attributes['thumbnailColumns'][0] : '4' ); $tcolumns_xl = ( ! empty( $attributes['thumbnailColumns'][1] ) ? $attributes['thumbnailColumns'][1] : '4' ); $tcolumns_md = ( ! empty( $attributes['thumbnailColumns'][2] ) ? $attributes['thumbnailColumns'][2] : '4' ); $tcolumns_sm = ( ! empty( $attributes['thumbnailColumns'][3] ) ? $attributes['thumbnailColumns'][3] : '4' ); $tcolumns_xs = ( ! empty( $attributes['thumbnailColumns'][4] ) ? $attributes['thumbnailColumns'][4] : '4' ); $tcolumns_ss = ( ! empty( $attributes['thumbnailColumns'][5] ) ? $attributes['thumbnailColumns'][5] : '4' ); $car_align = ( isset( $attributes['carouselAlign'] ) && false === $attributes['carouselAlign'] ? false : true ); $gap = ( isset( $attributes['gutter'][0] ) && is_numeric( $attributes['gutter'][0] ) ? $attributes['gutter'][0] : '10' ); $tablet_gap = ( isset( $attributes['gutter'][1] ) && is_numeric( $attributes['gutter'][1] ) ? $attributes['gutter'][1] : $gap ); $mobile_gap = ( isset( $attributes['gutter'][2] ) && is_numeric( $attributes['gutter'][2] ) ? $attributes['gutter'][2] : $tablet_gap ); $gap_unit = ( ! empty( $attributes['gutterUnit'] ) ? $attributes['gutterUnit'] : 'px' ); $show_pause_button = ( ! empty( $attributes['showPauseButton'] ) && $attributes['showPauseButton'] ? true : false ); if ( 'slider' === $type && is_array( $images ) && 1 === count( $images ) ) { $arrow_style = 'none'; //$dot_style = 'none'; } $outer_classes = array( 'kb-gallery-wrap-id-' . $unique_id ); $outer_classes[] = ! empty( $attributes['align'] ) ? 'align' . $attributes['align'] : 'alignnone'; // Gallery Class. $gallery_classes = array( 'kb-gallery-ul', 'kb-gallery-non-static' ); $gallery_classes[] = 'kb-gallery-type-' . esc_attr( $type ); if ( 'masonry' === $type ) { $gallery_classes[] = 'kb-masonry-init'; } if ( isset( $attributes['mobileForceHover'] ) && true === $attributes['mobileForceHover'] ) { $gallery_classes[] = 'kb-mobile-force-hover'; } $gallery_classes[] = 'kb-gallery-id-' . esc_attr( $unique_id ); $gallery_classes[] = 'kb-gallery-caption-style-' . ( ! empty( $attributes['captionStyle'] ) ? esc_attr( $attributes['captionStyle'] ) : 'bottom-hover' ); $gallery_classes[] = 'kb-gallery-filter-' . ( ! empty( $attributes['imageFilter'] ) ? esc_attr( $attributes['imageFilter'] ) : 'none' ); if ( 'media' === $link_to && 'magnific' === $lightbox ) { $gallery_classes[] = 'kb-gallery-magnific-init'; } $wrapper_args = array( 'class' => implode( ' ', $outer_classes ), ); if ( ! empty( $attributes['anchor'] ) ) { $wrapper_args['id'] = $attributes['anchor']; } $wrapper_attributes = get_block_wrapper_attributes( $wrapper_args ); $content = ''; switch ( $type ) { case 'carousel': $content .= '