settings = Plugin::get_settings( 'posts' ); add_filter( 'adminease_settings_fields', [ $this, 'adminease_settings_fields' ] ); if( empty( $this->settings['close_comments'] ) ) { return; } add_filter( 'comments_open', '__return_false', 20 ); } /** * Adds the switch to the Posts tab. * * @param array $fields The settings fields keyed by tab. * * @return array The modified settings fields. */ public function adminease_settings_fields( array $fields ): array { $fields['posts']['fields'][] = [ 'type' => 'switch', 'id' => 'close-comments', 'name' => 'adminease[posts][close_comments]', 'value' => $this->settings['close_comments'] ?? '', 'label_class' => 'pwp-switch', 'input_class' => 'pwp-field-input', 'label' => __( 'Close comments, keep existing ones visible', 'adminease' ), 'risk' => 'safe', 'breaks' => __( 'Visitors can no longer leave comments or product reviews.', 'adminease' ), 'description' => __( 'Stops new comments everywhere. Comments already on your site stay visible. Product reviews close too.', 'adminease' ), ]; return $fields; } }