$items){ $string .= $key; $string .= '{'; if(is_array($items)){ if(isset($items['font-family']) && $items['font-family'] != NULL){ $string .= 'font-family:'.$items['font-family'].';'; } if(isset($items['font-size']) && $items['font-size'] != NULL){ $string .= 'font-size:'.$items['font-size'].';'; } if(isset($items['font-weight']) && $items['font-weight'] != NULL){ $string .= 'font-weight:'.$items['font-weight'].';'; } if(isset($items['font-style']) && $items['font-style'] != NULL){ $string .= 'font-style:'.$items['font-style'].';'; } if(isset($items['line-height']) && $items['line-height'] != NULL){ $string .= 'line-height:'.$items['line-height'].';'; } if(isset($items['letter-spacing']) && $items['letter-spacing'] != NULL){ $string .= 'letter-spacing:'.$items['letter-spacing'].';'; } if(isset($items['text-transform']) && $items['text-transform'] != NULL){ $string .= 'text-transform:'.$items['text-transform'].';'; } //Backgorund if(isset($items['background-color']) && $items['background-color'] != NULL){ $string .= 'background-color:'.$items['background-color'].';'; } if(isset($items['background-image']) && $items['background-image'] != NULL){ $string .= 'background-image: url("'.$items['background-image'].'");'; } if(isset($items['background-repeat']) && $items['background-repeat'] != NULL){ $string .= 'background-repeat: '.$items['background-repeat'].';'; } if(isset($items['background-size']) && $items['background-size'] != NULL){ $string .= 'background-size: '.$items['background-size'].';'; } if(isset($items['background-position-vertical']) || isset($items['background-position-horizontal'])){ $position = ( isset($items['background-position-vertical']) && !empty($items['background-position-vertical']) ) ? $items['background-position-vertical'] : 'top'; $position_after = ( isset($items['background-position-horizontal'])&& !empty($items['background-position-horizontal']) ) ? $items['background-position-horizontal'] : 'left'; $position .= ' '.$position_after; $string .= 'background-position: '. $position .';'; } if(isset($items['background-attachment']) && $items['background-attachment'] != NULL){ $string .= 'background-attachment: '.$items['background-attachment'].';'; } if($preview){ //enqueue google font if ( isset($items['font-family']) && (!in_array($items['font-family'], $webSafeFonts_array))) { // Get the weight $variants = array(); if( isset($items['font-weight']) ) { $variant_prev = $items['font-weight']; if ( $variant_prev == 'normal' ) { $variants[] = '400'; $variants[] = '400italic'; } else if ( $variant_prev == 'bold' ) { $variants[] = '500'; $variants[] = '500italic'; } else if ( $variant_prev == 'bolder' ) { $variants[] = '800'; $variants[] = '800italic'; } else if ( $variant_prev == 'lighter' ) { $variants[] = '100'; $variants[] = '100italic'; } } if($items['font-family'] == 'Molle'){ $variants[] = '400i'; } $variants[] = '400'; $variants = array_unique( $variants ); $rs_global_google_font_family[] = sprintf("%s:%s",str_replace( ' ', '+', $items['font-family'] ),implode( ',', $variants )); } } } $string .= '}'; } $string_out = rstCompressCSS($string); if($preview){ /** * Enqueue Google Fonts. */ if(is_array($rs_global_google_font_family) && count($rs_global_google_font_family)){ $rs_global_google_font_family_out = implode('|',$rs_global_google_font_family); $query_args = array( 'family' => $rs_global_google_font_family_out ); wp_register_style( 'rst_custom_enqueue_google_font', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null ); wp_enqueue_style( 'rst_custom_enqueue_google_font' ); $link_font = add_query_arg( $query_args, "//fonts.googleapis.com/css" ); add_editor_style( str_replace( ',', '%2C', $link_font ) ); } } else{ if($write_file){ rst_WriteCSS( $string_out, RS_LIB_PATH . "/customize/rst-writerCSS.min.css"); } else{ rst_WriteCSS( $string_out, RS_LIB_PATH . "/customize/rst-writerCSS-customize.min.css"); } add_action( 'wp_enqueue_scripts', 'rst_enqueue_style_for_front_end_customize', 9999 ); } } function rstCheckFileExistAndAvailable($cssFilename){ require_once(ABSPATH . 'wp-admin/includes/file.php'); WP_Filesystem(); global $wp_filesystem; // Verify that we can create the file if ( $wp_filesystem->exists( $cssFilename ) ) { if ( ! $wp_filesystem->is_writable( $cssFilename ) ) { return false; } if ( ! $wp_filesystem->is_readable( $cssFilename ) ) { return false; } } // Verify directory if ( ! $wp_filesystem->is_dir( dirname( $cssFilename ) ) ) { return false; } if ( ! $wp_filesystem->is_writable( dirname( $cssFilename ) ) ) { return false; } return true; } function rst_enqueue_style_for_front_end_customize(){ if(!file_exists(RS_LIB_PATH . "/customize/rst-writerCSS-customize.min.css")){ rst_customizer_css_render_file(false); } wp_register_style( 'rst-font-for-frontend-customize', ( RS_LIB_URL . "/customize/rst-writerCSS-customize.min.css"), array(), time()); wp_enqueue_style( 'rst-font-for-frontend-customize' ); } function rst_enqueue_style_for_front_end(){ if(!file_exists(RS_LIB_PATH . "/customize/rst-writerCSS.min.css")){ rst_customizer_css_render_file(); } wp_register_style( 'rst-font-for-frontend', ( RS_LIB_URL . "/customize/rst-writerCSS.min.css"), array(), time()); wp_enqueue_style( 'rst-font-for-frontend' ); } add_action( 'wp_enqueue_scripts', 'rst_enqueue_style_for_front_end',9999 ); function rst_WriteCSS( $parsedCSS, $cssFilename ) { if(rstCheckFileExistAndAvailable($cssFilename)){ // Write our CSS global $wp_filesystem; return $wp_filesystem->put_contents( $cssFilename, $parsedCSS, 0644 ); } } function rst_customizer_css_render($write_file = false, $preview = false) { $controlCSS = array(); foreach( rs::$customize as $tab ) { if( $tab['controls'] ) { foreach( $tab['controls'] as $key=>$control ) { if( ( $control['type'] == 'font' && isset( $control['css_selector'] ) ) || ( $control['type'] == 'rsbackground' && isset( $control['css_selector'] ) ) ) { if( get_theme_mod( $control['name'] ) ) { $value = is_array(get_theme_mod( $control['name'] )) ? get_theme_mod( $control['name'] ) : unserialize(get_theme_mod( $control['name'] )); if( $value ) { if( isset( $controlCSS[$control['css_selector']] ) && is_array( array_merge($controlCSS[$control['css_selector']]) ) ) { $controlCSS[$control['css_selector']] = array_merge($controlCSS[$control['css_selector']], $value); } else { $controlCSS[$control['css_selector']] = $value; } } } } } } } rstGeneralCSS($controlCSS, $write_file, $preview); } function rstGeneralAdminCSS($values_admin = array()){ $string_admin = ''; $string_admin .='p{margin: 0 0 10px 0}'; $string_admin .='h1{margin: 20px 0}'; $string_admin .='h2{margin: 20px 0}'; $string_admin .='h3{margin: 18px 0}'; $string_admin .='h4{margin: 15px 0}'; $string_admin .='h5{margin: 15px 0}'; $string_admin .='h6{margin: 15px 0}'; foreach($values_admin as $key_ad => $items_admin){ $string_admin .= $key_ad; $string_admin .= '{'; if(is_array($items_admin)){ if(isset($items_admin['font-family']) && $items_admin['font-family'] != NULL){ $string_admin .= 'font-family:'.$items_admin['font-family'].';'; } if(isset($items_admin['font-size']) && $items_admin['font-size'] != NULL){ $string_admin .= 'font-size:'.$items_admin['font-size'].';'; } if(isset($items_admin['font-weight']) && $items_admin['font-weight'] != NULL){ $string_admin .= 'font-weight:'.$items_admin['font-weight'].';'; } if(isset($items_admin['font-style']) && $items_admin['font-style'] != NULL){ $string_admin .= 'font-style:'.$items_admin['font-style'].';'; } if(isset($items_admin['line-height']) && $items_admin['line-height'] != NULL){ $string_admin .= 'line-height:'.$items_admin['line-height'].';'; } if(isset($items_admin['letter-spacing']) && $items_admin['letter-spacing'] != NULL){ $string_admin .= 'letter-spacing:'.$items_admin['letter-spacing'].';'; } if(isset($items_admin['text-transform']) && $items_admin['text-transform'] != NULL){ $string_admin .= 'text-transform:'.$items_admin['text-transform'].';'; } } $string_admin .= '}'; } $string_out_admin = rstCompressCSS($string_admin); rst_WriteCSS( $string_out_admin, get_template_directory() . "/rst-writerEditorCSS.min.css"); ?> $control_admin ) { //var_dump($control); if( $control_admin['type'] == 'font' && isset( $control_admin['admin_css'] )) { if( get_theme_mod( $control_admin['name'] ) ) { $value_admin = is_array(get_theme_mod( $control_admin['name'] )) ? get_theme_mod( $control_admin['name'] ) : unserialize(get_theme_mod( $control_admin['name'] )); if( $value_admin ) { if( isset( $control_font_CSS[$control_admin['admin_css']] ) && is_array( array_merge($control_font_CSS[$control_admin['admin_css']]) ) ) { $control_font_CSS[$control_admin['admin_css']] = array_merge($control_font_CSS[$control_admin['admin_css']], $value_admin); } else { $control_font_CSS[$control_admin['admin_css']] = $value_admin; } } } } } } } echo rstGeneralAdminCSS($control_font_CSS); } //render preview css function rst_customizer_css_render_call(){ rst_customizer_css_render(false,false); rst_admin_css_render(); } add_action( 'customize_preview_init', 'rst_customizer_css_render_call' ); //render file function rst_customizer_css_render_file(){ rst_customizer_css_render(true,false); } add_action( 'customize_save_after', 'rst_customizer_css_render_file' ); //get google font function rst_customizer_css_render_google_fonts(){ rst_customizer_css_render(false,true); } add_action( 'wp_enqueue_scripts', 'rst_customizer_css_render_google_fonts' ); add_action( 'admin_enqueue_scripts', 'rst_customizer_css_render_google_fonts' ); //Conditional logic function rstCusConvertRules($rules, $remove_null_rule = true){ $data = array(); foreach($rules as $key=>$value){ if(is_string($key)){ if($remove_null_rule && $value === null){ continue; } $logic = array(); if(strpos($key, ':not')){ $key = trim(str_replace(':not', '', $key)); $logic['not'] = ((string)$value); } else{ $logic['equal'] = ((string)$value); } if(strpos($key, ':i')){ $key = trim(str_replace(':i', '', $key)); $logic['i'] = true; } $data[$key] = isset($data[$key]) ? array_merge($logic, $data[$key]) : $logic; } } return $data; } function rst_customizer_js() { ?>