customizer.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * toujours Theme Customizer.
  4. *
  5. * @package Toujours
  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 toujours_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( 'toujours_theme_options', array(
  17. 'title' => esc_html__( 'Theme Options', 'toujours' ),
  18. 'priority' => 130,
  19. ) );
  20. /* Front Page: Featured Page One */
  21. $wp_customize->add_setting( 'toujours_recent_posts', array(
  22. 'default' => '',
  23. 'sanitize_callback' => 'toujours_sanitize_checkbox',
  24. ) );
  25. $wp_customize->add_control( 'toujours_recent_posts', array(
  26. 'label' => esc_html__( 'Display the three most recent posts in a special area above your other posts', 'toujours' ),
  27. 'section' => 'toujours_theme_options',
  28. 'type' => 'checkbox',
  29. ) );
  30. /* General - Hide Featured Image borders */
  31. $wp_customize->add_setting( 'toujours_featured_image_borders', array(
  32. 'default' => 1,
  33. 'sanitize_callback' => 'toujours_sanitize_checkbox',
  34. 'transport' => 'postMessage',
  35. ) );
  36. $wp_customize->add_control( 'toujours_featured_image_borders', array(
  37. 'label' => esc_html__( 'Display a thin inset border on featured images', 'toujours' ),
  38. 'section' => 'toujours_theme_options',
  39. 'type' => 'checkbox',
  40. ) );
  41. }
  42. add_action( 'customize_register', 'toujours_customize_register' );
  43. /**
  44. * Sanitize the checkbox.
  45. *
  46. * @param boolean $input.
  47. *
  48. * @return boolean true if is 1 or '1', false if anything else
  49. */
  50. function toujours_sanitize_checkbox( $input ) {
  51. if ( 1 == $input ) {
  52. return true;
  53. } else {
  54. return false;
  55. }
  56. }
  57. /**
  58. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  59. */
  60. function toujours_customize_preview_js() {
  61. wp_enqueue_script( 'toujours_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
  62. }
  63. add_action( 'customize_preview_init', 'toujours_customize_preview_js' );