Linkcount::verify_request( array $data, awsmug\Torro_Forms\DB_Objects\Forms\Form $form, awsmug\Torro_Forms\DB_Objects\Submissions\Submission|null $submission = null )

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/linkcount.php

	public function verify_request( $data, $form, $submission = null ) {
		$trigger = $this->get_form_option( $form->id, 'trigger', 3 );

		foreach ( $data['values'] as $element_id => $fields ) {
			foreach ( $fields as $field_slug => $value ) {
				if ( empty( $value ) ) {
					continue;
				}

				if ( ! is_string( $value ) ) {
					continue;
				}

				preg_match_all('@https?://@' , $value, $matches );

				if ( count( $matches[0] ) < $trigger ) {
					continue;
				}

				return new WP_Error( 'too_many_links', __( 'Your submission contains too many links and was therefore considered spam.', 'torro-forms' ) );
			}
		}

		return true;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.