convert_variables_to_value example

/** * Replaces CSS variables with their values in place. * * @since 6.3.0 * @param array $styles CSS declarations to convert. * @param array $values key => value pairs to use for replacement. * @return array */
    private static function convert_variables_to_value( $styles$values ) {
        foreach ( $styles as $key => $style ) {
            if ( is_array( $style ) ) {
                $styles[ $key ] = self::convert_variables_to_value( $style$values );
                continue;
            }

            if ( 0 <= strpos( $style, 'var(' ) ) {
                // find all the variables in the string in the form of var(--variable-name, fallback), with fallback in the second capture group.
                $has_matches = preg_match_all( '/var\(([^),]+)?,?\s?(\S+)?\)/', $style$var_parts );

                if ( $has_matches ) {
                    $resolved_style = $styles[ $key ];
                    foreach ( $var_parts[1] as $index => $var_part ) {
                        
Home | Imprint | This part of the site doesn't use cookies.