ArrayRule.php
2 years ago
AuthenticationRule.php
2 years ago
BillingAddressCityRule.php
2 years ago
BillingAddressStateRule.php
2 years ago
BillingAddressZipRule.php
2 years ago
CurrencyRule.php
9 months ago
DonationTypeRule.php
2 years ago
GatewayRule.php
2 years ago
HoneyPotRule.php
1 year ago
Max.php
2 years ago
Min.php
2 years ago
PhoneIntlInputRule.php
2 years ago
Size.php
2 years ago
SubscriptionFrequencyRule.php
2 years ago
SubscriptionInstallmentsRule.php
2 years ago
SubscriptionPeriodRule.php
2 years ago
HoneyPotRule.php
46 lines
| 1 | <?php |
| 2 | namespace Give\DonationForms\Rules; |
| 3 | |
| 4 | use Closure; |
| 5 | use Give\DonationSpam\Exceptions\SpamDonationException; |
| 6 | use Give\Log\Log; |
| 7 | use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule; |
| 8 | |
| 9 | /** |
| 10 | * @since 3.16.2 |
| 11 | */ |
| 12 | class HoneyPotRule implements ValidationRule |
| 13 | { |
| 14 | |
| 15 | /** |
| 16 | * @since 3.16.2 |
| 17 | */ |
| 18 | public static function id(): string |
| 19 | { |
| 20 | return 'honeypot'; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @since 3.16.2 |
| 25 | */ |
| 26 | public static function fromString(string $options = null): ValidationRule |
| 27 | { |
| 28 | return new self(); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @since 3.16.2 |
| 33 | * @throws SpamDonationException |
| 34 | */ |
| 35 | public function __invoke($value, Closure $fail, string $key, array $values) |
| 36 | { |
| 37 | if (!empty($value)) { |
| 38 | Log::spam('Spam donation detected via Honeypot field.', [ |
| 39 | 'formId' => $values['formId'] ?? null, |
| 40 | ]); |
| 41 | |
| 42 | throw new SpamDonationException(__('Thank you for the submission!', 'give')); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 |