<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
* Jetpack comments admin menu file.
* @package automattic/jetpack
if ( ! defined( 'ABSPATH' ) ) {
* Class Jetpack_Comments_Settings
* This class represents the comments settings functionality.
class Jetpack_Comments_Settings {
/** Variables *************************************************************/
* The Jetpack Comments singleton
* @var Highlander_Comments_Base
public $jetpack_comments;
* The default comment form greeting - blank to start with
public $default_greeting = ''; // Set in constructor.
* The default comment form color scheme - an empty array to start with
public $color_schemes = array();
public static function init() {
static $instance = false;
$instance = new Jetpack_Comments_Settings( Jetpack_Comments::init() );
* @param Highlander_Comments_Base $jetpack_comments The Jetpack Comments singleton.
public function __construct( Highlander_Comments_Base $jetpack_comments ) {
$this->jetpack_comments = $jetpack_comments;
add_action( 'admin_init', array( $this, 'add_settings' ) );
/** Private Methods ****************************************************** */
* Set any global variables or class variables
protected function setup_globals() {
// Default option values.
$this->default_greeting = __( 'Leave a Reply', 'jetpack' );
// Possible color schemes.
$this->color_schemes = array(
'light' => __( 'Light', 'jetpack' ),
'dark' => __( 'Dark', 'jetpack' ),
'transparent' => __( 'Transparent', 'jetpack' ),
/** Settings ************************************************************* */
* Add the Jetpack settings to WordPress's discussions page
public function add_settings() {
__( 'Comments', 'jetpack' ),
array( $this, 'comment_form_settings_section' ),
'highlander_comment_form_prompt',
__( 'Greeting Text', 'jetpack' ),
array( $this, 'comment_form_greeting_setting' ),
'highlander_comment_form_prompt',
array( $this, 'comment_form_greeting_sanitize' )
'jetpack_comment_form_color_scheme',
__( 'Color Scheme', 'jetpack' ),
array( $this, 'comment_form_color_scheme_setting' ),
'jetpack_comment_form_color_scheme',
array( $this, 'comment_form_color_scheme_sanitize' )
* Discussions setting section blurb
public function comment_form_settings_section() {
<p id="jetpack-comments-settings"><?php esc_html_e( 'Adjust your Comments form with a clever greeting and color-scheme.', 'jetpack' ); ?></p>
* Custom Comment Greeting Text
public function comment_form_greeting_setting() {
$greeting = get_option( 'highlander_comment_form_prompt', $this->default_greeting );
<input type="text" name="highlander_comment_form_prompt" id="jetpack-comment-form-greeting" value="<?php echo esc_attr( $greeting ); ?>" class="regular-text">
<p class="description"><?php esc_html_e( 'A few catchy words to motivate your readers to comment', 'jetpack' ); ?></p>
* Sanitize the clever comment greeting
* @param string $val The contact form greeting string.
public function comment_form_greeting_sanitize( $val ) {
// Delete if empty or the default.
if ( empty( $val ) || ( $this->default_greeting === $val ) ) {
delete_option( 'highlander_comment_form_prompt' );
return wp_kses( $val, array() );
* Comment Form Color Scheme Setting
public function comment_form_color_scheme_setting() {
$scheme = get_option( 'jetpack_comment_form_color_scheme', $this->jetpack_comments->default_color_scheme );
<legend class="screen-reader-text"><?php esc_html_e( 'Color Scheme', 'jetpack' ); ?></legend>
<?php foreach ( $this->color_schemes as $key => $label ) : ?>
<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 ); ?>>
<?php echo esc_attr( $label ); ?>
* Sanitize the color scheme
* @param string $val The color scheme string.
public function comment_form_color_scheme_sanitize( $val ) {
// Delete the option if it's unknown, or the default.
empty( $val ) || ! array_key_exists( $val, $this->color_schemes )
$val === $this->jetpack_comments->default_color_scheme
delete_option( 'jetpack_comment_form_color_scheme' );
Jetpack_Comments_Settings::init();