' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } } else { $user = new WP_Error( esc_html( $aioc_error_name ), '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } return $user; } /** * Validate register form. * * @since 1.0.0 * * @param WP_Error $errors A WP_Error object. * @return WP_Error Modified error object. */ function aioc_validate_register_form( $errors ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { $errors = new WP_Error( esc_html( $aioc_error_name ), '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } } else { $errors = new WP_Error( esc_html( $aioc_error_name ), '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } return $errors; } /** * Validate lost password form. * * @since 1.0.0 * * @param WP_Error $errors A WP_Error object. */ function aioc_validate_lost_password_form( $errors ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { $errors->add( esc_html( $aioc_error_name ), '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } } else { $errors->add( esc_html( $aioc_error_name ), '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } } /** * Validate comment form. * * @since 1.0.0 * * @param array $commentdata Comment data. * @return array Modified comment data. */ function aioc_validate_comment_form( $commentdata ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; $comment_validation = false; if ( 'comment' === $commentdata['comment_type'] && 1 === absint( aioc_option( 'aioc_enable_comment_form' ) ) ) { $comment_validation = true; } elseif ( 'review' === $commentdata['comment_type'] && 1 === absint( aioc_option( 'aioc_enable_woo_review' ) ) ) { $comment_validation = true; } // No need to check for loggedin user. if ( absint( $commentdata['user_ID'] ) > 0 || false === $comment_validation ) { return $commentdata; } if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { wp_die( '
' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) . '
', esc_html( $aioc_error_name ), array( 'response' => 403, 'back_link' => 1, ) ); } } else { wp_die( '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) . '
', esc_html( $aioc_error_name ), array( 'response' => 403, 'back_link' => 1, ) ); } return $commentdata; } /** * Validate woo login form. * * @since 1.1.0 * * @param WP_Error|mixed $validation_error Validation error. * * @return WP_Error|mixed */ function aioc_validate_woo_login_form( $validation_error ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_REQUEST['woocommerce-login-nonce'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $nonce_value = sanitize_text_field( wp_unslash( $_REQUEST['woocommerce-login-nonce'] ) ); if ( wp_verify_nonce( $nonce_value, 'woocommerce-login' ) ) { if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { $validation_error = new WP_Error( esc_html( $aioc_error_name ), esc_html( $aioc_error_message ) ); } } else { $validation_error = new WP_Error( esc_html( $aioc_error_name ), esc_html( $aioc_error_message ) ); } return $validation_error; } } } /** * Validate WooCommerce register form. * * @since 1.1.0 * * @param string $username Username. * @param string $email Email. * @param WP_Error $errors A WP_Error object. */ function aioc_validate_woo_register_form( $username, $email, $errors ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { $errors->add( esc_html( $aioc_error_name ), esc_html( $aioc_error_message ) ); } } else { $errors->add( esc_html( $aioc_error_name ), esc_html( $aioc_error_message ) ); } } /** * Validate WooCommerce checkout block form. * * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. Usually a WP_REST_Response or WP_Error. * @param array $handler Route handler used for the request. * @param WP_REST_Request $request Request used to generate the response. * * @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed */ function aioc_validate_woo_checkout_block( $response, array $handler, WP_REST_Request $request ) { if ( '/wc/store/v1/checkout' !== $request->get_route() ) { return $response; } $validation_type = aioc_get_captcha_validation_type(); $aioc_key = array_key_exists( 'response_key', $validation_type ) ? $validation_type['response_key'] : ''; $aioc_error_name = array_key_exists( 'error_name', $validation_type ) ? $validation_type['error_name'] : ''; $aioc_error_message = aioc_option( 'aioc_validation_error_message' ); $captcha_type = aioc_option( 'aioc_captcha_type' ); if ( 'slide-captcha' === $captcha_type ) { $aioc_response_key_time = 'aioc_slide_captcha_time'; $aioc_response_time_value = $request->get_param( $aioc_response_key_time ); $_REQUEST[ $aioc_response_key_time ] = $aioc_response_time_value; } $aioc_response_value = $request->get_param( $aioc_key ); if ( 'math-captcha' === $captcha_type ) { $_REQUEST[ $aioc_key ] = array( $aioc_response_value['name'] => $aioc_response_value['value'] ); } else { $_REQUEST[ $aioc_key ] = $aioc_response_value; } $res = array_key_exists( 'response_cb', $validation_type ) && is_callable( $validation_type['response_cb'] ) ? call_user_func( $validation_type['response_cb'] ) : ''; if ( true !== $res ) { return new WP_Error( esc_html( $aioc_error_name ), esc_html( $aioc_error_message ) ); } } /** * Validate WooCommerce checkout form. * * @since 1.1.0 */ function aioc_validate_woo_checkout_form() { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { wc_add_notice( $aioc_error_message, 'error' ); } } else { wc_add_notice( $aioc_error_message, 'error' ); } } /** * Validate woo lost password form. * * @since 1.1.0 * * @param WP_Error $errors A WP_Error object. */ function aioc_validate_woo_lost_password_form( $errors ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $post_value = isset( $_REQUEST['wc_reset_password'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wc_reset_password'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ( ! isset( $_REQUEST['wc_reset_password'] ) ) || ( 'true' !== $post_value ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } if ( true !== $aioc_response ) { $errors->add( esc_html( $aioc_error_name ), '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } } else { $errors->add( esc_html( $aioc_error_name ), '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) ); } } /** * Validate WPForms form. * * @since 1.1.0 * * @param array $entry Form submission data. * @param array $form_data Form data. */ function aioc_validate_enable_wpforms( $entry, $form_data ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { wpforms()->process->errors[ $form_data['id'] ]['header'] = esc_html( $aioc_error_message ); } } else { wpforms()->process->errors[ $form_data['id'] ]['header'] = esc_html( $aioc_error_message ); } } /** * Validate CF7 form. * * @since 1.1.0 * * @param array $result Form result. * @return object $result */ function aioc_validate_enable_cf7( $result ) { $form_tags = wpcf7_scan_form_tags( array( 'type' => 'aioc_recaptcha' ) ); if ( empty( $form_tags ) ) { return $result; } global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { $result->invalidate( array( 'type' => 'captcha', 'name' => 'aioc_recaptcha', ), esc_html( $aioc_error_message ) ); } } else { $result->invalidate( array( 'type' => 'captcha', 'name' => 'aioc_recaptcha', ), esc_html( $aioc_error_message ) ); } return $result; } /** * Validate Buddypress register form. * * @since 1.1.0 */ function aioc_validate_enable_bp_register() { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { wp_die( '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) . '
', esc_html( $aioc_error_name ), array( 'response' => 403, 'back_link' => 1, ) ); } } else { wp_die( '' . esc_html__( 'ERROR:', 'all-in-one-captcha' ) . ' ' . esc_html( $aioc_error_message ) . '
', esc_html( $aioc_error_name ), array( 'response' => 403, 'back_link' => 1, ) ); } } /** * Validate edd login form. * * @since 1.1.0 */ function aioc_validate_edd_login_form() { global $aioc_response; if ( true !== $aioc_response ) { remove_action( 'edd_user_login', 'edd_process_login_form' ); add_filter( 'edd_errors', 'aioc_validate_edd_login_error' ); } } /** * Validate edd login error. * * @since 1.1.0 * * @param array|mixed $errors Validation error. * * @return array|mixed */ function aioc_validate_edd_login_error( $errors ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; $post_value = array_key_exists( 'edd_action', $_REQUEST ) ? sanitize_text_field( wp_unslash( $_REQUEST['edd_action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( 'user_login' !== $post_value ) { return $errors; } if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { $errors = $errors ? (array) $errors : array(); $errors[ $aioc_error_name ] = $aioc_error_message; } } else { $errors = $errors ? (array) $errors : array(); $errors[ $aioc_error_name ] = $aioc_error_message; } return $errors; } /** * Validate EDD register form. * * @since 1.1.0 */ function aioc_validate_enable_edd_register() { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { edd_set_error( $aioc_error_name, $aioc_error_message ); } } else { edd_set_error( $aioc_error_name, $aioc_error_message ); } } /** * Validate edd lost password form. * * @since 1.1.0 * * @param WP_Error $errors A WP_Error object. */ function aioc_validate_edd_lost_password_form( $errors ) { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; $post_value = isset( $_REQUEST['edd_action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edd_action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( 'user_lost_password' !== $post_value ) { return $errors; } if ( true === $aioc_response ) { return $errors; } remove_action( 'edd_user_lost_password', 'edd_handle_lost_password_request' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { if ( true !== $aioc_response ) { $errors = $errors ? (array) $errors : array(); $errors[ $aioc_error_name ] = $aioc_error_message; } } else { $errors = $errors ? (array) $errors : array(); $errors[ $aioc_error_name ] = $aioc_error_message; } return $errors; } /** * Validate EDD checkout. * * @since 1.1.0 */ function aioc_validate_enable_edd_checkout() { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! array_key_exists( 'payment-mode', $_REQUEST ) && true !== $aioc_response ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended edd_set_error( $aioc_error_name, $aioc_error_message ); } } else { edd_set_error( $aioc_error_name, $aioc_error_message ); } } /** * Validate bbPress new topic. * * @since 1.1.0 */ function aioc_validate_enable_bbpress_topic() { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { bbp_add_error( $aioc_error_name, $aioc_error_message ); return false; } } else { bbp_add_error( $aioc_error_name, $aioc_error_message ); return false; } return true; } /** * Validate bbPress reply. * * @since 1.1.0 */ function aioc_validate_enable_bbpress_reply() { global $aioc_key, $aioc_response, $aioc_error_name, $aioc_error_message; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_REQUEST[ $aioc_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( true !== $aioc_response ) { bbp_add_error( $aioc_error_name, $aioc_error_message ); return false; } } else { bbp_add_error( $aioc_error_name, $aioc_error_message ); return false; } return true; }