customizer.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Dara Theme Customizer.
  4. *
  5. * @package Dara
  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 dara_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( 'dara_theme_options', array(
  17. 'title' => esc_html__( 'Theme Options', 'dara' ),
  18. 'priority' => 130,
  19. ) );
  20. /* Randomize Testimonials */
  21. $wp_customize->add_setting( 'dara_testimonials', array(
  22. 'default' => 0,
  23. 'sanitize_callback' => 'dara_sanitize_checkbox',
  24. ) );
  25. $wp_customize->add_control( 'dara_testimonials', array(
  26. 'label' => esc_html__( 'Randomize Front Page Testimonials', 'dara' ),
  27. 'section' => 'dara_theme_options',
  28. 'priority' => 2,
  29. 'type' => 'checkbox',
  30. ) );
  31. /* Front Page: Featured Page One */
  32. $wp_customize->add_setting( 'dara_featured_page_one_front_page', array(
  33. 'default' => '',
  34. 'sanitize_callback' => 'dara_sanitize_dropdown_pages',
  35. ) );
  36. $wp_customize->add_control( 'dara_featured_page_one_front_page', array(
  37. 'label' => esc_html__( 'Front Page: Featured Page One', 'dara' ),
  38. 'section' => 'dara_theme_options',
  39. 'priority' => 8,
  40. 'type' => 'dropdown-pages',
  41. ) );
  42. /* Front Page: Featured Page Two */
  43. $wp_customize->add_setting( 'dara_featured_page_two_front_page', array(
  44. 'default' => '',
  45. 'sanitize_callback' => 'dara_sanitize_dropdown_pages',
  46. ) );
  47. $wp_customize->add_control( 'dara_featured_page_two_front_page', array(
  48. 'label' => esc_html__( 'Front Page: Featured Page Two', 'dara' ),
  49. 'section' => 'dara_theme_options',
  50. 'priority' => 9,
  51. 'type' => 'dropdown-pages',
  52. ) );
  53. /* Front Page: Featured Page Three */
  54. $wp_customize->add_setting( 'dara_featured_page_three_front_page', array(
  55. 'default' => '',
  56. 'sanitize_callback' => 'dara_sanitize_dropdown_pages',
  57. ) );
  58. $wp_customize->add_control( 'dara_featured_page_three_front_page', array(
  59. 'label' => esc_html__( 'Front Page: Featured Page Three', 'dara' ),
  60. 'section' => 'dara_theme_options',
  61. 'priority' => 10,
  62. 'type' => 'dropdown-pages',
  63. ) );
  64. }
  65. add_action( 'customize_register', 'dara_customize_register' );
  66. /**
  67. * Sanitize the dropdown pages.
  68. *
  69. * @param interger $input.
  70. * @return interger.
  71. */
  72. function dara_sanitize_dropdown_pages( $input ) {
  73. if ( is_numeric( $input ) ) {
  74. return intval( $input );
  75. }
  76. }
  77. /**
  78. * Sanitize the checkbox.
  79. *
  80. * @param interger $input.
  81. * @return interger.
  82. */
  83. function dara_sanitize_checkbox( $input ) {
  84. if ( 1 == $input ) {
  85. return true;
  86. } else {
  87. return false;
  88. }
  89. }
  90. /**
  91. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  92. */
  93. function dara_customize_preview_js() {
  94. wp_enqueue_script( 'dara_customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20151215', true );
  95. }
  96. add_action( 'customize_preview_init', 'dara_customize_preview_js' );