• File: render-style.php
  • Full Path: /home/chassiw/www/wp-content/themes/reon/customize/render-style.php
  • File size: 3.29 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
function reon_customize_css() {

    $layout_woo = include REON_URL . '/customize/settings/layout-woo.php';
    $layout_global = include REON_URL . '/customize/settings/layout-global.php';
    $general = include REON_URL . '/customize/settings/general.php';

    $allcss = <<<CSS
{$layout_woo}{$layout_global}{$general}
CSS;
    return $allcss;
    
}



add_action('wp_enqueue_scripts', 'reon_render_style');

function reon_render_style(){
    wp_enqueue_style( 'ova-google-fonts', reon_customize_google_fonts(), array(), null );
    wp_add_inline_style( 'reon-style', reon_customize_css() );
}

function reon_customize_google_fonts(){

    $fonts_url = '';

    $default_primary_font = json_decode( reon_primary_font() );
    $default_second_font = json_decode( reon_second_font() );
    $default_three_font = json_decode( reon_three_font() );

    $custom_fonts = get_theme_mod('ova_custom_font','');

    // General Font
    $primary_font = json_decode( get_theme_mod( 'primary_font' ) ) ? json_decode( get_theme_mod( 'primary_font' ) ) : $default_primary_font;
    $primary_font_family = $primary_font->font;
    $primary_font_weights_string = $primary_font->regularweight ? $primary_font->regularweight : '100,200,300,400,500,600,700,800,900';
    $is_custom_primary_font = $custom_fonts != '' ? !strpos($primary_font_family, $custom_fonts) : true;


    // Second Font
    $second_font = json_decode( get_theme_mod( 'second_font' ) ) ? json_decode( get_theme_mod( 'second_font' ) ) : $default_second_font;
    $second_font_family = $second_font->font;
    $second_font_weights_string = $second_font->regularweight ? $second_font->regularweight : '100,200,300,400,500,600,700,800,900';
    $is_custom_second_font = $custom_fonts != '' ? !strpos($second_font_family, $custom_fonts) : true;

    // Three Font
    $three_font = json_decode( get_theme_mod( 'three_font' ) ) ? json_decode( get_theme_mod( 'three_font' ) ) : $default_three_font;
    $three_font_family = $three_font->font;
    $three_font_weights_string = $three_font->regularweight ? $three_font->regularweight : '100,200,300,400,500,600,700,800,900';
    $is_custom_three_font = $custom_fonts != '' ? !strpos($three_font_family, $custom_fonts) : true;
    
    
    $general_flag = _x( 'on', $primary_font_family.': on or off', 'reon');
    $second_flag = _x( 'on', $second_font_family.': on or off', 'reon');
    $three_flag = _x( 'on', $three_font_family.': on or off', 'reon');

 
    if ( 'off' !== $general_flag || 'off' !== $second_flag || 'off' !== $three_flag  ) {
        $font_families = array();
 
        if ( 'off' !== $general_flag && $is_custom_primary_font ) {
            $font_families[] = $primary_font_family.':'.$primary_font_weights_string;
        }
 
        if ( 'off' !== $second_flag && $is_custom_second_font ) {
            $font_families[] = $second_font_family.':'.$second_font_weights_string;
        }

        if ( 'off' !== $three_flag && $is_custom_three_font ) {
            $font_families[] = $three_font_family.':'.$three_font_weights_string;
        }


        if($font_families != null){
          $query_args = array(
              'family' => urlencode( implode( '|', $font_families ) )
          );  
          $fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
        }
        
    }
 
    return esc_url_raw( $fonts_url );
}