wpseek.com
A WordPress-centric search engine for devs and theme authors



get_block_core_post_featured_image_overlay_element_markup › WordPress Function

Sincen/a
Deprecatedn/a
get_block_core_post_featured_image_overlay_element_markup ( $attributes )
Parameters:
  • (array) $attributes Block attributes.
    Required: Yes
Returns:
  • (string) HTML markup in string format.
Defined at:
Codex:

Generate markup for the HTML element that will be used for the overlay.



Source

function get_block_core_post_featured_image_overlay_element_markup( $attributes ) {
	$has_dim_background  = isset( $attributes['dimRatio'] ) && $attributes['dimRatio'];
	$has_gradient        = isset( $attributes['gradient'] ) && $attributes['gradient'];
	$has_custom_gradient = isset( $attributes['customGradient'] ) && $attributes['customGradient'];
	$has_solid_overlay   = isset( $attributes['overlayColor'] ) && $attributes['overlayColor'];
	$has_custom_overlay  = isset( $attributes['customOverlayColor'] ) && $attributes['customOverlayColor'];
	$class_names         = array(
		'wp-block-post-featured-image__overlay',
	);
	$styles_properties   = array();

	if ( ! $has_dim_background ) {
		return '';
	}

	// Generate required classes for the element.
	if ( $has_dim_background ) {
		$class_names[] = 'has-background-dim';
		$class_names[] = "has-background-dim-{$attributes['dimRatio']}";
	}

	if ( $has_solid_overlay ) {
		$class_names[] = "has-{$attributes['overlayColor']}-background-color";
	}

	if ( $has_gradient || $has_custom_gradient ) {
		$class_names[] = 'has-background-gradient';
	}

	if ( $has_gradient ) {
		$class_names[] = "has-{$attributes['gradient']}-gradient-background";
	}

	// Generate required CSS properties and their values.
	if ( ! empty( $attributes['style']['border']['radius'] ) ) {
		$styles_properties['border-radius'] = $attributes['style']['border']['radius'];
	}

	if ( ! empty( $attributes['style']['border']['width'] ) ) {
		$styles_properties['border-width'] = $attributes['style']['border']['width'];
	}

	if ( $has_custom_gradient ) {
		$styles_properties['background-image'] = $attributes['customGradient'];
	}

	if ( $has_custom_overlay ) {
		$styles_properties['background-color'] = $attributes['customOverlayColor'];
	}

	$styles = '';

	foreach ( $styles_properties as $style_attribute => $style_attribute_value ) {
		$styles .= "{$style_attribute}: $style_attribute_value; ";
	}

	return sprintf(
		'<span class="%s" style="%s" aria-hidden="true"></span>',
		esc_attr( implode( ' ', $class_names ) ),
		esc_attr( trim( $styles ) )
	);

}