hero-area-customizer.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Radcliffe 2 Theme Customizer - Hero Area
  4. *
  5. * @package Radcliffe 2
  6. */
  7. function radcliffe_2_hero_area_customize_register( $wp_customize ) {
  8. /* Add Section for Hero Area */
  9. $wp_customize->add_section( 'radcliffe_2_hero_area', array(
  10. 'title' => esc_html__( 'Featured Prompt', 'radcliffe-2' ),
  11. 'description' => esc_html__( 'Use this area to promote your most important message to site visitors. You can use a headline, a brief description and prominent link to help drive visitors where you’d like them to go.', 'radcliffe-2' ),
  12. 'priority' => 12,
  13. ) );
  14. /* Display on Front Page */
  15. $wp_customize->add_setting( 'radcliffe_2_hero_area_display', array(
  16. 'sanitize_callback' => 'radcliffe_2_hero_area_sanitize_checkbox',
  17. 'transport' => 'postMessage',
  18. ) );
  19. $wp_customize->add_control( 'radcliffe_2_hero_area_display', array(
  20. 'label' => esc_html__( 'Display on the Front Page', 'radcliffe-2' ),
  21. 'section' => 'radcliffe_2_hero_area',
  22. 'type' => 'checkbox',
  23. ) );
  24. /* Title */
  25. $wp_customize->add_setting( 'radcliffe_2_hero_area_title', array(
  26. 'sanitize_callback' => 'sanitize_text_field',
  27. 'transport' => 'postMessage',
  28. ) );
  29. $wp_customize->add_control( 'radcliffe_2_hero_area_title', array(
  30. 'label' => esc_html__( 'Title', 'radcliffe-2' ),
  31. 'section' => 'radcliffe_2_hero_area',
  32. 'type' => 'text',
  33. 'input_attrs' => array(
  34. 'placeholder' => esc_attr__( 'Write a headline', 'radcliffe-2' ),
  35. ),
  36. ) );
  37. /* Content */
  38. $wp_customize->add_setting( 'radcliffe_2_hero_area_content', array(
  39. 'sanitize_callback' => 'wp_kses_post',
  40. 'transport' => 'postMessage',
  41. ) );
  42. $wp_customize->add_control( 'radcliffe_2_hero_area_content', array(
  43. 'label' => esc_html__( 'Description', 'radcliffe-2' ),
  44. 'section' => 'radcliffe_2_hero_area',
  45. 'type' => 'textarea',
  46. 'input_attrs' => array(
  47. 'placeholder' => esc_attr__( 'Write some compelling text to encourage people to click the button below', 'radcliffe-2' ),
  48. ),
  49. ) );
  50. /* Button Text */
  51. $wp_customize->add_setting( 'radcliffe_2_hero_area_button_text', array(
  52. 'sanitize_callback' => 'sanitize_text_field',
  53. 'transport' => 'postMessage',
  54. ) );
  55. $wp_customize->add_control( 'radcliffe_2_hero_area_button_text', array(
  56. 'label' => esc_html__( 'Button Text', 'radcliffe-2' ),
  57. 'section' => 'radcliffe_2_hero_area',
  58. 'type' => 'text',
  59. 'input_attrs' => array(
  60. 'placeholder' => esc_attr__( 'Click Me!', 'radcliffe-2' ),
  61. ),
  62. ) );
  63. /* Button URL */
  64. $wp_customize->add_setting( 'radcliffe_2_hero_area_button_url', array(
  65. 'sanitize_callback' => 'esc_url_raw',
  66. 'transport' => 'postMessage',
  67. ) );
  68. $wp_customize->add_control( 'radcliffe_2_hero_area_button_url', array(
  69. 'label' => esc_html__( 'Button URL Link', 'radcliffe-2' ),
  70. 'section' => 'radcliffe_2_hero_area',
  71. 'type' => 'url',
  72. 'input_attrs' => array(
  73. 'placeholder' => esc_attr__( 'http://www.example.com/', 'radcliffe-2' ),
  74. ),
  75. ) );
  76. /* Background Image */
  77. $wp_customize->add_setting( 'radcliffe_2_hero_area_background', array(
  78. 'sanitize_callback' => 'esc_url_raw',
  79. 'transport' => 'postMessage',
  80. ) );
  81. $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'radcliffe_2_hero_area_background', array(
  82. 'label' => esc_html__( 'Background Image', 'radcliffe-2' ),
  83. 'section' => 'radcliffe_2_hero_area',
  84. ) ) );
  85. /* Background Image Overlay Opacity */
  86. $wp_customize->add_setting( 'radcliffe_2_hero_overlay_opacity', array(
  87. 'default' => 40,
  88. 'type' => 'theme_mod',
  89. 'transport' => 'postMessage',
  90. 'sanitize_callback' => 'absint',
  91. 'sanitize_js_callback' => 'absint',
  92. ) );
  93. $wp_customize->add_control( 'radcliffe_2_hero_overlay_opacity', array(
  94. 'label' => esc_html__( 'Background Overlay', 'radcliffe-2' ),
  95. 'description' => esc_html__( 'Adjust the darkness of the overlay over the background image.', 'radcliffe-2' ),
  96. 'section' => 'radcliffe_2_hero_area',
  97. 'type' => 'range',
  98. 'input_attrs' => array(
  99. 'step' => 10,
  100. 'min' => 0,
  101. 'max' => 90,
  102. 'aria-valuemin' => 0,
  103. 'aria-valuemax' => 90,
  104. 'aria-valuenow' => 40,
  105. 'aria-orientation' => 'horizontal',
  106. ),
  107. ) );
  108. }
  109. add_action( 'customize_register', 'radcliffe_2_hero_area_customize_register' );
  110. /**
  111. * Sanitize the checkbox.
  112. *
  113. * @param boolean $input.
  114. * @return boolean
  115. */
  116. function radcliffe_2_hero_area_sanitize_checkbox( $input ) {
  117. return ( 1 == $input ? true : false );
  118. }
  119. /**
  120. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  121. */
  122. function radcliffe_2_hero_customize_preview_js() {
  123. wp_enqueue_script( 'radcliffe-2-hero-customizer', get_template_directory_uri() . '/hero-area/hero-area-customize-preview.js', array( 'jquery', 'customize-preview' ), '20170823', true );
  124. }
  125. add_action( 'customize_preview_init', 'radcliffe_2_hero_customize_preview_js' );