Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions admin/comment_form_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public function sanitize_settings ( $data ){

$data['text_before'] = wp_kses_post( $data['text_before'] );
$data['text_after'] = wp_kses_post( $data['text_after'] );
$data['recaptcha_site_key'] = wp_kses_post( $data['recaptcha_site_key'] );
$data['recaptcha_secret_key'] = wp_kses_post( $data['recaptcha_secret_key'] );

return $data;
}
Expand Down
2 changes: 1 addition & 1 deletion admin/views/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function render_mailchimp_field_callback() {
<img src="<?php echo esc_url( $images_url . 'key.svg' ) ?>" class="mr-2" alt=""> API key
</div>
<div class="input-wrapper">
<input name="commentform_settings[recaptcha_site_key]" type="text"
<input name="commentform_settings[mailchimp_api_key]" type="text"
<?php echo ( sc_fs()->is__premium_only() ? '' : 'disabled' ) ?>>
<div class="input-append copy-button">COPY</div>
</div>
Expand Down
34 changes: 34 additions & 0 deletions frontend/comment_form_frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function __construct() {
add_action('wp_footer', array($this, 'footer_output'));
// add comment form shortcode
add_shortcode('comment-form', array($this, 'shortcode'));
// add the pro feature: recaptcha
add_action( 'wp_enqueue_scripts', array($this, 'enqueue_recaptcha_script'));
add_action( 'comment_form_after', array($this, 'add_recaptcha_to_comment_form'));
}

/**
Expand Down Expand Up @@ -203,4 +206,35 @@ public function shortcode($atts = array(), $content = '') {
return $output;
}

/**
* show the recaptcha badge
*
* @since 1.0.0
*/
public function enqueue_recaptcha_script() {
if (sc_fs()->is__premium_only()) {
if ( is_single() && comments_open() ) {
wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), null, true );
}
}
}

/**
* ensure that the reCAPTCHA badge and the required scripts
* are only loaded on pages where the comment form is displayed
*
* @since 1.0.0
*/
public function add_recaptcha_to_comment_form() {
$options = $this->options();
echo print_r($options);

if ( is_single() && comments_open() ) :
if ( isset($options['recaptcha_site_key']) && $options['recaptcha_site_key'] != '' ) : ?>
<div id="recaptcha-placeholder">
<div class="g-recaptcha" data-sitekey="<?php echo esc_attr( $options['recaptcha_site_key'] ); ?>"></div>
</div>
<?php endif;
endif;
}
}