array( 'font_family' => 'Outfit', ), 'h1' => array( 'font_size' => array( 'units' => array( 'px', 'rem' ), 'unit' => 'rem', 'value' => 2.25, 'min' => 0, 'max' => 10, ), 'appearance' => 'semibold', 'line_height' => 1.28, ), 'h2' => array( 'font_size' => array( 'units' => array( 'px', 'rem' ), 'unit' => 'rem', 'value' => 1.875, 'min' => 0, 'max' => 10, ), 'appearance' => 'semibold', 'line_height' => 1.33, ), 'h3' => array( 'font_size' => array( 'units' => array( 'px', 'rem' ), 'unit' => 'rem', 'value' => 1.3125, 'min' => 0, 'max' => 10, ), 'appearance' => 'semibold', 'line_height' => 1.475, ), 'h4' => array( 'font_size' => array( 'units' => array( 'px', 'rem' ), 'unit' => 'rem', 'value' => 1.125, 'min' => 0, 'max' => 10, ), 'appearance' => 'semibold', 'line_height' => 1.55, ), 'h5' => array( 'font_size' => array( 'units' => array( 'px', 'rem' ), 'unit' => 'rem', 'value' => 1, 'min' => 0, 'max' => 10, ), 'appearance' => 'semibold', 'line_height' => 1.625, ), 'h6' => array( 'font_size' => array( 'units' => array( 'px', 'rem' ), 'unit' => 'rem', 'value' => 0.875, 'min' => 0, 'max' => 10, ), 'appearance' => 'semibold', 'line_height' => 1.7, ), 'body' => array( 'font_family' => 'system', 'font_size' => array( 'units' => array( 'px', 'rem' ), 'unit' => 'px', 'value' => 16, 'min' => 10, 'max' => 30, ), 'appearance' => 'regular', 'line_height' => 1.625, ), ); } /** * Print out global css */ public static function print_css() { $settings = self::get_settings(); $css = ''; $variables = array_merge( array( '--heading-font-family:' . self::parse_font( $settings['heading']['font_family'] ), '--body-font-family:' . self::parse_font( $settings['body']['font_family'] ), ), self::get_heading_child_styles( $settings['h1'], 'h1' ), self::get_heading_child_styles( $settings['h2'], 'h2' ), self::get_heading_child_styles( $settings['h3'], 'h3' ), self::get_heading_child_styles( $settings['h4'], 'h4' ), self::get_heading_child_styles( $settings['h5'], 'h5' ), self::get_heading_child_styles( $settings['h6'], 'h6' ), self::get_heading_child_styles( $settings['body'], 'body' ) ); $css .= 'html{' . implode( ';', $variables ) . '}'; echo wp_kses_post( $css ); } /** * Returns settings * * @return array *) */ public static function get_settings() { $default_settings = self::get_default_settings(); $typography_settings = get_theme_mod( self::get_option_key(), $default_settings ); $typography_settings = Helpers::recursive_wp_parse_args( $typography_settings, $default_settings ); foreach ( array_keys( $typography_settings ) as $key ) { if ( ! key_exists( $key, $default_settings ) ) { unset( $typography_settings[ $key ] ); } } return $typography_settings; } public static function save_settings( $data ) { $default_settings = self::get_default_settings(); $typography_settings = Helpers::recursive_wp_parse_args( $data, $default_settings ); foreach ( array_keys( $typography_settings ) as $key ) { if ( ! key_exists( $key, $default_settings ) ) { unset( $typography_settings[ $key ] ); } } set_theme_mod( self::get_option_key(), $typography_settings ); do_action( 'brandy_after_saving_typography_settings', $typography_settings ); } private static function get_heading_child_styles( $settings, $key = 'h1' ) { $result = array(); if ( isset( $settings['font_size'] ) ) { $result[] = "--$key-font-size:" . StylesDataHelpers::get_dimension_css( $settings['font_size'] ); } if ( isset( $settings['line_height'] ) ) { $result[] = "--$key-line-height:" . $settings['line_height']; } if ( isset( $settings['appearance'] ) ) { $result[] = "--$key-font-weight:" . self::parse_font_weight( $settings['appearance'] ); $result[] = "--$key-font-style:" . self::parse_font_style( $settings['appearance'] ); } return $result; } private static function parse_font_weight( $value ) { if ( false !== strpos( $value, 'thin' ) ) { return '100'; } if ( false !== strpos( $value, 'extra_light' ) ) { return '200'; } if ( false !== strpos( $value, 'light' ) ) { return '300'; } if ( false !== strpos( $value, 'regular' ) ) { return '400'; } if ( false !== strpos( $value, 'medium' ) ) { return '500'; } if ( false !== strpos( $value, 'semibold' ) ) { return '600'; } if ( false !== strpos( $value, 'extra_bold' ) ) { return '800'; } if ( false !== strpos( $value, 'bold' ) ) { return '700'; } if ( false !== strpos( $value, 'black' ) ) { return '900'; } return '400'; } private static function parse_font_style( $value ) { if ( false !== strpos( $value, 'italic' ) ) { return 'italic'; } return 'normal'; } public static function parse_font( $value ) { if ( 'system' === $value ) { return BRANDY_SYSTEM_FONT; } return $value; } /** * Returns default typography * * @param array $args Value to parse * * @return array */ public static function get_default_typography_value( $args = array() ) { $default_typography = array( 'font_style' => array( 'desktop' => array( 'weight' => 400, 'italic' => false, ), 'tablet' => null, 'mobile' => null, ), 'font_size' => array( 'desktop' => array( 'unit' => 'px', 'value' => 14, 'min' => 1, 'max' => 30, ), 'tablet' => null, 'mobile' => null, ), 'line_height' => array( 'desktop' => array( 'unit' => 'px', 'value' => 16, 'min' => 0, 'max' => 100, ), 'tablet' => null, 'mobile' => null, ), 'letter_spacing' => array( 'desktop' => array( 'unit' => 'px', 'value' => 0, 'min' => 0, 'max' => 10, ), 'tablet' => null, 'mobile' => null, ), 'transform' => array( 'desktop' => 'normal', 'tablet' => null, 'mobile' => null, ), 'decoration' => array( 'desktop' => 'normal', 'tablet' => null, 'mobile' => null, ), ); return Helpers::recursive_wp_parse_args( $args, $default_typography ); } }