Advertisement
firoze

CSS File Dynamically in Redux framework

Jul 24th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. Updating a CSS File Dynamically in Redux framework
  2.  
  3.  
  4. / show style.css || file.php
  5. // Help link: https://docs.reduxframework.com/core/advanced/updating-a-css-file-dynamically/
  6.  
  7. add_filter('redux/options/' . $opt_name . '/compiler', 'compiler_action', 10, 3);
  8.  
  9. function compiler_action($options, $css, $changed_values) {
  10.  
  11. $css_dir = get_template_directory() . '/css/style.css';
  12. ob_start();
  13. require_once( get_template_directory().'/css/file.php' );
  14. $css = ob_get_clean();
  15.  
  16. /** Write to options.css file **/
  17. global $wp_filesystem;
  18. WP_Filesystem();
  19. if ($wp_filesystem->put_contents( $css_dir, $css, FS_CHMOD_FILE ) ) {
  20. return true;
  21. }
  22.  
  23. }
  24.  
  25. /*
  26. array(
  27. 'id'=>'body_color_bg',
  28. 'type'=>'color',
  29. 'compiler'=>array('body_color_bg'), OR 'body_color_bg'
  30. 'title'=>'Body Background Color',
  31. 'default'=>'#FFFFFF'
  32.  
  33. ),
  34. */
  35.  
  36. // Redux Dynamic css
  37. function reDux_dynamic_CSS() {
  38. /* ------------------------------------------------------------------------ */
  39. /* Register Stylesheets */
  40. /* ------------------------------------------------------------------------ */
  41. wp_register_style('redux-style', get_template_directory_uri() . '/css/style.css', 'style');
  42.  
  43. /* ------------------------------------------------------------------------ */
  44. /* Enqueue Styles */
  45. /* ------------------------------------------------------------------------ */
  46. wp_enqueue_style( 'redux-style');
  47. }
  48. add_action( 'wp_enqueue_scripts', 'reDux_dynamic_CSS', 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement