PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.1
GiveWP – Donation Plugin and Fundraising Platform v4.15.1
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / src / DonationSpam / ServiceProvider.php

ServiceProvider.php in GiveWP – Donation Plugin and Fundraising Platform 4.15.1, at src/DonationSpam/ServiceProvider.php

66 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonationSpam;
4
5 use Give\DonationSpam\Akismet\Actions\ValidateDonation;
6 use Give\DonationSpam\Exceptions\SpamDonationException;
7 use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
8
9 /**
10 * @since 3.15.0
11 */
12 class ServiceProvider implements ServiceProviderInterface
13 {
14 /**
15 * @since 3.15.0
16 * @inheritDoc
17 */
18 public function register(): void
19 {
20 /**
21 * @since 3.15.1 Case filtered value as an array to enforce type.
22 * @since 3.15.0
23 */
24 give()->singleton(EmailAddressWhiteList::class, function () {
25 return new EmailAddressWhiteList(
26 (array)apply_filters('give_akismet_whitelist_emails', give_akismet_get_whitelisted_emails())
27 );
28 });
29 }
30
31 /**
32 * @since 3.22.0 updated Akismet validation to use new givewp_donation_form_fields_validated action
33 * @since 3.15.0
34 *
35 * @inheritDoc
36 *
37 * @throws SpamDonationException
38 */
39 public function boot(): void
40 {
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 );
64 }
65 }
66