Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 102 |
|
0.00% |
0 / 14 |
CRAP | |
0.00% |
0 / 1 |
| Verbum_Admin | |
0.00% |
0 / 102 |
|
0.00% |
0 / 14 |
552 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setup_globals | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| add_settings | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
2 | |||
| comment_form_settings_section | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| verbum_field | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| allow_blocks_field | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| is_verbum_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| are_blocks_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| comment_form_greeting_setting | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| comment_form_greeting_sanitize | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| comment_form_color_scheme_setting | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| comment_form_color_scheme_sanitize | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| allow_blocks_sanitize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| enable_verbum_commenting_sanitize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Verbum Admin |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-plugins |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | |
| 10 | namespace Automattic\Jetpack; |
| 11 | |
| 12 | /** |
| 13 | * Verbum_Admin is responsible for additional admin settings for comments. |
| 14 | * |
| 15 | * @phan-constructor-used-for-side-effects |
| 16 | */ |
| 17 | class Verbum_Admin { |
| 18 | |
| 19 | /** |
| 20 | * The default commenting experience |
| 21 | * |
| 22 | * @var boolean |
| 23 | */ |
| 24 | public $default_verbum_commenting; |
| 25 | |
| 26 | /** |
| 27 | * The default value for allowing blocks in comments |
| 28 | * |
| 29 | * @var boolean |
| 30 | */ |
| 31 | public $default_allow_blocks; |
| 32 | |
| 33 | /** |
| 34 | * The default comment form greeting - blank to start with |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | public $default_greeting = ''; |
| 39 | |
| 40 | /** |
| 41 | * The default comment form color scheme - default is light |
| 42 | * |
| 43 | * @var string |
| 44 | * @see ::set_default_color_theme_based_on_theme_settings() |
| 45 | */ |
| 46 | public $default_color_scheme = ''; |
| 47 | |
| 48 | /** |
| 49 | * The default comment form color scheme - an empty array to start with |
| 50 | * |
| 51 | * @var array |
| 52 | */ |
| 53 | public $color_schemes = array(); |
| 54 | |
| 55 | /** |
| 56 | * Class constructor |
| 57 | */ |
| 58 | public function __construct() { |
| 59 | $this->setup_globals(); |
| 60 | |
| 61 | add_action( 'admin_init', array( $this, 'add_settings' ) ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Set any global variables or class variables |
| 66 | */ |
| 67 | protected function setup_globals() { |
| 68 | // Default commenting experience |
| 69 | $this->default_verbum_commenting = true; |
| 70 | |
| 71 | // Default allow blocks in comments |
| 72 | $this->default_allow_blocks = true; |
| 73 | |
| 74 | // Default option values. |
| 75 | $this->default_greeting = __( 'Leave a Reply', 'jetpack-mu-wpcom' ); |
| 76 | |
| 77 | // Default color scheme. |
| 78 | $this->default_color_scheme = 'light'; |
| 79 | |
| 80 | // Possible color schemes. |
| 81 | $this->color_schemes = array( |
| 82 | 'light' => __( 'Light', 'jetpack-mu-wpcom' ), |
| 83 | 'dark' => __( 'Dark', 'jetpack-mu-wpcom' ), |
| 84 | 'transparent' => __( 'Transparent', 'jetpack-mu-wpcom' ), |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | /** Settings ************************************************************* */ |
| 89 | |
| 90 | /** |
| 91 | * Add the Jetpack settings to WordPress's discussions page |
| 92 | */ |
| 93 | public function add_settings() { |
| 94 | |
| 95 | // Create the section. |
| 96 | add_settings_section( |
| 97 | 'jetpack_comment_form', |
| 98 | __( 'Comments', 'jetpack-mu-wpcom' ), |
| 99 | array( $this, 'comment_form_settings_section' ), |
| 100 | 'discussion' |
| 101 | ); |
| 102 | |
| 103 | add_settings_field( |
| 104 | 'enable_verbum_commenting', |
| 105 | __( 'Verbum', 'jetpack-mu-wpcom' ), |
| 106 | array( $this, 'verbum_field' ), |
| 107 | 'discussion' |
| 108 | ); |
| 109 | |
| 110 | register_setting( |
| 111 | 'discussion', |
| 112 | 'enable_verbum_commenting', |
| 113 | array( $this, 'enable_verbum_commenting_sanitize' ) |
| 114 | ); |
| 115 | |
| 116 | add_settings_field( |
| 117 | 'enable_blocks_comments', |
| 118 | __( 'Allow Blocks', 'jetpack-mu-wpcom' ), |
| 119 | array( $this, 'allow_blocks_field' ), |
| 120 | 'discussion' |
| 121 | ); |
| 122 | |
| 123 | register_setting( |
| 124 | 'discussion', |
| 125 | 'enable_blocks_comments', |
| 126 | array( $this, 'allow_blocks_sanitize' ) |
| 127 | ); |
| 128 | |
| 129 | /** |
| 130 | * Clever Greeting |
| 131 | */ |
| 132 | add_settings_field( |
| 133 | 'highlander_comment_form_prompt', |
| 134 | __( 'Greeting Text', 'jetpack-mu-wpcom' ), |
| 135 | array( $this, 'comment_form_greeting_setting' ), |
| 136 | 'discussion', |
| 137 | 'jetpack_comment_form' |
| 138 | ); |
| 139 | |
| 140 | register_setting( |
| 141 | 'discussion', |
| 142 | 'highlander_comment_form_prompt', |
| 143 | array( $this, 'comment_form_greeting_sanitize' ) |
| 144 | ); |
| 145 | |
| 146 | /** |
| 147 | * Color Scheme |
| 148 | */ |
| 149 | add_settings_field( |
| 150 | 'jetpack_comment_form_color_scheme', |
| 151 | __( 'Color Scheme', 'jetpack-mu-wpcom' ), |
| 152 | array( $this, 'comment_form_color_scheme_setting' ), |
| 153 | 'discussion', |
| 154 | 'jetpack_comment_form' |
| 155 | ); |
| 156 | |
| 157 | register_setting( |
| 158 | 'discussion', |
| 159 | 'jetpack_comment_form_color_scheme', |
| 160 | array( $this, 'comment_form_color_scheme_sanitize' ) |
| 161 | ); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Discussions setting section blurb |
| 166 | * |
| 167 | * @since 1.4 |
| 168 | */ |
| 169 | public function comment_form_settings_section() { |
| 170 | ?> |
| 171 | |
| 172 | <p id="jetpack-comments-settings"><?php esc_html_e( 'Adjust your Comments form with a clever greeting and color-scheme.', 'jetpack-mu-wpcom' ); ?></p> |
| 173 | |
| 174 | <?php |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Prints HTML for the verbum commenting setting |
| 179 | */ |
| 180 | public function verbum_field() { |
| 181 | ?> |
| 182 | <label><input name="enable_verbum_commenting" type="checkbox" <?php checked( $this->is_verbum_enabled(), true, true ); ?> value="1" /> |
| 183 | <?php esc_html_e( 'Let visitors use a WordPress.com or Facebook account to comment', 'jetpack-mu-wpcom' ); ?> |
| 184 | </label> |
| 185 | <?php |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Prints HTML for the verbum commenting setting |
| 190 | */ |
| 191 | public function allow_blocks_field() { |
| 192 | ?> |
| 193 | <label><input name="enable_blocks_comments" type="checkbox" <?php checked( $this->are_blocks_enabled(), true, true ); ?> value="1" /> |
| 194 | <?php esc_html_e( 'Enable blocks in comments', 'jetpack-mu-wpcom' ); ?> |
| 195 | </label> |
| 196 | <?php |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Is verbum commenting enabled? |
| 201 | * |
| 202 | * @return boolean |
| 203 | */ |
| 204 | public function is_verbum_enabled() { |
| 205 | return (bool) get_option( 'enable_verbum_commenting', $this->default_verbum_commenting ); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Is verbum commenting enabled? |
| 210 | * |
| 211 | * @return boolean |
| 212 | */ |
| 213 | public function are_blocks_enabled() { |
| 214 | return (bool) get_option( 'enable_blocks_comments', $this->default_allow_blocks ); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Custom Comment Greeting Text |
| 219 | */ |
| 220 | public function comment_form_greeting_setting() { |
| 221 | |
| 222 | // The greeting. |
| 223 | $greeting = get_option( 'highlander_comment_form_prompt', $this->default_greeting ); |
| 224 | |
| 225 | if ( empty( $greeting ) ) { |
| 226 | $greeting = $this->default_greeting; |
| 227 | } |
| 228 | |
| 229 | ?> |
| 230 | |
| 231 | <input type="text" name="highlander_comment_form_prompt" id="jetpack-comment-form-greeting" value="<?php echo esc_attr( $greeting ); ?>" class="regular-text"> |
| 232 | <p class="description"><?php esc_html_e( 'A few catchy words to motivate your readers to comment', 'jetpack-mu-wpcom' ); ?></p> |
| 233 | |
| 234 | <?php |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Sanitize the clever comment greeting |
| 239 | * |
| 240 | * @param string $val The contact form greeting string. |
| 241 | * @return string|boolean |
| 242 | */ |
| 243 | public function comment_form_greeting_sanitize( $val ) { |
| 244 | |
| 245 | // Delete if empty or the default. |
| 246 | if ( empty( $val ) || ( $this->default_greeting === $val ) ) { |
| 247 | delete_option( 'highlander_comment_form_prompt' ); |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | return wp_kses( $val, array() ); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Comment Form Color Scheme Setting |
| 256 | */ |
| 257 | public function comment_form_color_scheme_setting() { |
| 258 | |
| 259 | // The color scheme. |
| 260 | $scheme = get_option( 'jetpack_comment_form_color_scheme', $this->default_color_scheme ); |
| 261 | ?> |
| 262 | |
| 263 | <fieldset> |
| 264 | <legend class="screen-reader-text"><?php esc_html_e( 'Color Scheme', 'jetpack-mu-wpcom' ); ?></legend> |
| 265 | |
| 266 | <?php foreach ( $this->color_schemes as $key => $label ) : ?> |
| 267 | |
| 268 | <label> |
| 269 | <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 ); ?>> |
| 270 | <?php echo esc_attr( $label ); ?> |
| 271 | </label> |
| 272 | <br /> |
| 273 | |
| 274 | <?php endforeach; ?> |
| 275 | |
| 276 | </fieldset> |
| 277 | |
| 278 | <?php |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Sanitize the color scheme |
| 283 | * |
| 284 | * @param string $val The color scheme string. |
| 285 | * @return string|boolean |
| 286 | */ |
| 287 | public function comment_form_color_scheme_sanitize( $val ) { |
| 288 | |
| 289 | // Delete the option if it's unknown, or the default. |
| 290 | if ( |
| 291 | empty( $val ) || ! array_key_exists( $val, $this->color_schemes ) |
| 292 | || |
| 293 | $val === $this->default_color_scheme |
| 294 | ) { |
| 295 | delete_option( 'jetpack_comment_form_color_scheme' ); |
| 296 | return false; |
| 297 | } |
| 298 | |
| 299 | return $val; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Sanitize the allow blocks in comments setting |
| 304 | * |
| 305 | * @param string $val The allow blocks in comments string. |
| 306 | * @return string |
| 307 | */ |
| 308 | public function allow_blocks_sanitize( $val ) { |
| 309 | return $val ? '1' : '0'; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Sanitize the verbum commenting setting |
| 314 | * |
| 315 | * @param string $val The verbum commenting string. |
| 316 | * @return string |
| 317 | */ |
| 318 | public function enable_verbum_commenting_sanitize( $val ) { |
| 319 | return $val ? '1' : '0'; |
| 320 | } |
| 321 | } |