Skip to content

Commit 6105dc6

Browse files
Clean up type errors during submission process
1 parent 6f646b3 commit 6105dc6

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

class-gf-email-filtering-addon.php

+14-12
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function init(): void {
7676
parent::init();
7777

7878
$this->settings = get_option('gravityformsaddon_' . $this->_slug . '_settings');
79-
$this->getDenylist();
79+
$this->denylist = $this->getDenylist();
8080
}
8181

8282
/**
@@ -215,8 +215,6 @@ public function gform_editor_js(): void
215215
*/
216216
public function gform_validation(array $validation_result): array
217217
{
218-
$denylist = $this->denylist;
219-
220218
// Collect form results.
221219
$form = $validation_result['form'];
222220

@@ -234,8 +232,10 @@ public function gform_validation(array $validation_result): array
234232

235233
// Collect banned domains from the form and clean up.
236234
if (! empty($field['email_filtering'])) {
237-
$denylist = $field['email_filtering'];
238-
}
235+
$denylist = $this->getDenylist($field['email_filtering']);
236+
} else {
237+
$denylist = $this->denylist;
238+
}
239239

240240
// Get the domain from user entered email.
241241
$email = $this->clean_string(rgpost("input_{$field['id']}"));
@@ -258,9 +258,10 @@ public function gform_validation(array $validation_result): array
258258
}
259259

260260
// Create array of banned domains.
261-
$denylist = explode(',', $denylist);
262-
$denylist = str_replace('*', '', $denylist);
263-
$denylist = array_map([$this, 'clean_string'], $denylist);
261+
$denylist = array_map(function ($item) {
262+
return str_replace('*', '', $item);
263+
}, $denylist);
264+
264265
$denylist = array_filter($denylist);
265266

266267
// No filtered emails, skip.
@@ -327,13 +328,14 @@ public function saveDenylist(Textarea $field, string $setting): string {
327328
}
328329

329330
/**
330-
* Set the denylist in an array.
331+
* Get the denylist in an array.
331332
*/
332-
public function getDenylist(): void {
333-
$denylist = $this->settings['default_email_denylist'] ?? '';
333+
public function getDenylist(string $denylist = ''): array {
334+
$denylist = $denylist ?: $this->settings['default_email_denylist'];
334335
$denylist = str_replace(',', "\r\n", $denylist);
335336
$denylist = explode("\r\n", $denylist);
336-
$this->denylist = array_map([$this, 'clean_string'], $denylist);
337+
338+
return array_map([$this, 'clean_string'], $denylist);
337339
}
338340

339341
/**

0 commit comments

Comments
 (0)