customizer.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Shoreditch Theme Customizer.
  4. *
  5. * @package Shoreditch
  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 shoreditch_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( 'shoreditch_theme_options', array(
  17. 'title' => esc_html__( 'Theme Options', 'shoreditch' ),
  18. 'priority' => 130,
  19. ) );
  20. $wp_customize->add_setting( 'shoreditch_sticky_header', array(
  21. 'default' => '',
  22. 'sanitize_callback' => 'shoreditch_sanitize_checkbox',
  23. ) );
  24. $wp_customize->add_control( 'shoreditch_sticky_header', array(
  25. 'label' => esc_html__( 'Fixed header when scrolling down.', 'shoreditch' ),
  26. 'section' => 'shoreditch_theme_options',
  27. 'type' => 'checkbox',
  28. ) );
  29. $wp_customize->add_setting( 'shoreditch_footer_top_column', array(
  30. 'default' => 'column-1',
  31. 'sanitize_callback' => 'shoreditch_sanitize_column',
  32. ) );
  33. $wp_customize->add_control( 'shoreditch_footer_top_column', array(
  34. 'label' => esc_html__( 'Top Footer Area Layout', 'shoreditch' ),
  35. 'section' => 'shoreditch_theme_options',
  36. 'type' => 'radio',
  37. 'choices' => array(
  38. 'column-1' => esc_html__( '1 Column', 'shoreditch' ),
  39. 'column-2' => esc_html__( '2 Columns', 'shoreditch' ),
  40. 'column-3' => esc_html__( '3 Columns', 'shoreditch' ),
  41. ),
  42. ) );
  43. $wp_customize->add_setting( 'shoreditch_footer_bottom_column', array(
  44. 'default' => 'column-3',
  45. 'sanitize_callback' => 'shoreditch_sanitize_column',
  46. ) );
  47. $wp_customize->add_control( 'shoreditch_footer_bottom_column', array(
  48. 'label' => esc_html__( 'Bottom Footer Area Layout', 'shoreditch' ),
  49. 'section' => 'shoreditch_theme_options',
  50. 'type' => 'radio',
  51. 'choices' => array(
  52. 'column-1' => esc_html__( '1 Column', 'shoreditch' ),
  53. 'column-2' => esc_html__( '2 Columns', 'shoreditch' ),
  54. 'column-3' => esc_html__( '3 Columns', 'shoreditch' ),
  55. ),
  56. ) );
  57. }
  58. add_action( 'customize_register', 'shoreditch_customize_register' );
  59. /**
  60. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  61. */
  62. function shoreditch_customize_preview_js() {
  63. wp_enqueue_script( 'shoreditch_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
  64. }
  65. add_action( 'customize_preview_init', 'shoreditch_customize_preview_js' );
  66. /**
  67. * Sanitize the checkbox.
  68. *
  69. * @param boolean $input.
  70. * @return boolean true if portfolio page template displays title and content.
  71. */
  72. function shoreditch_sanitize_checkbox( $input ) {
  73. if ( 1 == $input ) {
  74. return true;
  75. } else {
  76. return false;
  77. }
  78. }
  79. /**
  80. * Sanitize the Column value.
  81. *
  82. * @param string $column.
  83. * @return string (column-1|column-2|column-3).
  84. */
  85. function shoreditch_sanitize_column( $column ) {
  86. if ( ! in_array( $column, array( 'column-1', 'column-2', 'column-3' ) ) ) {
  87. $column = 'column-1';
  88. }
  89. return $column;
  90. }