Akismet
1 year ago
Exceptions
1 year ago
EmailAddressWhiteList.php
1 year ago
ServiceProvider.php
1 year ago
ServiceProvider.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationSpam; |
| 4 | |
| 5 | use Give\Helpers\Hooks; |
| 6 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 7 | |
| 8 | /** |
| 9 | * @since 3.15.0 |
| 10 | */ |
| 11 | class ServiceProvider implements ServiceProviderInterface |
| 12 | { |
| 13 | /** |
| 14 | * @since 3.15.0 |
| 15 | * @inheritDoc |
| 16 | */ |
| 17 | public function register(): void |
| 18 | { |
| 19 | give()->singleton(EmailAddressWhiteList::class, function () { |
| 20 | return new EmailAddressWhiteList( |
| 21 | apply_filters( 'give_akismet_whitelist_emails', give_akismet_get_whitelisted_emails() ) |
| 22 | ); |
| 23 | }); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @since 3.15.0 |
| 28 | * @inheritDoc |
| 29 | */ |
| 30 | public function boot(): void |
| 31 | { |
| 32 | if($this->isAkismetEnabledAndConfigured()) { |
| 33 | Hooks::addAction('givewp_donate_form_data_validated', Akismet\Actions\ValidateDonation::class); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @since 3.15.0 |
| 39 | * @return bool |
| 40 | */ |
| 41 | public function isAkismetEnabledAndConfigured(): bool |
| 42 | { |
| 43 | return |
| 44 | give_check_akismet_key() |
| 45 | && give_is_setting_enabled( |
| 46 | give_get_option( 'akismet_spam_protection', 'enabled') |
| 47 | ); |
| 48 | } |
| 49 | } |
| 50 |