customizer.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Canard Theme Customizer
  4. *
  5. * @package Canard
  6. */
  7. /**
  8. * Add postMessage support for site title and description for the Theme Customizer.
  9. *
  10. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  11. */
  12. function canard_customize_register( $wp_customize ) {
  13. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  14. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  15. $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  16. /* Theme Options */
  17. $wp_customize->add_section( 'canard_theme_options', array(
  18. 'title' => __( 'Theme Options', 'canard' ),
  19. 'priority' => 130,
  20. ) );
  21. /* Author Bio */
  22. $wp_customize->add_setting( 'canard_author_bio', array(
  23. 'sanitize_callback' => 'canard_sanitize_checkbox',
  24. ) );
  25. $wp_customize->add_control( 'canard_author_bio', array(
  26. 'label' => __( 'Show author bio on single posts.', 'canard' ),
  27. 'section' => 'canard_theme_options',
  28. 'priority' => 10,
  29. 'type' => 'checkbox',
  30. ) );
  31. }
  32. add_action( 'customize_register', 'canard_customize_register' );
  33. /**
  34. * Sanitize the checkbox.
  35. *
  36. * @param boolean $input.
  37. * @return boolean (true|false).
  38. */
  39. function canard_sanitize_checkbox( $input ) {
  40. if ( 1 == $input ) {
  41. return true;
  42. } else {
  43. return false;
  44. }
  45. }
  46. /**
  47. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  48. */
  49. function canard_customize_preview_js() {
  50. wp_enqueue_script( 'canard-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
  51. }
  52. add_action( 'customize_preview_init', 'canard_customize_preview_js' );