| @@ -3,8 +3,16 @@ | ||
| 3 | 3 | * Jetpack comments admin menu file. |
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | + | |
| 8 | +use Automattic\Jetpack\Comments\Block_Editor; | |
| 9 | +use Automattic\Jetpack\Comments\Comments; | |
| 10 | + | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit( 0 ); | |
| 13 | +} | |
| 14 | + | |
| 7 | 15 | /** |
| 8 | 16 | * Class Jetpack_Comments_Settings |
| 9 | 17 | * This class represents the comments settings functionality. |
| 10 | 18 | */ |
| @@ -127,8 +135,51 @@ | ||
| 127 | 135 | 'discussion', |
| 128 | 136 | 'jetpack_comment_form_color_scheme', |
| 129 | 137 | array( $this, 'comment_form_color_scheme_sanitize' ) |
| 130 | 138 | ); |
| 139 | + | |
| 140 | + // The rebuilt comment form is what offers blocks; the package may lag this file on a staged deploy. | |
| 141 | + if ( ! class_exists( Block_Editor::class ) || ! Comments::is_enabled() ) { | |
| 142 | + return; | |
| 143 | + } | |
| 144 | + | |
| 145 | + add_settings_field( | |
| 146 | + 'enable_blocks_comments', | |
| 147 | + __( 'Allow Blocks', 'jetpack' ), | |
| 148 | + array( $this, 'allow_blocks_field' ), | |
| 149 | + 'discussion', | |
| 150 | + 'jetpack_comment_form' | |
| 151 | + ); | |
| 152 | + | |
| 153 | + register_setting( | |
| 154 | + 'discussion', | |
| 155 | + 'enable_blocks_comments', | |
| 156 | + array( $this, 'allow_blocks_sanitize' ) | |
| 157 | + ); | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Blocks in comments setting. | |
| 162 | + */ | |
| 163 | + public function allow_blocks_field() { | |
| 164 | + ?> | |
| 165 | + | |
| 166 | + <label> | |
| 167 | + <input name="enable_blocks_comments" type="checkbox" value="1" <?php checked( (bool) get_option( 'enable_blocks_comments', true ) ); ?>> | |
| 168 | + <?php esc_html_e( 'Enable blocks in comments', 'jetpack' ); ?> | |
| 169 | + </label> | |
| 170 | + | |
| 171 | + <?php | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Sanitize the blocks in comments setting. | |
| 176 | + * | |
| 177 | + * @param mixed $val The submitted value. | |
| 178 | + * @return string | |
| 179 | + */ | |
| 180 | + public function allow_blocks_sanitize( $val ) { | |
| 181 | + return $val ? '1' : '0'; | |
| 131 | 182 | } |
| 132 | 183 | |
| 133 | 184 | /** |
| 134 | 185 | * Discussions setting section blurb |