customizer.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Ixion Theme Customizer.
  4. *
  5. * @package Ixion
  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 ixion_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. /**
  17. * Add the Theme Options section
  18. */
  19. $wp_customize->add_section( 'ixion_theme_options', array(
  20. 'title' => esc_html__( 'Theme Options', 'ixion' ),
  21. 'description' => esc_html( 'Customize your front page with these options.', 'ixion' ),
  22. ) );
  23. $wp_customize->add_setting( 'ixion_button_text', array(
  24. 'default' => '',
  25. 'sanitize_callback' => 'sanitize_text_field',
  26. 'transport' => 'postMessage',
  27. ) );
  28. $wp_customize->add_control( 'ixion_button_text', array(
  29. 'label' => esc_html__( 'Call-to-Action Button Text', 'ixion' ),
  30. 'section' => 'ixion_theme_options',
  31. 'type' => 'text',
  32. ) );
  33. $wp_customize->add_setting( 'ixion_button_link', array(
  34. 'default' => '',
  35. 'sanitize_callback' => 'esc_url_raw',
  36. ) );
  37. $wp_customize->add_control( 'ixion_button_link', array(
  38. 'label' => esc_html__( 'Call-to-Action Button URL', 'ixion' ),
  39. 'section' => 'ixion_theme_options',
  40. 'type' => 'text',
  41. ) );
  42. $wp_customize->add_setting( 'ixion_header_overlay_opacity', array(
  43. 'default' => 'dark',
  44. 'sanitize_callback' => 'ixion_sanitize_opacity',
  45. 'transport' => 'postMessage',
  46. ) );
  47. $wp_customize->add_control( 'ixion_header_overlay_opacity', array(
  48. 'label' => esc_html__( 'Header Image Overlay', 'ixion' ),
  49. 'section' => 'ixion_theme_options',
  50. 'type' => 'select',
  51. 'description' => esc_html( 'Adjust the darkness of the overlay over the header image.', 'ixion' ),
  52. 'choices' => array(
  53. 'none' => esc_html__( 'None', 'ixion' ),
  54. 'light' => esc_html__( 'Light', 'ixion' ),
  55. 'medium' => esc_html__( 'Medium', 'ixion' ),
  56. 'dark' => esc_html__( 'Dark', 'ixion' ), /* 0.7 */
  57. ),
  58. ) );
  59. $wp_customize->add_setting( 'ixion_featured_overlay_opacity', array(
  60. 'default' => 'medium',
  61. 'sanitize_callback' => 'ixion_sanitize_opacity',
  62. 'transport' => 'postMessage',
  63. ) );
  64. $wp_customize->add_control( 'ixion_featured_overlay_opacity', array(
  65. 'label' => esc_html__( 'Featured Content Image Overlay', 'ixion' ),
  66. 'section' => 'ixion_theme_options',
  67. 'type' => 'select',
  68. 'description' => esc_html( 'Adjust the darkness of the overlay over the featured content images.', 'ixion' ),
  69. /* Technically this one changes the opacity of the image, not the overlay, but let's not complicate things. */
  70. 'choices' => array(
  71. 'none' => esc_html__( 'None', 'ixion' ),
  72. 'light' => esc_html__( 'Light', 'ixion' ),
  73. 'medium' => esc_html__( 'Medium', 'ixion' ), /* 0.4 */
  74. 'dark' => esc_html__( 'Dark', 'ixion' ),
  75. ),
  76. ) );
  77. }
  78. add_action( 'customize_register', 'ixion_customize_register' );
  79. /*
  80. * Sanitize our opacity values
  81. */
  82. function ixion_sanitize_opacity( $input ) {
  83. $choices = array( 'none', 'light', 'medium', 'dark' );
  84. if ( ! in_array( $input, $choices ) ) {
  85. $input = 'dark';
  86. }
  87. return $input;
  88. }
  89. /**
  90. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  91. */
  92. function ixion_customize_preview_js() {
  93. wp_enqueue_script( 'ixion-customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20151215', true );
  94. }
  95. add_action( 'customize_preview_init', 'ixion_customize_preview_js' );