Created
November 20, 2017 12:18
-
-
Save flayder/8765b047ad6f27801f4bfaf5122f3c78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment