customizer.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Seedlet Theme: Customizer
  4. *
  5. * @package Seedlet
  6. * @since 1.0.0
  7. */
  8. if ( ! class_exists( 'Seedlet_Customize' ) ) {
  9. /**
  10. * Customizer Settings.
  11. *
  12. * @since 1.0.0
  13. */
  14. class Seedlet_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. // Change site-title & description to postMessage.
  38. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  39. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  40. // Add partial for blogname.
  41. $wp_customize->selective_refresh->add_partial(
  42. 'blogname',
  43. array(
  44. 'selector' => '.site-title',
  45. 'render_callback' => array( $this, 'partial_blogname' ),
  46. )
  47. );
  48. // Add partial for blogdescription.
  49. $wp_customize->selective_refresh->add_partial(
  50. 'blogdescription',
  51. array(
  52. 'selector' => '.site-description',
  53. 'render_callback' => array( $this, 'partial_blogdescription' ),
  54. )
  55. );
  56. /**
  57. * Add excerpt or full text selector to customizer
  58. */
  59. $wp_customize->add_section(
  60. 'excerpt_settings',
  61. array(
  62. 'title' => esc_html__( 'Excerpt Settings', 'seedlet' ),
  63. 'priority' => 120,
  64. )
  65. );
  66. $wp_customize->add_setting(
  67. 'index_display_excerpt_or_full_post',
  68. array(
  69. 'capability' => 'edit_theme_options',
  70. 'default' => 'full',
  71. 'sanitize_callback' => function( $value ) {
  72. return 'excerpt' === $value || 'full' === $value ? $value : 'excerpt';
  73. },
  74. )
  75. );
  76. $wp_customize->add_setting(
  77. 'archive_display_excerpt_or_full_post',
  78. array(
  79. 'capability' => 'edit_theme_options',
  80. 'default' => 'full',
  81. 'sanitize_callback' => function( $value ) {
  82. return 'excerpt' === $value || 'full' === $value ? $value : 'excerpt';
  83. },
  84. )
  85. );
  86. $wp_customize->add_control(
  87. 'index_display_excerpt_or_full_post',
  88. array(
  89. 'type' => 'radio',
  90. 'section' => 'excerpt_settings',
  91. 'label' => esc_html__( 'On the home page, posts show:', 'seedlet' ),
  92. 'choices' => array(
  93. 'excerpt' => esc_html__( 'Summary', 'seedlet' ),
  94. 'full' => esc_html__( 'Full text', 'seedlet' ),
  95. ),
  96. )
  97. );
  98. $wp_customize->add_control(
  99. 'archive_display_excerpt_or_full_post',
  100. array(
  101. 'type' => 'radio',
  102. 'section' => 'excerpt_settings',
  103. 'label' => esc_html__( 'On archive pages, posts show:', 'seedlet' ),
  104. 'choices' => array(
  105. 'excerpt' => esc_html__( 'Summary', 'seedlet' ),
  106. 'full' => esc_html__( 'Full text', 'seedlet' ),
  107. ),
  108. )
  109. );
  110. }
  111. /**
  112. * Render the site title for the selective refresh partial.
  113. *
  114. * @access public
  115. *
  116. * @since 1.0.0
  117. *
  118. * @return void
  119. */
  120. public function partial_blogname() {
  121. bloginfo( 'name' );
  122. }
  123. /**
  124. * Render the site tagline for the selective refresh partial.
  125. *
  126. * @access public
  127. *
  128. * @since 1.0.0
  129. *
  130. * @return void
  131. */
  132. public function partial_blogdescription() {
  133. bloginfo( 'description' );
  134. }
  135. }
  136. new Seedlet_Customize();
  137. }