Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

3.4 Theme Customizer

By: a guest on Jun 8th, 2012  |  syntax: PHP  |  size: 1.18 KB  |  views: 218  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. function twentyeleven_customizer_options($wp_customize) {
  3.  
  4. $wp_customize->add_section( 'twentyeleven_color_scheme', array(
  5.         'title'          => __( 'Colors', 'twentyeleven' ),
  6.         'priority'       => 35,
  7. ));
  8.  
  9. $wp_customize->add_setting( 'twentyeleven_theme_options[text_color]', array(
  10.         'default'       => '#000000',
  11.         'type'          => 'option',
  12.         'transport'     => 'postMessage',
  13. ));
  14.  
  15. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'text_color', array(
  16.         'label'   => __( 'Text Color', 'twentyeleven' ),
  17.         'section' => 'twentyeleven_color_scheme',
  18.         'settings'   => 'twentyeleven_theme_options[text_color]',
  19. ) ) );
  20.  
  21.  
  22. $wp_customize->get_setting('twentyeleven_theme_options[text_color]')->transport='postMessage';
  23.  
  24. if ( $wp_customize->is_preview() && ! is_admin() )
  25.         add_action( 'wp_footer', 'twentyeleven_customize_preview', 21);
  26. }
  27. add_action( 'customize_register', 'twentyeleven_customizer_options' );
  28.  
  29. function twentyeleven_customize_preview() {
  30.         ?>
  31.         <script type="text/javascript">
  32.         wp.customize( 'twentyeleven_theme_options[text_color]', function( value ) {
  33.                 value.bind(function(to) {
  34.                         jQuery('body').css('color', to );
  35.                 });
  36.         });
  37.         </script>
  38.         <?php
  39. }