Skip to content

Instantly share code, notes, and snippets.

Last active August 16, 2016 21:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Asgaros/6d4b88b1f5013efb910d9fcd01284698 to your computer and use it in GitHub Desktop.
Asgaros Forum: Captcha example
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);
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment