astra_get_css_value( string $value = '', string $unit = 'px', string $default = '' )
Get CSS value
Description
Syntax:
astra_get_css_value( VALUE, UNIT );
E.g.
astra_get_css_value( VALUE, ‘url’ ); astra_get_css_value( VALUE, ‘px’ ); astra_get_css_value( VALUE, ’em’ );
Parameters
- $value
-
(string) (Optional) CSS value.
Default value: ''
- $unit
-
(string) (Optional) CSS unit.
Default value: 'px'
- $default
-
(string) (Optional) CSS default font.
Default value: ''
Return
(mixed) CSS value depends on $unit
Source
File: inc/core/common-functions.php
function astra_get_css_value( $value = '', $unit = 'px', $default = '' ) { if ( '' == $value && '' == $default ) { return $value; } $css_val = ''; switch ( $unit ) { case 'font': if ( 'inherit' != $value ) { $value = astra_get_font_family( $value ); $css_val = $value; } elseif ( '' != $default ) { $css_val = $default; } else { $css_val = ''; } break; case 'px': case '%': if ( 'inherit' === strtolower( $value ) || 'inherit' === strtolower( $default ) ) { return $value; } $value = ( '' != $value ) ? $value : $default; $css_val = esc_attr( $value ) . $unit; break; case 'url': $css_val = $unit . '(' . esc_url( $value ) . ')'; break; case 'rem': if ( 'inherit' === strtolower( $value ) || 'inherit' === strtolower( $default ) ) { return $value; } if ( is_numeric( $value ) || strpos( $value, 'px' ) ) { $value = intval( $value ); $body_font_size = astra_get_option( 'font-size-body' ); if ( is_array( $body_font_size ) ) { $body_font_size_desktop = ( isset( $body_font_size['desktop'] ) && '' != $body_font_size['desktop'] ) ? $body_font_size['desktop'] : 15; } else { $body_font_size_desktop = ( '' != $body_font_size ) ? $body_font_size : 15; } if ( $body_font_size_desktop ) { $css_val = esc_attr( $value ) . 'px;font-size:' . ( esc_attr( $value ) / esc_attr( $body_font_size_desktop ) ) . $unit; } } else { $css_val = esc_attr( $value ); } break; default: $value = ( '' != $value ) ? $value : $default; if ( '' != $value ) { $css_val = esc_attr( $value ) . $unit; } } return $css_val; }
Expand full source code Collapse full source code View on Trac