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