customizer.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Karuna Theme Customizer.
  4. *
  5. * @package Karuna
  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 karuna_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. $wp_customize->add_section( 'karuna_theme_options', array(
  17. 'title' => esc_html__( 'Theme Options', 'karuna' ),
  18. ) );
  19. $wp_customize->add_setting( 'karuna_display_recent_posts', array(
  20. 'default' => 1,
  21. 'sanitize_callback' => 'karuna_sanitize_checkbox',
  22. ) );
  23. $wp_customize->add_control( 'karuna_display_recent_posts', array(
  24. 'label' => esc_html__( 'Display up to four Recent Posts on the static front page.', 'karuna' ),
  25. 'section' => 'karuna_theme_options',
  26. 'type' => 'checkbox',
  27. ) );
  28. }
  29. add_action( 'customize_register', 'karuna_customize_register' );
  30. /**
  31. * Sanitize the checkbox.
  32. *
  33. * @param int $input.
  34. * @return boolean|string
  35. */
  36. function karuna_sanitize_checkbox( $input ) {
  37. return ( 1 == $input ) ? 1 : '';
  38. }
  39. /**
  40. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  41. */
  42. function karuna_customize_preview_js() {
  43. wp_enqueue_script( 'karuna_customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20151215', true );
  44. }
  45. add_action( 'customize_preview_init', 'karuna_customize_preview_js' );