Automattic\WooCommerce\Blocks\BlockTypes
ProductGallery::parse_aspect_ratio
Parse an aspect ratio into CSS variable values.
Method of the class: ProductGallery{}
No Hooks.
Returns
array.
Usage
// private - for code of main (parent) class only $result = $this->parse_aspect_ratio( $aspect_ratio );
- $aspect_ratio(string|null) (required)
- CSS aspect ratio value.
ProductGallery::parse_aspect_ratio() ProductGallery::parse aspect ratio code WC 11.2.1
private function parse_aspect_ratio( $aspect_ratio ) {
$default_aspect_ratio = array(
'width' => '1',
'height' => '1',
);
if ( empty( $aspect_ratio ) || ! is_string( $aspect_ratio ) ) {
return $default_aspect_ratio;
}
$parts = array_map( 'trim', explode( '/', $aspect_ratio ) );
if ( count( $parts ) > 2 ) {
return $default_aspect_ratio;
}
$width = (float) $parts[0];
$height = isset( $parts[1] ) ? (float) $parts[1] : $width;
if ( $width <= 0 || $height <= 0 ) {
return $default_aspect_ratio;
}
return array(
'width' => (string) $width,
'height' => (string) $height,
);
}