customizer.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Gazette Theme Customizer
  4. *
  5. * @package Gazette
  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 gazette_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( 'gazette_theme_options', array(
  18. 'title' => __( 'Theme Options', 'gazette' ),
  19. 'priority' => 130,
  20. ) );
  21. /* Header Image */
  22. $wp_customize->add_setting( 'gazette_header_image', array(
  23. 'sanitize_callback' => 'gazette_sanitize_checkbox',
  24. ) );
  25. $wp_customize->add_control( 'gazette_header_image', array(
  26. 'label' => __( 'Display header image on blog index only.', 'gazette' ),
  27. 'section' => 'gazette_theme_options',
  28. 'priority' => 10,
  29. 'type' => 'checkbox',
  30. ) );
  31. /* Unfixed header */
  32. $wp_customize->add_setting( 'gazette_unfixed_header', array(
  33. 'sanitize_callback' => 'gazette_sanitize_checkbox',
  34. 'transport' => 'postMessage',
  35. ) );
  36. $wp_customize->add_control( 'gazette_unfixed_header', array(
  37. 'label' => __( 'Unfixed header when scrolling down.', 'gazette' ),
  38. 'section' => 'gazette_theme_options',
  39. 'priority' => 20,
  40. 'type' => 'checkbox',
  41. ) );
  42. /* Author Bio */
  43. $wp_customize->add_setting( 'gazette_author_bio', array(
  44. 'sanitize_callback' => 'gazette_sanitize_checkbox',
  45. ) );
  46. $wp_customize->add_control( 'gazette_author_bio', array(
  47. 'label' => __( 'Show author bio on single posts.', 'gazette' ),
  48. 'section' => 'gazette_theme_options',
  49. 'priority' => 30,
  50. 'type' => 'checkbox',
  51. ) );
  52. /* Footer Content */
  53. $wp_customize->add_setting( 'gazette_footer_content', array(
  54. 'default' => '',
  55. 'sanitize_callback' => 'wp_kses_post',
  56. ) );
  57. $wp_customize->add_control( 'gazette_footer_content', array(
  58. 'label' => __( 'Footer Content', 'gazette' ),
  59. 'section' => 'gazette_theme_options',
  60. 'priority' => 40,
  61. 'type' => 'textarea',
  62. ) );
  63. }
  64. add_action( 'customize_register', 'gazette_customize_register' );
  65. /**
  66. * Sanitize the checkbox.
  67. *
  68. * @param boolean $input.
  69. * @return boolean (true|false).
  70. */
  71. function gazette_sanitize_checkbox( $input ) {
  72. if ( 1 == $input ) {
  73. return true;
  74. } else {
  75. return false;
  76. }
  77. }
  78. /**
  79. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  80. */
  81. function gazette_customize_preview_js() {
  82. wp_enqueue_script( 'gazette-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
  83. }
  84. add_action( 'customize_preview_init', 'gazette_customize_preview_js' );