jetpack_content_options_customize_register

Add Content section to the Theme Customizer.

Description

jetpack_content_options_customize_register( (WP_Customize_Manager) $wp_customize ); 

Parameters (1)

0. $wp_customize (WP_Customize_Manager)
Theme Customizer object.

Usage

  1. if ( !function_exists( 'jetpack_content_options_customize_register' ) ) { 
  2. require_once '/modules/theme-tools/content-options/customizer.php'; 
  3.  
  4. // Theme Customizer object. 
  5. $wp_customize = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_content_options_customize_register($wp_customize); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/theme-tools/content-options/customizer.php  
  1. function jetpack_content_options_customize_register( $wp_customize ) { 
  2. $options = get_theme_support( 'jetpack-content-options' ); 
  3. $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; 
  4. $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); 
  5. sort( $blog_display ); 
  6. $blog_display = implode( ', ', $blog_display ); 
  7. $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; 
  8. $author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null; 
  9. $author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1; 
  10. $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; 
  11. $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; 
  12. $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; 
  13. $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; 
  14. $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; 
  15. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; 
  16. $fi_archive = ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null; 
  17. $fi_post = ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null; 
  18. $fi_page = ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null; 
  19. $fi_archive_default = ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1; 
  20. $fi_post_default = ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1; 
  21. $fi_page_default = ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1; 
  22.  
  23. // If the theme doesn't support 'jetpack-content-options[ 'blog-display' ]', 'jetpack-content-options[ 'author-bio' ]', 'jetpack-content-options[ 'post-details' ]' and 'jetpack-content-options[ 'featured-images' ]', don't continue. 
  24. if ( ( ! in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ) ) ) 
  25. && ( true !== $author_bio ) 
  26. && ( ( empty( $post_details['stylesheet'] ) ) 
  27. && ( empty( $date ) 
  28. || empty( $categories ) 
  29. || empty( $tags ) 
  30. || empty( $author ) ) ) 
  31. && ( true !== $fi_archive && true !== $fi_post && true !== $fi_page ) ) { 
  32. return; 
  33.  
  34. // New control type: Title. 
  35. class Jetpack_Customize_Control_Title extends WP_Customize_Control { 
  36. public $type = 'title'; 
  37.  
  38. public function render_content() { 
  39. ?> 
  40. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> 
  41. <?php 
  42.  
  43. // Add Content section. 
  44. $wp_customize->add_section( 'jetpack_content_options', array( 
  45. 'title' => esc_html__( 'Content Options', 'jetpack' ),  
  46. 'theme_supports' => 'jetpack-content-options',  
  47. 'priority' => 100,  
  48. ) ); 
  49.  
  50. // Add Blog Display option. 
  51. if ( in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ) ) ) { 
  52. if ( 'mixed' === $blog_display ) { 
  53. $blog_display_choices = array( 
  54. 'content' => esc_html__( 'Full post', 'jetpack' ),  
  55. 'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ),  
  56. 'mixed' => esc_html__( 'Default', 'jetpack' ),  
  57. ); 
  58.  
  59. $blog_display_description = esc_html__( 'Choose between a full post or an excerpt for the blog and archive pages, or opt for the theme\'s default combination of excerpt and full post.', 'jetpack' ); 
  60. } else { 
  61. $blog_display_choices = array( 
  62. 'content' => esc_html__( 'Full post', 'jetpack' ),  
  63. 'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ),  
  64. ); 
  65.  
  66. $blog_display_description = esc_html__( 'Choose between a full post or an excerpt for the blog and archive pages.', 'jetpack' ); 
  67.  
  68. if ( 'mixed' === get_option( 'jetpack_content_blog_display' ) ) { 
  69. update_option( 'jetpack_content_blog_display', $blog_display ); 
  70.  
  71. $wp_customize->add_setting( 'jetpack_content_blog_display', array( 
  72. 'default' => $blog_display,  
  73. 'type' => 'option',  
  74. 'transport' => 'postMessage',  
  75. 'sanitize_callback' => 'jetpack_content_options_sanitize_blog_display',  
  76. ) ); 
  77.  
  78. $wp_customize->add_control( 'jetpack_content_blog_display', array( 
  79. 'section' => 'jetpack_content_options',  
  80. 'label' => esc_html__( 'Blog Display', 'jetpack' ),  
  81. 'description' => $blog_display_description,  
  82. 'type' => 'radio',  
  83. 'choices' => $blog_display_choices,  
  84. ) ); 
  85.  
  86. // Add Author Bio option. 
  87. if ( true === $author_bio ) { 
  88. $wp_customize->add_setting( 'jetpack_content_author_bio_title' ); 
  89.  
  90. $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_author_bio_title', array( 
  91. 'section' => 'jetpack_content_options',  
  92. 'label' => esc_html__( 'Author Bio', 'jetpack' ),  
  93. 'type' => 'title',  
  94. ) ) ); 
  95.  
  96. $wp_customize->add_setting( 'jetpack_content_author_bio', array( 
  97. 'default' => $author_bio_default,  
  98. 'type' => 'option',  
  99. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  100. ) ); 
  101.  
  102. $wp_customize->add_control( 'jetpack_content_author_bio', array( 
  103. 'section' => 'jetpack_content_options',  
  104. 'label' => esc_html__( 'Display on single posts', 'jetpack' ),  
  105. 'type' => 'checkbox',  
  106. ) ); 
  107.  
  108. // Add Post Details options. 
  109. if ( ( ! empty( $post_details ) ) 
  110. && ( ! empty( $post_details['stylesheet'] ) ) 
  111. && ( ! empty( $date ) 
  112. || ! empty( $categories ) 
  113. || ! empty( $tags ) 
  114. || ! empty( $author ) ) ) { 
  115. $wp_customize->add_setting( 'jetpack_content_post_details_title' ); 
  116.  
  117. $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_post_details_title', array( 
  118. 'section' => 'jetpack_content_options',  
  119. 'label' => esc_html__( 'Post Details', 'jetpack' ),  
  120. 'type' => 'title',  
  121. ) ) ); 
  122.  
  123. // Post Details: Date 
  124. if ( ! empty( $date ) ) { 
  125. $wp_customize->add_setting( 'jetpack_content_post_details_date', array( 
  126. 'default' => 1,  
  127. 'type' => 'option',  
  128. 'transport' => 'postMessage',  
  129. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  130. ) ); 
  131.  
  132. $wp_customize->add_control( 'jetpack_content_post_details_date', array( 
  133. 'section' => 'jetpack_content_options',  
  134. 'label' => esc_html__( 'Display date', 'jetpack' ),  
  135. 'type' => 'checkbox',  
  136. ) ); 
  137.  
  138. // Post Details: Categories 
  139. if ( ! empty( $categories ) ) { 
  140. $wp_customize->add_setting( 'jetpack_content_post_details_categories', array( 
  141. 'default' => 1,  
  142. 'type' => 'option',  
  143. 'transport' => 'postMessage',  
  144. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  145. ) ); 
  146.  
  147. $wp_customize->add_control( 'jetpack_content_post_details_categories', array( 
  148. 'section' => 'jetpack_content_options',  
  149. 'label' => esc_html__( 'Display categories', 'jetpack' ),  
  150. 'type' => 'checkbox',  
  151. ) ); 
  152.  
  153. // Post Details: Tags 
  154. if ( ! empty( $tags ) ) { 
  155. $wp_customize->add_setting( 'jetpack_content_post_details_tags', array( 
  156. 'default' => 1,  
  157. 'type' => 'option',  
  158. 'transport' => 'postMessage',  
  159. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  160. ) ); 
  161.  
  162. $wp_customize->add_control( 'jetpack_content_post_details_tags', array( 
  163. 'section' => 'jetpack_content_options',  
  164. 'label' => esc_html__( 'Display tags', 'jetpack' ),  
  165. 'type' => 'checkbox',  
  166. ) ); 
  167.  
  168. // Post Details: Author 
  169. if ( ! empty( $author ) ) { 
  170. $wp_customize->add_setting( 'jetpack_content_post_details_author', array( 
  171. 'default' => 1,  
  172. 'type' => 'option',  
  173. 'transport' => 'postMessage',  
  174. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  175. ) ); 
  176.  
  177. $wp_customize->add_control( 'jetpack_content_post_details_author', array( 
  178. 'section' => 'jetpack_content_options',  
  179. 'label' => esc_html__( 'Display author', 'jetpack' ),  
  180. 'type' => 'checkbox',  
  181. ) ); 
  182.  
  183. // Add Featured Images options. 
  184. if ( true === $fi_archive || true === $fi_post || true === $fi_page ) { 
  185. $wp_customize->add_setting( 'jetpack_content_featured_images_title' ); 
  186.  
  187. $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_featured_images_title', array( 
  188. 'section' => 'jetpack_content_options',  
  189. 'label' => esc_html__( 'Featured Images', 'jetpack' ),  
  190. 'type' => 'title',  
  191. ) ) ); 
  192.  
  193. // Featured Images: Archive 
  194. if ( true === $fi_archive ) { 
  195. $wp_customize->add_setting( 'jetpack_content_featured_images_archive', array( 
  196. 'default' => $fi_archive_default,  
  197. 'type' => 'option',  
  198. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  199. ) ); 
  200.  
  201. $wp_customize->add_control( 'jetpack_content_featured_images_archive', array( 
  202. 'section' => 'jetpack_content_options',  
  203. 'label' => esc_html__( 'Display on blog and archives', 'jetpack' ),  
  204. 'type' => 'checkbox',  
  205. ) ); 
  206.  
  207. // Featured Images: Post 
  208. if ( true === $fi_post ) { 
  209. $wp_customize->add_setting( 'jetpack_content_featured_images_post', array( 
  210. 'default' => $fi_post_default,  
  211. 'type' => 'option',  
  212. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  213. ) ); 
  214.  
  215. $wp_customize->add_control( 'jetpack_content_featured_images_post', array( 
  216. 'section' => 'jetpack_content_options',  
  217. 'label' => esc_html__( 'Display on single posts', 'jetpack' ),  
  218. 'type' => 'checkbox',  
  219. ) ); 
  220.  
  221. // Featured Images: Page 
  222. if ( true === $fi_page ) { 
  223. $wp_customize->add_setting( 'jetpack_content_featured_images_page', array( 
  224. 'default' => $fi_page_default,  
  225. 'type' => 'option',  
  226. 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox',  
  227. ) ); 
  228.  
  229. $wp_customize->add_control( 'jetpack_content_featured_images_page', array( 
  230. 'section' => 'jetpack_content_options',  
  231. 'label' => esc_html__( 'Display on pages', 'jetpack' ),  
  232. 'type' => 'checkbox',  
  233. ) );