.
if ( ! preg_match( '/<(a|div)\b[^>]*\bclass="swiper-container-outer[^"]*"[^>]*>/', $content, $match, PREG_OFFSET_CAPTURE ) ) {
return $content;
}
$open_tag = $match[0][0];
$open_at = $match[0][1];
$is_link = 'a' === $match[1][0];
$bg_type = $attrs['bgType'] ?? 'classic';
$responsive = ! empty( $attrs['enableResponsiveBg'] );
$image = isset( $attrs['image'] ) && is_array( $attrs['image'] ) ? $attrs['image'] : array();
$image_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
$image_url = isset( $image['url'] ) ? (string) $image['url'] : '';
$tags = new \WP_HTML_Tag_Processor( $open_tag );
$tags->next_tag();
$style = (string) $tags->get_attribute( 'style' );
$before = '';
// Background image as a real image (not for responsive or gradient backgrounds).
if ( 'classic' === $bg_type && ! $responsive && $image_id && wp_attachment_is_image( $image_id ) ) {
$focus = isset( $attrs['focusPoint']['x'], $attrs['focusPoint']['y'] ) ? $attrs['focusPoint'] : array( 'x' => 0.5, 'y' => 0.5 );
$first = 1 === self::$slides;
$img_html = wp_get_attachment_image(
$image_id,
'full',
false,
array(
'class' => 'gutslider-slide-bg',
// Decorative: the slide's own content says what it is about.
'alt' => '',
'loading' => $first ? 'eager' : 'lazy',
'fetchpriority' => $first && 1 === self::$sliders ? 'high' : 'auto',
'decoding' => 'async',
'style' => sprintf( 'object-position:%s%% %s%%', round( (float) $focus['x'] * 100, 2 ), round( (float) $focus['y'] * 100, 2 ) ),
)
);
// Parallax: the image moves slower than the slide.
if ( $img_html && 'parallax' === ( self::$context['bgEffect'] ?? '' ) ) {
$img_html = str_replace( '
![]()
, with the link stretched behind its content.
$link = '';
if ( $is_link ) {
$link_attrs = '';
foreach ( (array) $tags->get_attribute_names_with_prefix( '' ) as $name ) {
if ( in_array( $name, array( 'class', 'style' ), true ) ) {
continue;
}
$value = $tags->get_attribute( $name );
$link_attrs .= true === $value ? ' ' . esc_attr( $name ) : sprintf( ' %s="%s"', esc_attr( $name ), esc_attr( (string) $value ) );
}
$label = self::slide_label( $content );
$link = sprintf( '
%2$s', $link_attrs, esc_html( $label ) );
}
// Per-slide settings (same as slideClasses() / slideStyle() in slide.js).
$classes = (string) $tags->get_attribute( 'class' );
$position = $attrs['contentPosition'] ?? '';
if ( in_array( $position, self::POSITIONS, true ) ) {
$classes .= ' gs-pos-' . $position;
}
if ( in_array( $attrs['textColor'] ?? '', array( 'light', 'dark' ), true ) ) {
$classes .= ' gs-text-' . $attrs['textColor'];
}
$width = isset( $attrs['contentMaxWidth'] ) ? (int) $attrs['contentMaxWidth'] : 0;
if ( $width > 0 ) {
$classes .= ' gs-has-width';
$style = trim( $style . ';--gs-content-width:' . $width . 'px', ';' );
}
if ( $is_link ) {
$classes .= ' has-slide-link';
}
$new_open = sprintf(
'
',
esc_attr( trim( $classes ) ),
'' !== trim( $style ) ? ' style="' . esc_attr( $style ) . '"' : ''
);
$html = substr_replace( $content, $new_open . $link . $before, $open_at, strlen( $open_tag ) );
if ( $is_link ) {
// The box's closing is the last one in the slide.
$close_at = strrpos( $html, '' );
if ( false !== $close_at ) {
$html = substr_replace( $html, '
', $close_at, 4 );
}
}
// The slide itself: its name (tab pagination) and where it is hidden.
$slide_tag = new \WP_HTML_Tag_Processor( $html );
if ( $slide_tag->next_tag( array( 'class_name' => 'swiper-slide' ) ) ) {
$title = isset( $attrs['slideTitle'] ) && '' !== $attrs['slideTitle'] ? (string) $attrs['slideTitle'] : self::slide_label( $content, '' );
if ( '' !== $title ) {
$slide_tag->set_attribute( 'data-title', $title );
}
$hide = array_intersect( (array) ( $attrs['hideOn'] ?? array() ), array( 'desktop', 'tablet', 'mobile' ) );
if ( $hide ) {
$slide_tag->set_attribute( 'data-hide', implode( ' ', $hide ) );
}
if ( 'parallax' === ( self::$context['bgEffect'] ?? '' ) ) {
$slide_tag->add_class( 'has-parallax' );
}
$html = $slide_tag->get_updated_html();
}
// Background video: the slide image as its poster.
if ( 'video' === $bg_type && '' !== $image_url && false === strpos( $html, 'poster=' ) ) {
$html = preg_replace( '/