cf7_style_custom_css_generator

The Contact Form 7 Style cf7 style custom css generator function.

Description

cf7_style_custom_css_generator(); 

Usage

  1. if ( !function_exists( 'cf7_style_custom_css_generator' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7-style/cf7-style.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = cf7_style_custom_css_generator(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/cf7-style.php  
  1. function cf7_style_custom_css_generator() { 
  2. global $post; 
  3. if( empty( $post ) ) { 
  4. return false; 
  5. $args = array(  
  6. 'post_type' => 'wpcf7_contact_form',  
  7. 'post_status' => 'publish',  
  8. 'posts_per_page' => -1 
  9. ); 
  10. $forms = new WP_Query( $args ); 
  11. $total_num_posts = $forms->found_posts; 
  12. $style = ""; 
  13. $cf7s_manual_style = html_entity_decode( stripslashes(get_option( 'cf7_style_manual_style', true )), ENT_QUOTES ); 
  14. $cf7s_manual_style = ( $cf7s_manual_style == '1' ) ? "" : $cf7s_manual_style; 
  15. $cf7s_force_css = get_option( 'cf7_style_forcecss', true ); 
  16. $cf7s_force_css = (1 == $cf7s_force_css ) ? " !important" : ""; 
  17. $active_styles = array(); 
  18. $style_number = 0; 
  19. if( $forms->have_posts() ) : 
  20. while( $forms->have_posts() ) : $forms->the_post(); 
  21. $id = get_the_ID(); 
  22. $cf7s_id = get_post_meta( $id, 'cf7_style_id', true ); 
  23. $form_title = get_the_title($cf7s_id); 
  24. if ( ( ! empty( $cf7s_id ) || $cf7s_id !== 0 ) && ! in_array( $cf7s_id, $active_styles ) ) {  
  25. array_push( $active_styles, $cf7s_id ); 
  26. $cf7_style_data = get_post( $cf7s_id, OBJECT );  
  27. $check_custom_style = has_term( 'custom-style', 'style_category', $cf7_style_data ); 
  28. /**Check if custom style or template*/ 
  29. $cf7s_slug = ( $check_custom_style ) ? $cf7s_id : sanitize_title( $form_title); 
  30. /**check if custom again*/ 
  31. if( $check_custom_style ) { 
  32. $cf7s_custom_settings = maybe_unserialize( get_post_meta( $cf7s_id, 'cf7_style_custom_styler', true )); 
  33. $cf7s_custom_settings = ( empty($cf7s_custom_settings) ) ? array() : $cf7s_custom_settings; 
  34. $groundzero = ""; 
  35. $groundzero_hover = ""; 
  36. $groundone = ""; 
  37. $groundone_hover = ""; 
  38. $tempSave = ""; 
  39. $bleah = array(); 
  40. $bleah_hover = array(); 
  41. $i = 0; 
  42. $i_hover = 0; 
  43. $curr_tag_gen = ""; 
  44. $cur_property_gen = ""; 
  45. $the_hover = "no"; 
  46. foreach( $cf7s_custom_settings as $setting_key => $setting ) { 
  47. $setting_key_part = explode( "_", $setting_key ); 
  48. $classelem = "body .cf7-style." . ( ( is_numeric( $cf7s_slug ) ) ? "cf7-style-".$cf7s_slug : $cf7s_slug ); 
  49. $html_element = ( $setting_key_part[0] == "submit" || $setting_key_part[0] == "radio" || $setting_key_part[0] == "checkbox" ) ? 
  50. " input[type='". $setting_key_part[0]."']" : ( ( $setting_key_part[0] == "form" ) ? "" : (( $setting_key_part[0] == "wpcf7-not-valid-tip" || $setting_key_part[0] == "wpcf7-validation-errors" || $setting_key_part[0] == "wpcf7-mail-sent-ok" ) ? 
  51. " .". $setting_key_part[0] : ' '.$setting_key_part[0]) ); 
  52. $endtag = ( $i == 0 ) ? "" : "}\n"; 
  53. $endtag_hover = ( $i_hover == 0 ) ? "" : "}\n"; 
  54. $curr_tag_gen = $classelem.$html_element; 
  55. if( $setting != "" ) { 
  56. $setting = ($setting_key_part[1] == "background-image") ? 'url("'.$setting.'")' : $setting; 
  57. $cur_property_gen = "\t\t".$setting_key_part[1].": ".$setting.$cf7s_force_css. ";\n"; 
  58. $the_hover = ( array_key_exists (3, $setting_key_part) && $setting_key_part[3] == "hover" ) ? "yes" : 
  59. ( array_key_exists (2, $setting_key_part) && $setting_key_part[2] == "hover" ) ? "yes" : "no"; 
  60. if($the_hover == "yes") { 
  61. if( $groundzero_hover != $setting_key_part[0]) { 
  62. if(array_key_exists($i_hover, $bleah_hover)) { 
  63. $i_hover++; 
  64. $bleah_hover[$i_hover] = $endtag_hover.$curr_tag_gen.":hover {\n"; 
  65. $groundzero_hover = $setting_key_part[0]; 
  66. $i_hover++; 
  67. if( $setting != "" ) { 
  68. if ( $groundone_hover != $setting_key_part[1]) { 
  69. $groundone_hover = $setting_key_part[1]; 
  70. $tempSave = $setting; 
  71. if( $setting != "px" && $setting != "%" && $setting != "em" ) { 
  72. $bleah_hover[$i_hover] = $cur_property_gen; 
  73. } else { 
  74. $bleah_hover[--$i_hover] = ( $tempSave != "done" ) ? ( "\t\t".$setting_key_part[1].": ".$tempSave.$setting.$cf7s_force_css. ";\n") : ""; 
  75. $tempSave = "done"; 
  76. }  
  77. } else { 
  78.  
  79. if( $groundzero != $setting_key_part[0]) { 
  80. if(array_key_exists($i, $bleah)) { 
  81. $i++; 
  82. $bleah[$i] = $endtag.$curr_tag_gen." {\n"; 
  83. $groundzero = $setting_key_part[0]; 
  84. $i++; 
  85. if( $setting != "" ) { 
  86. if ( $groundone != $setting_key_part[1]) { 
  87. $groundone = $setting_key_part[1]; 
  88. $tempSave = $setting; 
  89. if( $setting != "px" && $setting != "%" && $setting != "em" ) { 
  90. $bleah[$i] = $cur_property_gen; 
  91. } else { 
  92. $bleah[--$i] = ( $tempSave != "done" ) ? ( "\t\t".$setting_key_part[1].": ".$tempSave.$setting.$cf7s_force_css. ";\n") : ""; 
  93. $tempSave = "done"; 
  94. foreach ($bleah as $style_line) { 
  95. $style .= $style_line; 
  96. $style .= "}\n"; 
  97. foreach ($bleah_hover as $style_line) { 
  98. $style .= $style_line; 
  99. $style .= "}"; 
  100. }/**custom end*/ 
  101. $font_family = return_font_name( $cf7s_id ); 
  102.  
  103. if( ! empty( $font_family ) && "none" !== $font_family ) { 
  104. if (is_numeric($cf7s_slug)) { 
  105. $cf7s_slug = "cf7-style-".$cf7s_slug; 
  106. $style .= "\n".'body .cf7-style.' . $cf7s_slug . ", \nbody .cf7-style." . $cf7s_slug . " input[type='submit'] {\n\t font-family: '" . $font_family . "', sans-serif;\n} "; 
  107. $style_number++; 
  108. }/**Main if ends here*/ 
  109. endwhile; 
  110. $style_manual = ""; 
  111. $style_start = "\n<style class='cf7-style' media='screen' type='text/css'>\n"; 
  112. if( !empty( $cf7s_manual_style ) ) { 
  113. $style_manual = "\n".$cf7s_manual_style."\n"; 
  114. $cur_css = $style_start; 
  115. if ( version_compare( phpversion() , '5.3', '>' ) ) { 
  116. require_once 'inc/cssparser.php'; 
  117. $css = new CSSParser(); 
  118. $cssIndex = $css->ParseCSS($style); 
  119. $cur_css .= $css->GetCSS($cssIndex); 
  120. } else { 
  121. $cur_css .= $style; 
  122. $cur_css .= $style_manual; 
  123. if( ( $style_number !== 0 ) && $style_number == count( $active_styles ) ) { 
  124. $cur_css .= "\n</style>\n"; 
  125. $cur_css = str_replace(' 0px;', ' 0;', $cur_css); 
  126. echo $cur_css; 
  127. wp_reset_postdata(); 
  128. endif;  
  129. }// end of cf7_style_custom_css_generator