Verifies a request by ensuring that it is not spammy.
Description
See also
Parameters
- $data
-
(array) (Required) Submission POST data.
- $form
-
(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form object.
- $submission
-
(awsmug\Torro_Forms\DB_Objects\Submissions\Submission|null) (Optional) Submission object, or null if a new submission.
Default value: null
Return
(bool|WP_Error) True if request is not spammy, false or error object otherwise.
Source
File: src/modules/protectors/recaptcha.php
public function verify_request( $data, $form, $submission = null ) { if ( empty( $_POST['g-recaptcha-response'] ) ) { return new WP_Error( 'missing_recaptcha', __( 'Missing reCAPTCHA response. Please check the reCAPTCHA checkbox to verify you are human.', 'torro-forms' ) ); } $verification = $this->verify_response_input( $_POST['g-recaptcha-response'] ); try { $verification = json_decode( $verification, true ); } catch ( Exception $e ) { return new WP_Error( 'cannot_process_recaptcha', __( 'An unknown error occurred processing the reCAPTCHA response.', 'torro-forms' ) ); } if ( ! is_array( $verification ) ) { return new WP_Error( 'cannot_process_recaptcha', __( 'An unknown error occurred processing the reCAPTCHA response.', 'torro-forms' ) ); } if ( empty( $verification['success'] ) ) { $error_code = ! empty( $verification['error-codes'] ) ? $verification['error-codes'][0] : ''; switch ( $error_code ) { case 'missing-input-secret': return new WP_Error( 'missing_recaptcha_secret', __( 'Internal error: The reCAPTCHA secret is missing. Please contact an administrator.', 'torro-forms' ) ); case 'invalid-input-secret': return new WP_Error( 'invalid_recaptcha_secret', __( 'Internal error: The reCAPTCHA secret is invalid or malformed. Please contact an administrator.', 'torro-forms' ) ); case 'missing-input-response': return new WP_Error( 'missing_recaptcha_response', __( 'Internal error: The reCAPTCHA response is missing. Please contact an administrator.', 'torro-forms' ) ); case 'invalid-input-response': return new WP_Error( 'invalid_recaptcha_response', __( 'Internal error: The reCAPTCHA response is invalid or malformed. Please contact an administrator.', 'torro-forms' ) ); default: return new WP_Error( 'unknown_recaptcha_error', __( 'Internal error: An unknown reCAPTCHA error occurred. Please contact an administrator.', 'torro-forms' ) ); } } return true; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |