=' ) ) { 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 = '
' . $errmsg . '
'; } $this->form_field(); } function verify( $response = false ) { static $last_verify = null; if ( is_user_logged_in() && anr_get_option( 'loggedin_hide' ) ) { return true; } $secre_key = trim( anr_get_option( 'secret_key' ) ); $remoteip = $_SERVER['REMOTE_ADDR']; $verify = false; if ( in_array( $remoteip, array_filter( explode( '\n', anr_get_option( 'whitelisted_ips' ) ) ) ) ) { return true; } if ( false === $response ) { $response = isset( $_POST['g-recaptcha-response'] ) ? $_POST['g-recaptcha-response'] : ''; } $pre_check = apply_filters( 'anr_verify_captcha_pre', null, $response ); if ( null !== $pre_check ) { return $pre_check; } if ( ! $secre_key ) { // if $secre_key is not set return true; } if ( ! $response || ! $remoteip ) { return $verify; } if ( null !== $last_verify ) { return $last_verify; } $url = apply_filters( 'anr_google_verify_url', 'https://www.google.com/recaptcha/api/siteverify' ); // make a POST request to the Google reCAPTCHA Server $request = wp_remote_post( $url, array( 'timeout' => 10, 'body' => array( 'secret' => $secre_key, 'response' => $response, 'remoteip' => $remoteip, ), ) ); // get the request response body $request_body = wp_remote_retrieve_body( $request ); if ( ! $request_body ) { return $verify; } $result = json_decode( $request_body, true ); if ( isset( $result['success'] ) && true == $result['success'] ) { if ( 'v3' === anr_get_option( 'captcha_version' ) ) { $score = isset( $result['score'] ) ? $result['score'] : 0; $action = isset( $result['action'] ) ? $result['action'] : ''; $verify = anr_get_option( 'score', '0.5' ) <= $score && 'advanced_nocaptcha_recaptcha' == $action; } else { $verify = true; } } $verify = apply_filters( 'anr_verify_captcha', $verify, $result, $response ); $last_verify = $verify; return $verify; } 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() { do_action( 'bp_anr_error_errors' ); $this->form_field(); } function bp_registration_verify() { if ( ! $this->verify() ) { buddypress()->signup->errors['anr_error'] = anr_get_option( 'error_message' ); } } function ms_form_field_verify( $result ) { if ( isset( $_POST['stage'] ) && 'validate-user-signup' === $_POST['stage'] && ! $this->verify() ) { $result['errors']->add( 'anr_error', anr_get_option( 'error_message' ) ); } return $result; } function ms_blog_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 ) { return $this->form_field_return() . 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 );