<?php
class wm4LiveDesigner
{
function __construct(){
// Hook main register function to the wp_customize_register hook
add_action( 'customize_register', array(&$this, 'regCustomizer') );
}
/***********************
/*
/* Main Reg function for WP Customizer
/* Passes in the $wp_customize object to extend
/* and work with.
/*
/***********************/
public function regCustomizer($wp_customize)
{
$wp_customize->add_section( 'mainheader', array(
'title' => __('Website Header', 'wm4'),
'priority' => 40,
'description' => ''
) );
$wp_customize->add_setting( 'wm4_options[header_background_color]', array(
'default' => '#ffffff',
'transport' => 'refresh',
'type' => 'option'
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_background_color', array(
'label' => __( 'Background Color', 'wm4' ),
'section' => 'mainheader',
'settings' => 'wm4_options[header_background_color]',
) ) );
// Load javascript in preview footer, to connect the values we set
// and see changes live in the preview
if ( $wp_customize->is_preview() && ! is_admin() )
{
add_action( 'wp_footer', array(&$this,'previewScript'), 21);
}
}
/***********************
/*
/* Javascript added to the preview footer
/* to catch and bind changed designer values
/*
/************************/
public function previewScript()
{ ?>
<script type="text/javascript">
( function( $ ){
wp.customize('wm4_options[header_background_color]',function( value ) {
value.bind(function(to) {
$('#mainheader').css('background-color', to );
});
});
} )( jQuery )
</script>
<?php
}
}
$wm4LiveDesigner = new wm4LiveDesigner;
?>