Advertisement
ashishsthanp

WP Customizer setting argument

Jul 18th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2.  
  3. class Modular_Customizer_Output {
  4.  
  5.     public $output = array();
  6.  
  7.     public function __construct() {
  8.  
  9.         add_action( 'wp_enqueue_scripts', array( $this, 'my_styles_method' ) );
  10.         add_filter( 'customize_dynamic_setting_args', array( $this, 'modular_add_output' ), 10, 2 );
  11.  
  12.     }
  13.  
  14.     public function modular_add_output( $settings_args, $setting_id ) {
  15.  
  16.         $output_css = '';
  17.         $output     = $settings_args['output'];
  18.  
  19.         if ( ! empty( $output ) ) {
  20.             $element  = $output[0]['element'];
  21.             $property = $output[0]['property'];
  22.             $value    = get_theme_mod( $setting_id );
  23.  
  24.             $output_css .= $element . '{ ' . $property . ': ' . $value . '}';
  25.  
  26.             $this->output = $output_css;
  27.         }
  28.  
  29.     }
  30.  
  31.     function my_styles_method() {
  32.  
  33.         wp_add_inline_style( 'modular-style', $this->output );
  34.     }
  35.  
  36. }
  37.  
  38. new Modular_Customizer_Output();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement