Advertisement
Guest User

wm4customizer

a guest
Apr 14th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2. class wm4LiveDesigner
  3. {
  4.    
  5.     function __construct(){
  6.        
  7.         // Hook main register function to the wp_customize_register hook
  8.         add_action( 'customize_register', array(&$this, 'regCustomizer') );
  9.  
  10.     }
  11.    
  12.     /***********************
  13.     /*
  14.     /*  Main Reg function for WP Customizer
  15.     /*  Passes in the $wp_customize object to extend
  16.     /*  and work with.
  17.     /*
  18.     /***********************/
  19.     public function regCustomizer($wp_customize)
  20.     {
  21.        
  22.         $wp_customize->add_section( 'mainheader', array(
  23.             'title' => __('Website Header', 'wm4'),
  24.             'priority' => 40,
  25.             'description' => ''
  26.         ) );
  27.                                    
  28.         $wp_customize->add_setting( 'wm4_options[header_background_color]', array(
  29.             'default'   => '#ffffff',
  30.             'transport' => 'refresh',
  31.             'type'      => 'option'
  32.         ) );   
  33.        
  34.         $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_background_color', array(
  35.             'label'   => __( 'Background Color', 'wm4' ),
  36.             'section' => 'mainheader',
  37.             'settings'   => 'wm4_options[header_background_color]',
  38.         ) ) );     
  39.        
  40.         // Load javascript in preview footer, to connect the values we set
  41.         // and see changes live in the preview
  42.         if ( $wp_customize->is_preview() && ! is_admin() )
  43.         {
  44.             add_action( 'wp_footer', array(&$this,'previewScript'), 21);
  45.        
  46.         }
  47.        
  48.     }
  49.    
  50.    
  51.     /***********************
  52.     /*
  53.     /*  Javascript added to the preview footer
  54.     /*  to catch and bind changed designer values
  55.     /*
  56.     /************************/
  57.     public function previewScript()
  58.     { ?>
  59.        
  60.         <script type="text/javascript">
  61.         ( function( $ ){
  62.             wp.customize('wm4_options[header_background_color]',function( value ) {
  63.                 value.bind(function(to) {
  64.                     $('#mainheader').css('background-color', to );
  65.                 });
  66.             });
  67.         } )( jQuery )
  68.         </script>
  69.     <?php
  70.     }
  71.    
  72. }
  73. $wm4LiveDesigner = new wm4LiveDesigner;
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement