compiler.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. function vamtam_recompile_css() {
  3. global $vamtam_theme;
  4. vamtam_customizer_compiler( $vamtam_theme );
  5. }
  6. // "clear cache" implementation
  7. function vamtam_actions() {
  8. if ( isset( $_GET['vamtam_action'] ) ) {
  9. if ( 'clear_cache' === $_GET['vamtam_action'] ) {
  10. vamtam_recompile_css();
  11. wp_redirect( admin_url() );
  12. }
  13. }
  14. }
  15. add_action( 'admin_init', 'vamtam_actions' );
  16. // we need font-style and font-weight to be in a single variable
  17. function vamtam_customizer_normalize_typography( $options ) {
  18. foreach ( $options as $name => $value ) {
  19. if ( is_array( $value ) && isset( $value['font-family'] ) ) {
  20. $options[ $name ]['font-weight'] = isset( $value['variant'] ) ? $value['variant'] : 'normal';
  21. unset( $options[ $name ]['variant'] );
  22. }
  23. }
  24. return $options;
  25. }
  26. add_filter( 'vamtam_customizer_compiler_options', 'vamtam_customizer_normalize_typography' );
  27. function vamtam_customizer_compiler( $options ) {
  28. if ( is_network_admin() ) {
  29. if ( class_exists( 'FLBuilderAdminSettings' ) ) {
  30. FLBuilderAdminSettings::clear_cache_for_all_sites();
  31. }
  32. } else {
  33. if ( class_exists( 'FLBuilderModel' ) ) {
  34. // Clear builder cache.
  35. FLBuilderModel::delete_asset_cache_for_all_posts();
  36. }
  37. // Clear theme cache.
  38. if ( class_exists( 'FLCustomizer' ) && method_exists( 'FLCustomizer', 'clear_all_css_cache' ) ) {
  39. FLCustomizer::clear_all_css_cache();
  40. }
  41. }
  42. update_option( 'vamtam-css-cache-timestamp', time() );
  43. }
  44. add_action( 'vamtam_customizer/' . $opt_name . '/compiler', 'vamtam_customizer_compiler', 10, 1 );
  45. function vamtam_export_beaver_options_to_less( $options ) {
  46. $settings = array(
  47. 'module_margins' => 10,
  48. );
  49. if ( class_exists( 'FLBuilderModel' ) ) {
  50. $settings = FLBuilderModel::get_global_settings();
  51. }
  52. $options['beaver-global'] = (array)$settings;
  53. return $options;
  54. }
  55. add_filter( 'vamtam_less_vars', 'vamtam_export_beaver_options_to_less' );