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



wp_get_state_style_with_fallback_dimension_styles › WordPress Function

Since7.1.0
Deprecatedn/a
wp_get_state_style_with_fallback_dimension_styles ( $state_style )
Parameters:
  • (array) $state_style State style object.
    Required: Yes
Returns:
  • (array) State style object with fallback dimension styles applied where needed.
Defined at:
Codex:

Adds fallback dimension styles for aspectRatio and height block-support values.



Source

function wp_get_state_style_with_fallback_dimension_styles( $state_style ) {
	if ( ! is_array( $state_style ) ) {
		return $state_style;
	}

	$dimensions = isset( $state_style['dimensions'] ) && is_array( $state_style['dimensions'] )
		? $state_style['dimensions']
		: array();

	if ( empty( $dimensions ) ) {
		return $state_style;
	}

	if ( wp_is_explicit_aspect_ratio_value( $dimensions['aspectRatio'] ?? null ) ) {
		return array_replace_recursive(
			$state_style,
			array(
				'dimensions' => array(
					'minHeight' => 'unset',
					'height'    => 'unset',
				),
			)
		);
	}

	$has_min_height = isset( $dimensions['minHeight'] ) && ( is_string( $dimensions['minHeight'] ) || is_numeric( $dimensions['minHeight'] ) ) && '' !== trim( (string) $dimensions['minHeight'] );
	$has_height     = isset( $dimensions['height'] ) && ( is_string( $dimensions['height'] ) || is_numeric( $dimensions['height'] ) ) && '' !== trim( (string) $dimensions['height'] );

	if ( $has_min_height || $has_height ) {
		return array_replace_recursive(
			$state_style,
			array(
				'dimensions' => array(
					'aspectRatio' => 'unset',
				),
			)
		);
	}

	return $state_style;
}