set_style_id( 'kb-' . $this->block_name . $unique_style_id );
$css->set_selector( '.kb-identity' . $unique_id );
$css->render_measure_output( $attributes, 'padding', 'padding' );
$css->render_measure_output( $attributes, 'margin', 'margin' );
$css->set_selector( '.kb-identity' . $unique_id .' a');
$css->add_property('text-decoration', 'inherit');
$css->add_property('color', 'inherit');
$css->set_selector( '.kb-identity' . $unique_id . ' .wp-block-site-title' );
$css->render_typography( $attributes, 'titleTypography' );
$css->set_selector( '.kb-identity' . $unique_id . ' .wp-block-site-tagline' );
$css->render_typography( $attributes, 'taglineTypography' );
$css->set_selector( '.kb-identity' . $unique_id . ' .kb-identity-layout-container' );
if( $attributes['layout'] === 'logo-left' || $attributes['layout'] === 'logo-right' || $attributes['layout'] === 'logo-right-stacked' || $attributes['layout'] === 'logo-left-stacked' ) {
$css->add_property( 'align-items', $attributes['textVerticalAlign'] );
}
return $css->css_output();
}
/**
* Return dynamically generated HTML for block
*
* @param array $attributes The block attributes.
* @param string $unique_id The unique ID for the block.
* @param string $content The block inner content.
* @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered.
*
* @return string
*/
public function build_html( $attributes, $unique_id, $content, $block_instance ) {
$layout = isset( $attributes['layout'] ) ? $attributes['layout'] : 'logo-title';
$layout_class = 'kb-identity-layout-container kb-identity-layout-' . $layout;
$content = $this->strip_anchor_tags( $content );
if (!empty($attributes['urlTransparent'])) {
// Use regex to find the existing img tag
$pattern = '/]+>/i';
if (preg_match($pattern, $content, $matches)) {
$existing_img = $matches[0];
// Create the transparent image by cloning and modifying the existing img tag
$transparent_img = $existing_img;
$transparent_img = preg_replace('/\bsrc=["\'][^"\']+["\']/', 'src="' . esc_url($attributes['urlTransparent']) . '"', $transparent_img);
$transparent_img = preg_replace('/\bclass=["\']([^"\']*)["\']/', 'class="kb-img kb-img-transparent"', $transparent_img);
$transparent_img = preg_replace('/\bsrcset=["\'][^"\']+["\']/', '', $transparent_img);
$transparent_img = preg_replace('/\bsizes=["\'][^"\']+["\']/', '', $transparent_img);
// Insert the transparent image after the existing image
$content = preg_replace($pattern, '$0' . $transparent_img, $content, 1);
}
}
if (!empty($attributes['urlSticky'])) {
$this->enqueue_script('kadence-blocks-header-sticky-image');
// Use regex to find the existing img tag
$pattern = '/
]+>/i';
if (preg_match($pattern, $content, $matches)) {
$existing_img = $matches[0];
// Create the transparent image by cloning and modifying the existing img tag
$sticky_img = $existing_img;
$sticky_img = preg_replace('/\bsrc=["\'][^"\']+["\']/', 'src="' . esc_url($attributes['urlSticky']) . '"', $sticky_img);
$sticky_img = preg_replace('/\bclass=["\']([^"\']*)["\']/', 'class="kb-img kb-img-sticky"', $sticky_img);
$sticky_img = preg_replace('/\bsrcset=["\'][^"\']+["\']/', '', $sticky_img);
$sticky_img = preg_replace('/\bsizes=["\'][^"\']+["\']/', '', $sticky_img);
// Insert the transparent image after the existing image
$content = preg_replace($pattern, '$0' . $sticky_img, $content, 1);
}
}
$outer_classes = array( 'kb-identity', 'kb-identity' . $unique_id );
$outer_classes[] = ! empty( $attributes['align'] ) ? 'align' . $attributes['align'] : 'alignnone';
if (!empty($attributes['urlTransparent'])) {
$outer_classes[] = 'has-transparent-img';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $outer_classes ) ) );
if( !empty( $attributes['linkToHomepage']) || !empty( $attributes['link']) ) {
$url = !empty( $attributes['link']) ? esc_url( $attributes['link'] ) : esc_url( home_url( '/' ) );
$content = sprintf( '%3$s', $url, $layout_class, $content );
} else {
$content = sprintf( '