true ) ); add_filter('wpcf7_validate_anr_nocaptcha', array($this, 'wpcf7_verify'), 10, 2); } elseif( function_exists( 'wpcf7_add_shortcode' ) ){ wpcf7_add_shortcode('anr_nocaptcha', array($this, 'wpcf7_form_field'), true); add_filter('wpcf7_validate_anr_nocaptcha', array($this, 'wpcf7_verify'), 10, 2); } if ( '1' == anr_get_option( 'bb_new' )) { add_action ('bbp_theme_before_topic_form_submit_wrapper', array($this, 'form_field'), 99); add_action ('bbp_new_topic_pre_extras', array($this, 'bb_new_verify') ); } if ( '1' == anr_get_option( 'bb_reply' )) { add_action ('bbp_theme_before_reply_form_submit_wrapper', array($this, 'form_field'), 99); add_action ('bbp_new_reply_pre_extras', array($this, 'bb_reply_verify'), 10, 2 ); } } function total_captcha() { return self::$captcha_count; } function captcha_form_field() { self::$captcha_count++; $no_js = anr_get_option( 'no_js' ); $site_key = trim(anr_get_option( 'site_key' )); $number = $this->total_captcha(); $field = '
'; if ( 1 == $no_js ) { $field .=''; } return $field; } function footer_script() { $number = $this->total_captcha(); static $included = false; if ( !$number ) return; if ( $included ) return; $included = true; $site_key = trim(anr_get_option( 'site_key' )); $theme = anr_get_option( 'theme', 'light' ); $size = anr_get_option( 'size', 'normal' ); $language = trim(anr_get_option( 'language' )); $lang = ""; if ( $language ) $lang = "&hl=$language"; ?> get_var( "SELECT ID FROM $wpdb->posts WHERE post_type = 'anr-post' LIMIT 1"); if( ! $post_id ){ $wpdb->insert( $wpdb->posts, array( 'post_type' => 'anr-post' ) ); $post_id = $wpdb->insert_id; } $post_id = absint( $post_id ); return $post_id; } function show_login_captcha(){ global $wpdb; $show_captcha = true; $ip = $_SERVER['REMOTE_ADDR']; //filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ); $count = absint( anr_get_option( 'failed_login_allow' ) ); $post_id = $this->post_id(); if( $count && $post_id && filter_var( $ip, FILTER_VALIDATE_IP ) ){ $user_logins = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, md5( $ip ) ) ); if( count( $user_logins ) < $count && count( array_unique( $user_logins ) ) <= 1 ){ $show_captcha = false; } } return $show_captcha; } function login_form_field() { if( $this->show_login_captcha() ){ $this->form_field(); } } function login_form_return( $field = '' ) { if ( $this->show_login_captcha() ) { if ( is_user_logged_in() && anr_get_option( 'loggedin_hide' ) ) { return $field; } $field = anr_captcha_form_field( false ); } return $field; } function wc_form_field() { if( ! is_user_logged_in() && 'yes' == get_option( 'woocommerce_enable_signup_and_login_from_checkout', 'yes' ) && '1' == anr_get_option( 'registration' ) ){ $this->form_field(); } elseif( '1' == anr_get_option( 'wc_checkout' ) ){ $this->form_field(); } } function ms_form_field( $errors ) { $loggedin_hide = anr_get_option( 'loggedin_hide' ); if ( is_user_logged_in() && $loggedin_hide ) return; if ( $errmsg = $errors->get_error_message('anr_error') ) { echo '

' . $errmsg . '

'; } anr_captcha_form_field( true ); } function comment_form_field( $defaults ) { $loggedin_hide = anr_get_option( 'loggedin_hide' ); if ( is_user_logged_in() && $loggedin_hide ) return $defaults; $defaults = $defaults . anr_captcha_form_field( false ); return $defaults; } function verify() { $loggedin_hide = anr_get_option( 'loggedin_hide' ); if ( is_user_logged_in() && $loggedin_hide ) return true; return anr_verify_captcha(); } function fepcf_verify ( $errors ) { $error_message = str_replace(__('ERROR: ', 'advanced-nocaptcha-recaptcha'), '', anr_get_option( 'error_message' )); if ( ! $this->verify() ){ $errors->add('anr_error', $error_message); } } function login_verify ( $user, $username = '', $password = '' ) { global $wpdb; $show_captcha = $this->show_login_captcha(); if ( ! ( $user instanceof WP_User ) ){ if( ! $show_captcha && $username && ( $post_id = $this->post_id() ) ){ if( is_email( $username ) ){ $user_data = get_user_by( 'email', $username ); if( $user_data ){ $username = $user_data->user_login; } } $wpdb->insert( $wpdb->postmeta, array( 'post_id' => $post_id, 'meta_key' => md5( $_SERVER['REMOTE_ADDR'] ), 'meta_value' => $username ), array( '%d', '%s', '%s' ) ); } return $user; } if ( $show_captcha && ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); return new WP_Error( 'anr_error', $error_message ); } return $user; } function clear_data( $user_login, $user ){ global $wpdb; if( $post_id = $this->post_id() ){ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND ( meta_key = %s OR meta_value = %s )", $post_id, md5( $_SERVER['REMOTE_ADDR'] ), $user_login ) ); } } function registration_verify ( $errors, $sanitized_user_login, $user_email ) { if ( ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); $errors->add( 'anr_error', $error_message ); } return $errors; } function ms_form_field_verify( $result ) { if ( ! $this->verify() ) { $error_message = str_replace(__('ERROR: ', 'advanced-nocaptcha-recaptcha'), '', anr_get_option( 'error_message' )); $result['errors']->add( 'anr_error', $error_message ); } return $result; } function lostpassword_verify( $result, $user_id ) { if ( ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); return new WP_Error( 'anr_error', $error_message ); } return $result; } function lostpassword_verify_44( $errors ) { if ( ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); $errors->add('anr_error', $error_message); } } function reset_password_verify( $errors, $user ) { if ( ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); $errors->add('anr_error', $error_message); } } function comment_verify( $commentdata ) { if ( ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); wp_die( $error_message, 200 ); } return $commentdata; } function wpcf7_form_field( $tag ) { $loggedin_hide = anr_get_option( 'loggedin_hide' ); if ( is_user_logged_in() && $loggedin_hide ) return ''; return anr_captcha_form_field( false ). sprintf( '', $tag->name ); } function wpcf7_verify( $result, $tag ) { if ( ! $this->verify() ) { $error_message = str_replace(__('ERROR: ', 'advanced-nocaptcha-recaptcha'), '', anr_get_option( 'error_message' )); $result->invalidate( $tag, $error_message ); } return $result; } function bb_new_verify( $forum_id ) { if ( ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); bbp_add_error('anr_error', $error_message); } } function bb_reply_verify( $topic_id, $forum_id ) { if ( ! $this->verify() ) { $error_message = anr_get_option( 'error_message' ); bbp_add_error('anr_error', $error_message); } } function wc_checkout_verify() { if( ! is_user_logged_in() && 'yes' == get_option( 'woocommerce_enable_signup_and_login_from_checkout', 'yes' ) && '1' == anr_get_option( 'registration' ) ){ // verification done during ragistration, So no need any more verification } elseif( ! $this->verify() ){ $error_message = anr_get_option( 'error_message' ); wc_add_notice( $error_message, 'error' ); } } } //END CLASS } //ENDIF add_action('init', array(anr_captcha_class::init(), 'actions_filters'));