PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 15.1
Jetpack – WP Security, Backup, Speed, & Growth v15.1
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 15.1, at modules/comments/admin.php

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