=' ) ) { add_filter( 'pre_comment_approved', array( $this, 'comment_verify_490' ), 99 ); } else { add_filter( 'preprocess_comment', array( $this, 'comment_verify' ) ); } } if ( function_exists( 'wpcf7_add_form_tag' ) ) { $cf7_option = get_option( 'wpcf7' ); if ( ! is_array( $cf7_option ) || empty( $cf7_option['recaptcha'] ) ) { remove_filter( 'wpcf7_form_hidden_fields', 'wpcf7_recaptcha_add_hidden_fields', 100, 1 ); } wpcf7_add_form_tag( 'anr_nocaptcha', array( $this, 'wpcf7_form_field' ), array( 'name-attr' => 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 ( anr_is_form_enabled( 'bbp_new' ) ) { add_action( 'bbp_theme_before_topic_form_submit_wrapper', array( $this, 'form_field' ), 99 ); add_action( 'bbp_new_topic_pre_extras', array( $this, 'bbp_new_verify' ) ); } if ( anr_is_form_enabled( 'bbp_reply' ) ) { add_action( 'bbp_theme_before_reply_form_submit_wrapper', array( $this, 'form_field' ), 99 ); add_action( 'bbp_new_reply_pre_extras', array( $this, 'bbp_reply_verify' ), 10, 2 ); } } function add_error_to_mgs( $mgs = false ) { if ( false === $mgs ) { $mgs = anr_get_option( 'error_message', '' ); } return '' . __( 'ERROR', 'advanced-nocaptcha-recaptcha' ) . ': ' . $mgs; } 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(); $version = anr_get_option( 'captcha_version', 'v2_checkbox' ); $field = '
'; if ( 'v3' === $version ) { $field .= ''; } $field .= '
'; if ( 1 == $no_js && 'v2_checkbox' === $version ) { $field .= ''; } return $field; } function footer_script() { static $included = false; $number = $this->total_captcha(); $version = anr_get_option( 'captcha_version', 'v2_checkbox' ); if ( ! $number && ( 'v3' !== $version || 'all_pages' !== anr_get_option( 'v3_script_load', 'all_pages' ) ) ) { return; } if ( $included ) { return; } $included = true; if ( 'v2_checkbox' === $version ) { $this->v2_checkbox_script(); } elseif ( 'v2_invisible' === $version ) { $this->v2_invisible_script(); } elseif ( 'v3' === $version ) { $this->v3_script(); } } function v2_checkbox_script() { $number = $this->total_captcha(); ?> v2_invisible_script(); $language = trim( anr_get_option( 'language' ) ); $site_key = trim( anr_get_option( 'site_key' ) ); $lang = ''; if ( $language ) { $lang = '&hl=' . $language; } $google_url = 'https://www.google.com/recaptcha/api.js?render=' . $site_key . $lang; ?> 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 = $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' ) && anr_is_form_enabled( 'registration' ) ) { $this->form_field(); } elseif ( anr_is_form_enabled( '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 ) { if ( ! $this->verify() ) { $errors->add( 'anr_error', anr_get_option( 'error_message' ) ); } } function login_verify( $user, $username = '', $password = '' ) { global $wpdb; if ( ! $username ) { return $user; } $show_captcha = $this->show_login_captcha(); if ( ! ( $user instanceof WP_User ) ) { if ( ! $show_captcha && ( $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() ) { return new WP_Error( 'anr_error', $this->add_error_to_mgs() ); } 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() ) { $errors->add( 'anr_error', $this->add_error_to_mgs() ); } return $errors; } function wc_registration_verify( $errors, $sanitized_user_login, $user_email ) { if ( defined( 'WOOCOMMERCE_CHECKOUT' ) && ! anr_is_form_enabled( 'wc_checkout' ) ) { return $errors; } if ( ! $this->verify() ) { $errors->add( 'anr_error', anr_get_option( 'error_message' ) ); } return $errors; } function bp_form_field() { $loggedin_hide = anr_get_option( 'loggedin_hide' ); if ( is_user_logged_in() && $loggedin_hide ) { return; } do_action( 'bp_anr_error_errors' ); anr_captcha_form_field( true ); } function bp_registration_verify() { if ( ! $this->verify() ) { buddypress()->signup->errors['anr_error'] = anr_get_option( 'error_message' ); } } function ms_form_field_verify( $result ) { if ( ! $this->verify() ) { $result['errors']->add( 'anr_error', anr_get_option( 'error_message' ) ); } return $result; } function lostpassword_verify( $result, $user_id ) { if ( ! $this->verify() ) { return new WP_Error( 'anr_error', $this->add_error_to_mgs() ); } return $result; } function lostpassword_verify_44( $errors ) { if ( ! $this->verify() ) { $errors->add( 'anr_error', $this->add_error_to_mgs() ); } } function reset_password_verify( $errors, $user ) { if ( ! $this->verify() ) { $errors->add( 'anr_error', $this->add_error_to_mgs() ); } } function comment_verify( $commentdata ) { if ( ! $this->verify() ) { wp_die( '

' . $this->add_error_to_mgs() . '

', __( 'Comment Submission Failure' ), array( 'response' => 403, 'back_link' => true, ) ); } return $commentdata; } function comment_verify_490( $approved ) { if ( ! $this->verify() ) { return new WP_Error( 'anr_error', $this->add_error_to_mgs(), 403 ); } return $approved; } 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() ) { $result->invalidate( $tag, anr_get_option( 'error_message' ) ); } return $result; } function bbp_new_verify( $forum_id ) { if ( ! $this->verify() ) { bbp_add_error( 'anr_error', $this->add_error_to_mgs() ); } } function bbp_reply_verify( $topic_id, $forum_id ) { if ( ! $this->verify() ) { bbp_add_error( 'anr_error', $this->add_error_to_mgs() ); } } function wc_checkout_verify( $data, $errors ) { $is_reg_enable = apply_filters( 'woocommerce_checkout_registration_enabled', 'yes' === get_option( 'woocommerce_enable_signup_and_login_from_checkout' ) ); $is_reg_required = apply_filters( 'woocommerce_checkout_registration_required', 'yes' !== get_option( 'woocommerce_enable_guest_checkout' ) ); if ( ! is_user_logged_in() && $is_reg_enable && anr_is_form_enabled( 'registration' ) && ( $is_reg_required || ! empty( $data['createaccount'] ) ) ) { // verification done during ragistration, So no need any more verification } elseif ( ! $this->verify() ) { $errors->add( 'anr_error', anr_get_option( 'error_message' ) ); } } } //END CLASS } //ENDIF add_action( 'init', array( anr_captcha_class::init(), 'actions_filters' ), -9 );