customizer.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * Blank Canvas Theme: Customizer
  4. *
  5. * @package Blank Canvas
  6. * @since 1.0.0
  7. */
  8. if ( ! class_exists( 'Blank_Canvas_Customize' ) ) {
  9. /**
  10. * Customizer Settings.
  11. *
  12. * @since 1.0.0
  13. */
  14. class Blank_Canvas_Customize {
  15. /**
  16. * Constructor. Instantiate the object.
  17. *
  18. * @access public
  19. *
  20. * @since 1.0.0
  21. */
  22. public function __construct() {
  23. add_action( 'customize_register', array( $this, 'register' ) );
  24. }
  25. /**
  26. * Register customizer options.
  27. *
  28. * @access public
  29. *
  30. * @since 1.0.0
  31. *
  32. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  33. *
  34. * @return void
  35. */
  36. public function register( $wp_customize ) {
  37. // Add Content section.
  38. $wp_customize->add_section(
  39. 'jetpack_content_options',
  40. array(
  41. 'title' => esc_html__( 'Content Options', 'blank-canvas' ),
  42. 'priority' => 100,
  43. )
  44. );
  45. // Add setting to show the site header.
  46. $wp_customize->add_setting(
  47. 'show_site_header',
  48. array(
  49. 'default' => false,
  50. 'type' => 'theme_mod',
  51. 'transport' => 'refresh',
  52. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  53. )
  54. );
  55. // Add control to show the site header.
  56. $wp_customize->add_control(
  57. 'show_site_header',
  58. array(
  59. 'label' => esc_html__( 'Enable site header and top menu', 'blank-canvas' ),
  60. 'description' => esc_html__( 'Check to show a standard site header, navigation menu and social links menu on the top of every page. These can be configured in the "Site Identity" and "Menus" panels.', 'blank-canvas' ),
  61. 'section' => 'jetpack_content_options',
  62. 'priority' => 10,
  63. 'type' => 'checkbox',
  64. 'settings' => 'show_site_header',
  65. )
  66. );
  67. // Add setting to show the site footer.
  68. $wp_customize->add_setting(
  69. 'show_site_footer',
  70. array(
  71. 'default' => false,
  72. 'type' => 'theme_mod',
  73. 'transport' => 'refresh',
  74. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  75. )
  76. );
  77. // Add control to show the site footer.
  78. $wp_customize->add_control(
  79. 'show_site_footer',
  80. array(
  81. 'label' => esc_html__( 'Enable widgets and footer menu', 'blank-canvas' ),
  82. 'description' => esc_html__( "Check to show a navigation menu and widgets in your site's footer area.", 'blank-canvas' ),
  83. 'section' => 'jetpack_content_options',
  84. 'priority' => 10,
  85. 'type' => 'checkbox',
  86. 'settings' => 'show_site_footer',
  87. )
  88. );
  89. // Add setting to show post and page titles.
  90. $wp_customize->add_setting(
  91. 'show_post_and_page_titles',
  92. array(
  93. 'default' => false,
  94. 'type' => 'theme_mod',
  95. 'transport' => 'refresh',
  96. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  97. )
  98. );
  99. // Add control to show post and page titles.
  100. $wp_customize->add_control(
  101. 'show_post_and_page_titles',
  102. array(
  103. 'label' => esc_html__( 'Show post and page titles', 'blank-canvas' ),
  104. 'description' => esc_html__( 'Check to show titles at the top of single posts and pages.', 'blank-canvas' ),
  105. 'section' => 'jetpack_content_options',
  106. 'priority' => 10,
  107. 'type' => 'checkbox',
  108. 'settings' => 'show_post_and_page_titles',
  109. )
  110. );
  111. // Add setting to show the comments
  112. $wp_customize->add_setting(
  113. 'show_comments',
  114. array(
  115. 'default' => false,
  116. 'type' => 'theme_mod',
  117. 'transport' => 'refresh',
  118. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  119. )
  120. );
  121. // Add control to show the comments.
  122. $wp_customize->add_control(
  123. 'show_comments',
  124. array(
  125. 'label' => esc_html__( 'Make comments visible', 'blank-canvas' ),
  126. 'description' => esc_html__( 'Check to show comments underneath posts. Comments can be configured in "Settings > Discussion".', 'blank-canvas' ),
  127. 'section' => 'jetpack_content_options',
  128. 'priority' => 10,
  129. 'type' => 'checkbox',
  130. 'settings' => 'show_comments',
  131. )
  132. );
  133. }
  134. /**
  135. * Sanitize boolean for checkbox.
  136. *
  137. * @access public
  138. *
  139. * @since 1.0.0
  140. *
  141. * @param bool $checked Whether or not a box is checked.
  142. *
  143. * @return bool
  144. */
  145. public static function sanitize_checkbox( $checked = null ) {
  146. return (bool) isset( $checked ) && true === $checked;
  147. }
  148. }
  149. new Blank_Canvas_Customize();
  150. }