Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 67 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| Verbum_Admin | |
0.00% |
0 / 67 |
|
0.00% |
0 / 12 |
306 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setup_globals | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| add_settings | |
0.00% |
0 / 40 |
|
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 | |||
| 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 | * Class constructor |
| 42 | */ |
| 43 | public function __construct() { |
| 44 | $this->setup_globals(); |
| 45 | |
| 46 | add_action( 'admin_init', array( $this, 'add_settings' ) ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Set any global variables or class variables |
| 51 | */ |
| 52 | protected function setup_globals() { |
| 53 | // Default commenting experience |
| 54 | $this->default_verbum_commenting = true; |
| 55 | |
| 56 | // Default allow blocks in comments |
| 57 | $this->default_allow_blocks = true; |
| 58 | |
| 59 | // Default option values. |
| 60 | $this->default_greeting = __( 'Leave a Reply', 'jetpack-mu-wpcom' ); |
| 61 | } |
| 62 | |
| 63 | /** Settings ************************************************************* */ |
| 64 | |
| 65 | /** |
| 66 | * Add the Jetpack settings to WordPress's discussions page |
| 67 | */ |
| 68 | public function add_settings() { |
| 69 | |
| 70 | // Create the section. |
| 71 | add_settings_section( |
| 72 | 'jetpack_comment_form', |
| 73 | __( 'Comments', 'jetpack-mu-wpcom' ), |
| 74 | array( $this, 'comment_form_settings_section' ), |
| 75 | 'discussion' |
| 76 | ); |
| 77 | |
| 78 | add_settings_field( |
| 79 | 'enable_verbum_commenting', |
| 80 | __( 'Verbum', 'jetpack-mu-wpcom' ), |
| 81 | array( $this, 'verbum_field' ), |
| 82 | 'discussion' |
| 83 | ); |
| 84 | |
| 85 | register_setting( |
| 86 | 'discussion', |
| 87 | 'enable_verbum_commenting', |
| 88 | array( $this, 'enable_verbum_commenting_sanitize' ) |
| 89 | ); |
| 90 | |
| 91 | add_settings_field( |
| 92 | 'enable_blocks_comments', |
| 93 | __( 'Allow Blocks', 'jetpack-mu-wpcom' ), |
| 94 | array( $this, 'allow_blocks_field' ), |
| 95 | 'discussion' |
| 96 | ); |
| 97 | |
| 98 | register_setting( |
| 99 | 'discussion', |
| 100 | 'enable_blocks_comments', |
| 101 | array( $this, 'allow_blocks_sanitize' ) |
| 102 | ); |
| 103 | |
| 104 | /** |
| 105 | * Clever Greeting |
| 106 | */ |
| 107 | add_settings_field( |
| 108 | 'highlander_comment_form_prompt', |
| 109 | __( 'Greeting Text', 'jetpack-mu-wpcom' ), |
| 110 | array( $this, 'comment_form_greeting_setting' ), |
| 111 | 'discussion', |
| 112 | 'jetpack_comment_form' |
| 113 | ); |
| 114 | |
| 115 | register_setting( |
| 116 | 'discussion', |
| 117 | 'highlander_comment_form_prompt', |
| 118 | array( $this, 'comment_form_greeting_sanitize' ) |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Discussions setting section blurb |
| 124 | * |
| 125 | * @since 1.4 |
| 126 | */ |
| 127 | public function comment_form_settings_section() { |
| 128 | ?> |
| 129 | |
| 130 | <p id="jetpack-comments-settings"><?php esc_html_e( 'Adjust your Comments form with a clever greeting.', 'jetpack-mu-wpcom' ); ?></p> |
| 131 | |
| 132 | <?php |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Prints HTML for the verbum commenting setting |
| 137 | */ |
| 138 | public function verbum_field() { |
| 139 | ?> |
| 140 | <label><input name="enable_verbum_commenting" type="checkbox" <?php checked( $this->is_verbum_enabled(), true, true ); ?> value="1" /> |
| 141 | <?php esc_html_e( 'Let visitors use a WordPress.com or Facebook account to comment', 'jetpack-mu-wpcom' ); ?> |
| 142 | </label> |
| 143 | <?php |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Prints HTML for the verbum commenting setting |
| 148 | */ |
| 149 | public function allow_blocks_field() { |
| 150 | ?> |
| 151 | <label><input name="enable_blocks_comments" type="checkbox" <?php checked( $this->are_blocks_enabled(), true, true ); ?> value="1" /> |
| 152 | <?php esc_html_e( 'Enable blocks in comments', 'jetpack-mu-wpcom' ); ?> |
| 153 | </label> |
| 154 | <?php |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Is verbum commenting enabled? |
| 159 | * |
| 160 | * @return boolean |
| 161 | */ |
| 162 | public function is_verbum_enabled() { |
| 163 | return (bool) get_option( 'enable_verbum_commenting', $this->default_verbum_commenting ); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Is verbum commenting enabled? |
| 168 | * |
| 169 | * @return boolean |
| 170 | */ |
| 171 | public function are_blocks_enabled() { |
| 172 | return (bool) get_option( 'enable_blocks_comments', $this->default_allow_blocks ); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Custom Comment Greeting Text |
| 177 | */ |
| 178 | public function comment_form_greeting_setting() { |
| 179 | |
| 180 | // The greeting. |
| 181 | $greeting = get_option( 'highlander_comment_form_prompt', $this->default_greeting ); |
| 182 | |
| 183 | if ( empty( $greeting ) ) { |
| 184 | $greeting = $this->default_greeting; |
| 185 | } |
| 186 | |
| 187 | ?> |
| 188 | |
| 189 | <input type="text" name="highlander_comment_form_prompt" id="jetpack-comment-form-greeting" value="<?php echo esc_attr( $greeting ); ?>" class="regular-text"> |
| 190 | <p class="description"><?php esc_html_e( 'A few catchy words to motivate your readers to comment', 'jetpack-mu-wpcom' ); ?></p> |
| 191 | |
| 192 | <?php |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Sanitize the clever comment greeting |
| 197 | * |
| 198 | * @param string $val The contact form greeting string. |
| 199 | * @return string|boolean |
| 200 | */ |
| 201 | public function comment_form_greeting_sanitize( $val ) { |
| 202 | |
| 203 | // Delete if empty or the default. |
| 204 | if ( empty( $val ) || ( $this->default_greeting === $val ) ) { |
| 205 | delete_option( 'highlander_comment_form_prompt' ); |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | return wp_kses( $val, array() ); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Sanitize the allow blocks in comments setting |
| 214 | * |
| 215 | * @param string $val The allow blocks in comments string. |
| 216 | * @return string |
| 217 | */ |
| 218 | public function allow_blocks_sanitize( $val ) { |
| 219 | return $val ? '1' : '0'; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Sanitize the verbum commenting setting |
| 224 | * |
| 225 | * @param string $val The verbum commenting string. |
| 226 | * @return string |
| 227 | */ |
| 228 | public function enable_verbum_commenting_sanitize( $val ) { |
| 229 | return $val ? '1' : '0'; |
| 230 | } |
| 231 | } |