Please or Register to create posts and topics.

Add Captcha for guest postings

Page 1 of 5Next

For protection against spam and bots it can be necessary to use a captcha in the forums – especially when the guest posting functionality is enabled. There are already a lot of existing captcha plugins available for WordPress. Thats why I dont want to ship another one with the forum at the moment. Two of the available hooks and filters for the Asgaros Forum plugin allows you to integrate them into your forum:

  • asgarosforum_editor_custom_content_bottom hook: Allows you to add custom functions to the bottom area of the editor
  • asgarosforum_filter_insert_custom_validation filter: Can be used for custom checks to decide if a user is allowed to post new content

In this example we want to integrate the WordPress extension Really Simple CAPTCHA into our forum. To do this you just have to add this code to your themes functions.php file:

function editor_custom_content_bottom() {
  global $asgarosforum;
  if (!is_user_logged_in() && $asgarosforum->options['allow_guest_postings']) {
    $captcha_instance = new ReallySimpleCaptcha();
    $captcha_word = $captcha_instance->generate_random_word();
    $captcha_prefix = mt_rand();
    $captcha_file = $captcha_instance->generate_image($captcha_prefix, $captcha_word);
    $captcha_url = plugins_url().'/really-simple-captcha/tmp/'.$captcha_file;
    echo '<div class="editor-row editor-row-captcha">';
    echo '<span class="row-title">'.__('Captcha:', 'asgaros-forum').'</span>';
    echo '<img src="'.$captcha_url.'" /><br />';
    echo '<input type="text" name="captcha_value">';
    echo '<input type="hidden" name="captcha_prefix" value="'.$captcha_prefix.'">';
    echo '</div>';
  }
}
add_action('asgarosforum_editor_custom_content_bottom', 'editor_custom_content_bottom');
function insert_custom_validation($status) {
  global $asgarosforum;
  if (!is_user_logged_in() && $asgarosforum->options['allow_guest_postings']) {
    $captcha_instance = new ReallySimpleCaptcha();
    $captcha_value = $_POST['captcha_value'];
    $captcha_prefix = $_POST['captcha_prefix'];
    $captcha_correct = $captcha_instance->check($captcha_prefix, $captcha_value);
    $captcha_instance->remove($captcha_prefix);
    if (!$captcha_correct) {
      $asgarosforum->info = __('You must enter the correct captcha.', 'asgaros-forum');
      return false;
    }
  }
  return $status;
}
add_filter('asgarosforum_filter_insert_custom_validation', 'insert_custom_validation');

 

Alternative Google reCAPTCHA implementation

https://wordpress.org/plugins/recaptcha-for-asgaros-forum/

afalconr has reacted to this post.
afalconr
If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Its possible and how to integrate Better WordPress reCAPTCHA plugin?  Thanks….

Hello Zmajur,

I had a look at the plugin-site but couldnt find any API-documentation there. Maybe you can ask in their support forums which function-calls you want to use if you want to implement this plugin in your own extension. What you need are basically two things:

  • the code for displaying the captcha
  • the code to validate the user-input with the captcha

When the plugin-author could provide this kind of information to you, it would be possible for me to find a way. I also plan to integrate a captcha-functionality inside the Asgaros Forum extension by default one day.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Thank you for support. I on my way to ask them kindly to provides codes you need.

I was using Better WordPress reCAPTCHA, but now I see this plugin isn’t tested with the newest WP versions, so any solutions for this ?

Thanks you in advance.

Best regards
Uvan

Hello IAF,

you should try to contact the author of that plugin so he can release an updated version.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Hi

Thank you and I did that… Any other soltions?
I understand there is other possibilitys, but then, I don’t know how to implement them :- )

But anyway, I would like to say big thanks for this cool forum plugin!

As a quick workaround you could try to use the captcha-plugin and the code described in the first post. You just have to install it and put the code into your themes functions.php file. 🙂

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

The best Forum , I Love it. I put the Code to the Theme functions.php and it works and works not. Is it an act in the update version captcha include to the Forum ? Without manuall Codesnipets or  how it works ? Sorry for my bad English. Greeting from Munich … Germany … hari

Hast du auch die Really Simple Captcha-Erweiterung installert? Diese wird nämlich dafür benötigt.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!
Page 1 of 5Next