Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elhardoum/f3981ebc051b8b29ba2cf36ba393f033 to your computer and use it in GitHub Desktop.
Save elhardoum/f3981ebc051b8b29ba2cf36ba393f033 to your computer and use it in GitHub Desktop.
<?php
add_action('bbpm_conversation_form_additional_fields', function() {
/**
* Follows is just an example on how to implement a simple captcha,
* You can set the answer in a cookie or database option and fetch
* it with a unique key, or store it somewhere else, use honeypot and
* spam hidden traps, reCaptcha, or simply a captcha image..
*/
if( ! se_bbpm_add_spam_check() )
return; // not enabled for this user
$rand1 = rand(5,20); // generate random number
$rand2 = rand(1,9); // generate random number
$operations = array(
'+' => 'plus',
'-' => 'minus'
// add more as you wish, be careful with floats while *|/
);
$operationRand = array_rand($operations); // get a random operation from operations list
?>
<p>
<label>
<strong style="display: inline;">Spam test:</strong> What's <?php echo $rand1 . ' ' . $operations[$operationRand] . ' ' . $rand2; ?>? <br/>
<input type="text" name="capCheck[value]" />
<input type="hidden" name="capCheck[operation]" value="<?php echo $operations[$operationRand]; ?>" />
<input type="hidden" name="capCheck[a]" value="<?php echo $rand1; ?>" />
<input type="hidden" name="capCheck[b]" value="<?php echo $rand2; ?>" />
</label>
</p>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment