customizer.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * TextBook Theme Customizer.
  4. *
  5. * @package TextBook
  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 textbook_customize_register( $wp_customize ) {
  13. // Add the 'featured_page_title' setting.
  14. $wp_customize->add_section( 'textbook_theme_options', array(
  15. 'title' => __( 'Theme Options', 'textbook' ),
  16. 'priority' => 200,
  17. ) );
  18. // Add the 'featured_page_title' setting.
  19. $wp_customize->add_setting(
  20. 'featured_page_title',
  21. array(
  22. 'default' => '',
  23. 'sanitize_callback' => 'sanitize_text_field'
  24. )
  25. );
  26. // Add the 'featured_page_title' control.
  27. $wp_customize->add_control(
  28. 'featured_page_title',
  29. array(
  30. 'label' => esc_html__( 'Featured Content Title', 'textbook' ),
  31. 'description' => esc_html__( 'Enter a custom title for the featured content area.', 'textbook' ),
  32. 'section' => 'textbook_theme_options',
  33. 'type' => 'text',
  34. 'priority' => 40
  35. )
  36. );
  37. // Add the 'featured_page_description' setting.
  38. $wp_customize->add_setting(
  39. 'featured_page_description',
  40. array(
  41. 'default' => '',
  42. 'sanitize_callback' => 'sanitize_text_field'
  43. )
  44. );
  45. // Add the 'featured_page_description' control.
  46. $wp_customize->add_control(
  47. 'featured_page_description',
  48. array(
  49. 'label' => esc_html__( 'Featured Content Description', 'textbook' ),
  50. 'description' => esc_html__( 'Enter a description for the featured content area.', 'textbook' ),
  51. 'section' => 'textbook_theme_options',
  52. 'type' => 'textarea',
  53. 'priority' => 60
  54. )
  55. );
  56. // Add the 'featured_page' setting.
  57. $wp_customize->add_setting(
  58. 'featured_page',
  59. array(
  60. 'default' => 0,
  61. 'sanitize_callback' => 'absint'
  62. )
  63. );
  64. // Add the 'featured_page' control.
  65. $wp_customize->add_control(
  66. 'featured_page',
  67. array(
  68. 'label' => esc_html__( 'Select Featured Page', 'textbook' ),
  69. 'description' => esc_html__( 'Select which page you&#700;d like to highlight above the Featured Content area.', 'textbook' ),
  70. 'section' => 'textbook_theme_options',
  71. 'type' => 'dropdown-pages',
  72. 'priority' => 80
  73. )
  74. );
  75. // Add postMessage support.
  76. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  77. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  78. $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  79. }
  80. add_action( 'customize_register', 'textbook_customize_register' );
  81. /**
  82. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  83. */
  84. function textbook_customize_preview_js() {
  85. wp_enqueue_script( 'textbook_customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20151215', true );
  86. }
  87. add_action( 'customize_preview_init', 'textbook_customize_preview_js' );