customizer.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_disabled_header_custom_logo_notification_script') );
  25. }
  26. /**
  27. * Register customizer options.
  28. *
  29. * @access public
  30. *
  31. * @since 1.0.0
  32. *
  33. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  34. *
  35. * @return void
  36. */
  37. public function register( $wp_customize ) {
  38. // Add Content section.
  39. $wp_customize->add_section(
  40. 'jetpack_content_options',
  41. array(
  42. 'title' => esc_html__( 'Content Options', 'blank-canvas' ),
  43. 'priority' => 100,
  44. )
  45. );
  46. // Add setting to show the site header.
  47. $wp_customize->add_setting(
  48. 'show_site_header',
  49. array(
  50. 'default' => false,
  51. 'type' => 'theme_mod',
  52. 'transport' => 'refresh',
  53. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  54. )
  55. );
  56. // Add control to show the site header.
  57. $wp_customize->add_control(
  58. 'show_site_header',
  59. array(
  60. 'label' => esc_html__( 'Enable site header and top menu', 'blank-canvas' ),
  61. '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' ),
  62. 'section' => 'jetpack_content_options',
  63. 'priority' => 10,
  64. 'type' => 'checkbox',
  65. 'settings' => 'show_site_header',
  66. )
  67. );
  68. // Add setting to show the site footer.
  69. $wp_customize->add_setting(
  70. 'show_site_footer',
  71. array(
  72. 'default' => false,
  73. 'type' => 'theme_mod',
  74. 'transport' => 'refresh',
  75. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  76. )
  77. );
  78. // Add control to show the site footer.
  79. $wp_customize->add_control(
  80. 'show_site_footer',
  81. array(
  82. 'label' => esc_html__( 'Enable widgets and footer menu', 'blank-canvas' ),
  83. 'description' => esc_html__( "Check to show a navigation menu and widgets in your site's footer area.", 'blank-canvas' ),
  84. 'section' => 'jetpack_content_options',
  85. 'priority' => 10,
  86. 'type' => 'checkbox',
  87. 'settings' => 'show_site_footer',
  88. )
  89. );
  90. // Add setting to show post and page titles.
  91. $wp_customize->add_setting(
  92. 'show_post_and_page_titles',
  93. array(
  94. 'default' => false,
  95. 'type' => 'theme_mod',
  96. 'transport' => 'refresh',
  97. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  98. )
  99. );
  100. // Add control to show post and page titles.
  101. $wp_customize->add_control(
  102. 'show_post_and_page_titles',
  103. array(
  104. 'label' => esc_html__( 'Show post and page titles', 'blank-canvas' ),
  105. 'description' => esc_html__( 'Check to show titles at the top of single posts and pages.', 'blank-canvas' ),
  106. 'section' => 'jetpack_content_options',
  107. 'priority' => 10,
  108. 'type' => 'checkbox',
  109. 'settings' => 'show_post_and_page_titles',
  110. )
  111. );
  112. // Add setting to show the comments
  113. $wp_customize->add_setting(
  114. 'show_comments',
  115. array(
  116. 'default' => false,
  117. 'type' => 'theme_mod',
  118. 'transport' => 'refresh',
  119. 'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
  120. )
  121. );
  122. // Add control to show the comments.
  123. $wp_customize->add_control(
  124. 'show_comments',
  125. array(
  126. 'label' => esc_html__( 'Make comments visible', 'blank-canvas' ),
  127. 'description' => esc_html__( 'Check to show comments underneath posts and pages. Comments can be configured in your site’s Discussion settings screen.', 'blank-canvas' ),
  128. 'section' => 'jetpack_content_options',
  129. 'priority' => 10,
  130. 'type' => 'checkbox',
  131. 'settings' => 'show_comments',
  132. )
  133. );
  134. }
  135. /**
  136. * Displays a notification above the custom logo control when you have set a logo,
  137. * but it's not visible since the site header is disabled.
  138. *
  139. * @access public
  140. *
  141. * @return void
  142. */
  143. public function enqueue_disabled_header_custom_logo_notification_script() {
  144. $handle = 'disabled-site-header-custom-logo-notification';
  145. $src = get_stylesheet_directory_uri() . '/assets/js/disabled-site-header-custom-logo-notification.js';
  146. $deps = array( 'customize-controls' );
  147. wp_enqueue_script( $handle, $src, $deps );
  148. wp_localize_script(
  149. $handle,
  150. 'disabled_site_header_custom_logo_notification_translations',
  151. array(
  152. 'custom_logo_notification_content' => __( 'Your logo will not be shown on all posts and pages. To display your logo, follow the instructions above to enable your site header.', 'blank-canvas'),
  153. )
  154. );
  155. }
  156. /**
  157. * Sanitize boolean for checkbox.
  158. *
  159. * @access public
  160. *
  161. * @since 1.0.0
  162. *
  163. * @param bool $checked Whether or not a box is checked.
  164. *
  165. * @return bool
  166. */
  167. public static function sanitize_checkbox( $checked = null ) {
  168. return (bool) isset( $checked ) && true === $checked;
  169. }
  170. }
  171. new Blank_Canvas_Customize();
  172. }