PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 5.1.4
Jetpack – WP Security, Backup, Speed, & Growth v5.1.4
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / comments / admin.php

admin.php in Jetpack – WP Security, Backup, Speed, & Growth 5.1.4, at modules/comments/admin.php

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