Automattic\WooCommerce\EmailEditor\Engine
Site_Style_Sync_Controller::convert_to_px_size
Convert size value to px format with optional fallback
Method of the class: Site_Style_Sync_Controller{}
No Hooks.
Returns
String. Size in px format.
Usage
// private - for code of main (parent) class only $result = $this->convert_to_px_size( $size, ?string $fallback ): string;
- $size(string) (required)
- Original size value.
- ?string $fallback
- .
Default:null
Site_Style_Sync_Controller::convert_to_px_size() Site Style Sync Controller::convert to px size code WC 10.7.0
private function convert_to_px_size( string $size, ?string $fallback = null ): string {
$converted = null;
// Replace clamp() with its minimum value. We use min because it's emails are most likely to be viewed on smaller screens.
if ( stripos( $size, 'clamp(' ) !== false ) {
$converted = Styles_Helper::clamp_to_static_px( $size, 'min' );
// If clamp_to_static_px returns the original value, it failed to convert.
if ( $converted === $size ) {
$converted = null;
}
}
// Try standard conversion.
if ( is_null( $converted ) ) {
$converted = Styles_Helper::convert_to_px( $size, false );
}
// If all conversions failed, use fallback if provided.
if ( is_null( $converted ) && $fallback ) {
return $fallback;
}
// Return converted value or original if conversion failed.
return $converted ?? $size;
}