PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
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 2.3.2 2.30.0 2.31.0 All 254 releases
give / src / Email / GlobalSettingValidator.php

GlobalSettingValidator.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Email/GlobalSettingValidator.php

59 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Email;
4
5 use Give_Admin_Settings;
6
7 /**
8 * @since 2.17.1
9 */
10 class GlobalSettingValidator
11 {
12 /**
13 * @since 2.17.1
14 */
15 public function __invoke()
16 {
17 // Bailout.
18 if (
19 ! Give_Admin_Settings::is_saving_settings() ||
20 'emails' !== give_get_current_setting_tab() ||
21 ! isset($_GET['section'])
22 ) {
23 return;
24 }
25
26 add_filter($this->getFilterHookName(), [$this, 'validateSetting']);
27 }
28
29 /**
30 * @since 2.17.1
31 * @since 2.17.2 Only filter value as unique array if set. Some settings do not need to be set, ie donation-receipt_recipient.
32 */
33 public function validateSetting($value)
34 {
35 if( ! empty( $value ) ) {
36 // Same unique email address for email recipients.
37 $recipientEmails = array_unique(array_filter($value));
38
39 // Set default email recipient to admin email.
40 $value = $recipientEmails ?: [get_bloginfo('admin_email')];
41 }
42 return $value;
43 }
44
45 /**
46 * @since 2.17.1
47 * Note: Filter hook defined in Give_Admin_Settings::save_fields function::1163
48 *
49 * @return string
50 */
51 private function getFilterHookName()
52 {
53 $email_type = give_get_current_setting_section();
54 $settingName = "{$email_type}_recipient";
55
56 return "give_admin_settings_sanitize_option_$settingName";
57 }
58 }
59