*
';
/* Will retrieve the get varibale and prints a message from url if the captcha is wrong */
if(isset($_GET['captcha']) && $_GET['captcha'] == 'confirm_error' ) {
echo '';;
$_SESSION['captcha_error'] = '';
}
echo '
';
return true;
}
/* Hook to find out the errors while logging in */
function include_captcha_login_errors($errors){
if( isset( $_REQUEST['action'] ) && 'register' == $_REQUEST['action'] )
return($errors);
if($_SESSION['captcha_code'] != $_REQUEST['captcha_code']){
return $errors.'';
}
return $errors;
}
/* Hook to redirect after captcha confirmation */
function include_captcha_login_redirect($url){
/* Captcha mismatch */
if(isset($_SESSION['captcha_code']) && isset($_REQUEST['captcha_code']) && $_SESSION['captcha_code'] != $_REQUEST['captcha_code']){
$_SESSION['captcha_error'] = __('Incorrect captcha confirmation!', 'wpcaptchadomain');
wp_clear_auth_cookie();
return $_SERVER["REQUEST_URI"]."/?captcha='confirm_error'";
}
/* Captcha match: take to the admin panel */
else{
return home_url('/wp-admin/');
}
}
/* */
/* Captcha for Comments ends here */
$comment_captcha = get_option('wpcaptcha_comments');
if($comment_captcha == 'yes'){
global $wp_version;
if( version_compare($wp_version,'3','>=') ) { // wp 3.0 +
add_action( 'comment_form_after_fields', 'include_wp_captcha_comment_form_wp3', 1 );
add_action( 'comment_form_logged_in_after', 'include_wp_captcha_comment_form_wp3', 1 );
}
// for WP before WP 3.0
add_action( 'comment_form', 'include_captcha_comment_form' );
add_filter( 'preprocess_comment', 'include_captcha_comment_post' );
}
/* Function to include captcha for comments form */
function include_captcha_comment_form(){
$c_registered = get_option('wpcaptcha_registered');
if ( is_user_logged_in() && $c_registered == 'yes') {
return true;
}
echo '
*
';
return true;
}
/* Function to include captcha for comments form > wp3 */
function include_wp_captcha_comment_form_wp3(){
$c_registered = get_option('wpcaptcha_registered');
if ( is_user_logged_in() && $c_registered == 'yes') {
return true;
}
echo '
*
';
remove_action( 'comment_form', 'include_captcha_comment_form' );
return true;
}
// this function checks captcha posted with the comment
function include_captcha_comment_post($comment) {
$c_registered = get_option('wpcaptcha_registered');
if (is_user_logged_in() && $c_registered == 'yes') {
return $comment;
}
// skip captcha for comment replies from the admin menu
if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'replyto-comment' &&
( check_ajax_referer( 'replyto-comment', '_ajax_nonce', false ) || check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment', false ) ) ) {
// skip capthca
return $comment;
}
// Skip captcha for trackback or pingback
if ( $comment['comment_type'] != '' && $comment['comment_type'] != 'comment' ) {
// skip captcha
return $comment;
}
// If captcha is empty
if(empty($_REQUEST['captcha_code']))
wp_die( __('CAPTCHA cannot be empty.', 'wpcaptchadomain' ) );
// captcha was matched
if($_SESSION['captcha_code'] == $_REQUEST['captcha_code']) return($comment);
else wp_die( __('Error: Incorrect CAPTCHA. Press your browser\'s back button and try again.', 'wpcaptchadomain'));
}
/* */
// Add captcha in the register form
$register_captcha = get_option('wpcaptcha_register');
if($register_captcha == 'yes'){
add_action('register_form', 'include_wp_captcha_register');
add_action( 'register_post', 'include_captcha_register_post', 10, 3 );
add_action( 'signup_extra_fields', 'include_wp_captcha_register' );
add_filter( 'wpmu_validate_user_signup', 'include_captcha_register_validate' );
}
/* Function to include captcha for register form */
function include_wp_captcha_register($default){
echo '
*
';
return true;
}
/* This function checks captcha posted with registration */
function include_captcha_register_post($login,$email,$errors) {
// If captcha is blank - add error
if ( isset( $_REQUEST['captcha_code'] ) && "" == $_REQUEST['captcha_code'] ) {
$errors->add('captcha_blank', ''.__('ERROR', 'wpcaptchadomain').': '.__('Please complete the CAPTCHA.', 'wpcaptchadomain'));
return $errors;
}
if ( isset( $_REQUEST['captcha_code'] ) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'] )) {
// captcha was matched
} else {
$errors->add('captcha_wrong', ''.__('ERROR', 'wpcaptchadomain').': '.__('That CAPTCHA was incorrect.', 'wpcaptchadomain'));
}
return($errors);
}
/* End of the function include_captcha_register_post */
function include_captcha_register_validate($results) {
if ( isset( $_REQUEST['captcha_code'] ) && "" == $_REQUEST['captcha_code'] ) {
$results['errors']->add('captcha_blank', ''.__('ERROR', 'wpcaptchadomain').': '.__('Please complete the CAPTCHA.', 'wpcaptchadomain'));
return $results;
}
if ( isset( $_REQUEST['captcha_code'] ) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'] )) {
// captcha was matched
} else {
$results['errors']->add('captcha_wrong', ''.__('ERROR', 'wpcaptchadomain').': '.__('That CAPTCHA was incorrect.', 'wpcaptchadomain'));
}
return($results);
}
/* End of the function include_captcha_register_validate */
$lost_captcha = get_option('wpcaptcha_lost');
// Add captcha into lost password form
if($lost_captcha == 'yes'){
add_action( 'lostpassword_form', 'include_wp_captcha_lostpassword' );
add_action( 'lostpassword_post', 'include_wp_captcha_lostpassword_post', 10, 3 );
}
/* Function to include captcha for lost password form */
function include_wp_captcha_lostpassword($default){
echo '
*
';
}
function include_wp_captcha_lostpassword_post() {
if( isset( $_REQUEST['user_login'] ) && "" == $_REQUEST['user_login'] )
return;
// If captcha doesn't entered
if ( isset( $_REQUEST['captcha_code'] ) && "" == $_REQUEST['captcha_code'] ) {
wp_die( __( 'Please complete the CAPTCHA.', 'wpcaptchadomain' ) );
}
// Check entered captcha
if ( isset( $_REQUEST['captcha_code'] ) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'] )) {
return;
} else {
wp_die( __( 'Error: Incorrect CAPTCHA. Press your browser\'s back button and try again.', 'wpcaptchadomain' ) );
}
}
?>