WC_Predictive_Search_Less

The WooCommerce Predictive Search LITE WC Predictive Search Less class.

Defined (1)

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

/admin/less/sass.php  
  1. class WC_Predictive_Search_Less 
  2. public $plugin_name = 'woo_predictive_search'; 
  3. public $css_file_name = 'wc_predictive_search'; 
  4. public $plugin_folder = WOOPS_FOLDER; 
  5. public $plugin_dir = WOOPS_DIR; 
  6.  
  7. /**-----------------------------------------------------------------------------------*/ 
  8. /** Constructor */ 
  9. /**-----------------------------------------------------------------------------------*/ 
  10. public function __construct() 
  11. add_action( $this->plugin_name.'_after_settings_save_reset', array ($this, 'plugin_build_sass') ); 
  12. //add_action( 'wp_enqueue_scripts', array ($this, 'apply_style_css_fontend') , 11 ); 
  13.  
  14. public function apply_style_css_fontend() 
  15. $_upload_dir = wp_upload_dir(); 
  16. if ( file_exists( $_upload_dir['basedir'] . '/sass/' . $this->css_file_name . '.min.css' ) ) { 
  17. wp_enqueue_style( 'a3' . $this->css_file_name, str_replace( array('http:', 'https:'), '', $_upload_dir['baseurl'] ) . '/sass/' . $this->css_file_name . '.min.css', array(), $this->get_css_file_version() ); 
  18.  
  19. public function plugin_build_sass() 
  20. $sass = $this->sass_content_data(); 
  21. $this->plugin_compile_less_mincss( $sass ); 
  22. $this->set_css_file_version(); 
  23. public function custom_filesystem_method( $method = '') { 
  24. return 'direct'; 
  25.  
  26. public function plugin_compile_less_mincss( $sass, $css_file_name = '' ) 
  27. // just filter when compile less file 
  28. add_filter( 'filesystem_method', array( $this, 'custom_filesystem_method' ) ); 
  29.  
  30. $form_url = wp_nonce_url( esc_url( add_query_arg( 'compile-sass', 'true' ) ), 'compile-sass' ); 
  31.  
  32. if ( ! function_exists( 'request_filesystem_credentials' ) ) { 
  33. require_once( ABSPATH . 'wp-admin/includes/file.php' ); 
  34.  
  35. if ( false === ( $creds = request_filesystem_credentials( $form_url, '', false, false, null ) ) ) { 
  36. return true; 
  37.  
  38. if ( ! WP_Filesystem( $creds ) ) { 
  39. // our credentials were no good, ask the user for them again 
  40. request_filesystem_credentials( $form_url, '', true ); 
  41. return true; 
  42.  
  43. global $wp_filesystem; 
  44.  
  45. @ini_set( 'display_errors', false ); 
  46. $_upload_dir = wp_upload_dir(); 
  47. $wp_filesystem->chmod($_upload_dir['basedir'], 0755); 
  48. if (! $wp_filesystem->is_dir($_upload_dir['basedir'] . '/sass')) { 
  49. $wp_filesystem->mkdir($_upload_dir['basedir'] . '/sass', 0755); 
  50. } else { 
  51. $wp_filesystem->chmod($_upload_dir['basedir'] . '/sass', 0755); 
  52.  
  53. if ( trim( $css_file_name ) == '' ) $css_file_name = $this->css_file_name; 
  54.  
  55. if ( $css_file_name == '' ) 
  56. return; 
  57.  
  58. if ( $this->plugin_folder == '' ) 
  59. return; 
  60.  
  61. $filename = $css_file_name; 
  62.  
  63. if (!file_exists($_upload_dir['basedir'] . '/sass/' . $filename . '.less')) { 
  64. $wp_filesystem->put_contents($_upload_dir['basedir'] . '/sass/' . $filename . '.less', '', 0644 ); 
  65. $wp_filesystem->put_contents($_upload_dir['basedir'] . '/sass/' . $filename . '.css', '', 0644); 
  66. $wp_filesystem->put_contents($_upload_dir['basedir'] . '/sass/' . $filename . '.min.css', '', 0644); 
  67.  
  68. $mixins = $this->css_file_name . '_mixins'; 
  69. if( !file_exists( $_upload_dir['basedir'].'/sass/'.$mixins.'.less' ) ) { 
  70. $mixinsless = $this->plugin_dir.'/admin/less/assets/css/mixins.less'; 
  71. $a3rev_mixins_less = $_upload_dir['basedir'].'/sass/'.$mixins.'.less'; 
  72. $wp_filesystem->copy($mixinsless, $a3rev_mixins_less, true ); 
  73.  
  74. $files = array_diff(scandir($_upload_dir['basedir'] . '/sass'), array( 
  75. '.',  
  76. '..' 
  77. )); 
  78. if ($files) { 
  79. foreach ($files as $file) { 
  80. $wp_filesystem->chmod($_upload_dir['basedir'] . '/sass/' . $file, 0644); 
  81.  
  82. $sass_data = ''; 
  83.  
  84. if ($sass != '') { 
  85.  
  86. $sass_data = '@import "'.$mixins.'.less";' . "\n"; 
  87.  
  88. $sass_data .= $sass; 
  89.  
  90. $sass_data = str_replace(':;', ': transparent;', $sass_data); 
  91. $sass_data = str_replace(': ;', ': transparent;', $sass_data); 
  92. $sass_data = str_replace(': !important', ': transparent !important', $sass_data); 
  93. $sass_data = str_replace(':px', ':0px', $sass_data); 
  94. $sass_data = str_replace(': px', ': 0px', $sass_data); 
  95.  
  96. $less_file = $_upload_dir['basedir'] . '/sass/' . $filename . '.less'; 
  97. if (is_writable($less_file)) { 
  98.  
  99. if (!class_exists('Compile_Less_Sass')) 
  100. include( dirname( __FILE__ ) . '/compile_less_sass_class.php'); 
  101. $wp_filesystem->put_contents($less_file, $sass_data, 0644); 
  102. $css_file = $_upload_dir['basedir'] . '/sass/' . $filename . '.css'; 
  103. $css_min_file = $_upload_dir['basedir'] . '/sass/' . $filename . '.min.css'; 
  104. $compile = new Compile_Less_Sass; 
  105. $compile->compileLessFile($less_file, $css_file, $css_min_file); 
  106.  
  107. public function sass_content_data() 
  108. do_action($this->plugin_name . '_get_all_settings'); 
  109.  
  110. ob_start(); 
  111. include( $this->plugin_dir. '/templates/dynamic-styles/sidebar-template-style.php' ); 
  112. $sass = ob_get_clean(); 
  113. $sass = str_replace( '<style>', '', str_replace( '</style>', '', $sass ) ); 
  114. $sass = str_replace( '<style type="text/css">', '', str_replace( '</style>', '', $sass ) ); 
  115.  
  116. // Start Less 
  117. $sass_ext = ''; 
  118.  
  119. $sass_ext = apply_filters( $this->plugin_name.'_build_sass', $sass_ext ); 
  120.  
  121. if ($sass_ext != '') 
  122. $sass .= "\n" . $sass_ext; 
  123.  
  124. return $sass; 
  125.  
  126. public function set_css_file_version( $css_file_name = '' ) { 
  127. if ( trim( $css_file_name ) == '' ) { 
  128. $css_file_name = $this->css_file_name; 
  129.  
  130. if ( $css_file_name == '' ) { 
  131. return false; 
  132.  
  133. update_option( $css_file_name . '_style_version', time() ); 
  134.  
  135. public function get_css_file_version( $css_file_name = '' ) { 
  136. if ( trim( $css_file_name ) == '' ) { 
  137. $css_file_name = $this->css_file_name; 
  138.  
  139. if ( $css_file_name == '' ) { 
  140. return false; 
  141.  
  142. $version_number = get_option( $css_file_name . '_style_version', time() ); 
  143.  
  144. return $version_number;