Jetpack_Comments_Settings

The Jetpack by WordPress.com Jetpack Comments Settings class.

Defined (1)

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

/modules/comments/admin.php  
  1. class Jetpack_Comments_Settings { 
  2.  
  3. /** Variables *************************************************************/ 
  4.  
  5. /** 
  6. * The Jetpack Coments singleton 
  7. */ 
  8. public $jetpack_comments; 
  9.  
  10. /** 
  11. * The default comment form greeting 
  12. * @var string 
  13. */ 
  14. public $default_greeting = ''; // Set in constructor 
  15.  
  16. /** 
  17. * The default comment form color scheme 
  18. * @var string 
  19. */ 
  20. public $color_schemes = array(); 
  21.  
  22. public static function init() { 
  23. static $instance = false; 
  24.  
  25. if ( !$instance ) { 
  26. $instance = new Jetpack_Comments_Settings( Jetpack_Comments::init() ); 
  27.  
  28. return $instance; 
  29.  
  30. public function __construct( Highlander_Comments_Base $jetpack_comments ) { 
  31. $this->jetpack_comments = $jetpack_comments; 
  32.  
  33. // Setup settings 
  34. add_action( 'admin_init', array( $this, 'add_settings' ) ); 
  35. $this->setup_globals(); 
  36.  
  37. /** Private Methods *******************************************************/ 
  38.  
  39. /** 
  40. * Set any global variables or class variables 
  41. * @since JetpackComments (1.4) 
  42. */ 
  43. protected function setup_globals() { 
  44. // Default option values 
  45. $this->default_greeting = __( 'Leave a Reply', 'jetpack' ); 
  46.  
  47. // Possible color schemes 
  48. $this->color_schemes = array( 
  49. 'light' => __( 'Light', 'jetpack' ),  
  50. 'dark' => __( 'Dark', 'jetpack' ),  
  51. 'transparent' => __( 'Transparent', 'jetpack' ),  
  52. ); 
  53.  
  54. /** Settings **************************************************************/ 
  55.  
  56. /** 
  57. * Add the Jetpack settings to WordPress's discussions page 
  58. * @since JetpackComments (1.4) 
  59. */ 
  60. public function add_settings() { 
  61.  
  62. // Create the section 
  63. add_settings_section( 
  64. 'jetpack_comment_form',  
  65. __( 'Comments', 'jetpack' ),  
  66. array( $this, 'comment_form_settings_section' ),  
  67. 'discussion' 
  68. ); 
  69.  
  70. /** Clever Greeting ***************************************************/ 
  71.  
  72. add_settings_field( 
  73. 'highlander_comment_form_prompt',  
  74. __( 'Greeting Text', 'jetpack' ),  
  75. array( $this, 'comment_form_greeting_setting' ),  
  76. 'discussion',  
  77. 'jetpack_comment_form' 
  78. ); 
  79.  
  80. register_setting( 
  81. 'discussion',  
  82. 'highlander_comment_form_prompt',  
  83. array( $this, 'comment_form_greeting_sanitize' ) 
  84. ); 
  85.  
  86. /** Color Scheme ******************************************************/ 
  87.  
  88. add_settings_field( 
  89. 'jetpack_comment_form_color_scheme',  
  90. __( 'Color Scheme', 'jetpack' ),  
  91. array( $this, 'comment_form_color_scheme_setting' ),  
  92. 'discussion',  
  93. 'jetpack_comment_form' 
  94. ); 
  95.  
  96. register_setting( 
  97. 'discussion',  
  98. 'jetpack_comment_form_color_scheme',  
  99. array( $this, 'comment_form_color_scheme_sanitize' ) 
  100. ); 
  101.  
  102. /** 
  103. * Discussions setting section blurb 
  104. * @since JetpackComments (1.4) 
  105. */ 
  106. public function comment_form_settings_section() { 
  107. ?> 
  108.  
  109. <p id="jetpack-comments-settings"><?php _e( 'Adjust your Comments form with a clever greeting and color-scheme.', 'jetpack' ); ?></p> 
  110.  
  111. <?php 
  112.  
  113. /** 
  114. * Custom Comment Greeting Text 
  115. * @since JetpackComments (1.4) 
  116. */ 
  117. public function comment_form_greeting_setting() { 
  118.  
  119. // The greeting 
  120. $greeting = get_option( 'highlander_comment_form_prompt', $this->default_greeting ); ?> 
  121.  
  122. <input type="text" name="highlander_comment_form_prompt" id="jetpack-comment-form-greeting" value="<?php echo esc_attr( $greeting ); ?>" class="regular-text"> 
  123. <p class="description"><?php _e( 'A few catchy words to motivate your readers to comment', 'jetpack' ); ?></p> 
  124.  
  125. <?php 
  126.  
  127. /** 
  128. * Sanitize the clever comment greeting 
  129. * @since JetpackComments (1.4) 
  130. * @param type $val 
  131. * @return string 
  132. */ 
  133. function comment_form_greeting_sanitize( $val ) { 
  134.  
  135. // Delete if empty or the default 
  136. if ( empty( $val ) || ( $this->default_greeting == $val ) ) { 
  137. delete_option( 'highlander_comment_form_prompt' ); 
  138. return false; 
  139.  
  140. return wp_kses( $val, array() ); 
  141.  
  142. /** 
  143. * Color Scheme Setting 
  144. * @since JetpackComments (1.4) 
  145. */ 
  146. public function comment_form_color_scheme_setting() { 
  147.  
  148. // The color scheme 
  149. $scheme = get_option( 'jetpack_comment_form_color_scheme', $this->jetpack_comments->default_color_scheme ); ?> 
  150.  
  151. <fieldset> 
  152. <legend class="screen-reader-text"><?php _e( 'Color Scheme', 'jetpack' ); ?></legend> 
  153.  
  154. <?php foreach( $this->color_schemes as $key => $label ) : ?> 
  155.  
  156. <label> 
  157. <input type="radio" name="jetpack_comment_form_color_scheme" id="jetpack-comment-form-color-scheme" value="<?php echo $key; ?>" <?php checked( $scheme, $key ); ?>> 
  158. <?php echo $label; ?> 
  159. </label> 
  160. <br /> 
  161.  
  162. <?php endforeach; ?> 
  163.  
  164. </fieldset> 
  165.  
  166. <?php 
  167.  
  168. /** 
  169. * Sanitize the color scheme 
  170. * @since JetpackComments (1.4) 
  171. * @param type $val 
  172. * @return string 
  173. */ 
  174. public function comment_form_color_scheme_sanitize( $val ) { 
  175.  
  176. // Delete the option if it's... 
  177. if ( 
  178. empty( $val ) || !in_array( $val, array_keys( $this->color_schemes ) ) // ... unknown 
  179. || 
  180. $val == $this->jetpack_comments->default_color_scheme // ... or the default 
  181. ) { 
  182. delete_option( 'jetpack_comment_form_color_scheme' ); 
  183. return false; 
  184.  
  185. return $val;