| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Give\DonationSpam; |
| 4 | 4 | |
| 5 | -use Give\DonationSpam\Akismet\Actions\ValidateDonation; | |
| 6 | -use Give\DonationSpam\Exceptions\SpamDonationException; | |
| 5 | +use Give\DonationSpam\Akismet\Actions\ValidateDonationOnFinalSubmission; | |
| 6 | +use Give\Helpers\Hooks; | |
| 7 | 7 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * @since 3.15.0 |
| @@ -28,38 +28,21 @@ | ||
| 28 | 28 | }); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | + * @since 4.16.0 register an invokable action that gates the Akismet check to the final submission | |
| 32 | 33 | * @since 3.22.0 updated Akismet validation to use new givewp_donation_form_fields_validated action |
| 33 | 34 | * @since 3.15.0 |
| 34 | 35 | * |
| 35 | 36 | * @inheritDoc |
| 36 | - * | |
| 37 | - * @throws SpamDonationException | |
| 38 | 37 | */ |
| 39 | 38 | public function boot(): void |
| 40 | 39 | { |
| 41 | - if ($this->isAkismetEnabledAndConfigured()) { | |
| 42 | - add_action('givewp_donation_form_fields_validated', static function (array $data) { | |
| 43 | - give(ValidateDonation::class)( | |
| 44 | - $data['email'] ?? '', | |
| 45 | - $data['comment'] ?? '', | |
| 46 | - $data['firstName'] ?? '', | |
| 47 | - $data['lastName'] ?? '' | |
| 48 | - ); | |
| 49 | - }); | |
| 50 | - } | |
| 51 | - } | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * @since 3.15.0 | |
| 55 | - * @return bool | |
| 56 | - */ | |
| 57 | - public function isAkismetEnabledAndConfigured(): bool | |
| 58 | - { | |
| 59 | - return | |
| 60 | - give_check_akismet_key() | |
| 61 | - && give_is_setting_enabled( | |
| 62 | - give_get_option('akismet_spam_protection', 'enabled') | |
| 63 | - ); | |
| 40 | + Hooks::addAction( | |
| 41 | + 'givewp_donation_form_fields_validated', | |
| 42 | + ValidateDonationOnFinalSubmission::class, | |
| 43 | + '__invoke', | |
| 44 | + 10, | |
| 45 | + 2 | |
| 46 | + ); | |
| 64 | 47 | } |
| 65 | 48 | } |