Akismet
1 year ago
Exceptions
1 year ago
EmailAddressWhiteList.php
1 year ago
ServiceProvider.php
1 year ago
ServiceProvider.php
54 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 | /** |
| 20 | * @since 3.15.1 Case filtered value as an array to enforce type. |
| 21 | * @since 3.15.0 |
| 22 | */ |
| 23 | give()->singleton(EmailAddressWhiteList::class, function () { |
| 24 | return new EmailAddressWhiteList( |
| 25 | (array) apply_filters( 'give_akismet_whitelist_emails', give_akismet_get_whitelisted_emails() ) |
| 26 | ); |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @since 3.15.0 |
| 32 | * @inheritDoc |
| 33 | */ |
| 34 | public function boot(): void |
| 35 | { |
| 36 | if($this->isAkismetEnabledAndConfigured()) { |
| 37 | Hooks::addAction('givewp_donate_form_data_validated', Akismet\Actions\ValidateDonation::class); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @since 3.15.0 |
| 43 | * @return bool |
| 44 | */ |
| 45 | public function isAkismetEnabledAndConfigured(): bool |
| 46 | { |
| 47 | return |
| 48 | give_check_akismet_key() |
| 49 | && give_is_setting_enabled( |
| 50 | give_get_option( 'akismet_spam_protection', 'enabled') |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 |