Skip to content

Commit 836af8d

Browse files
authored
gw-remove-empty-emails-from-notifications.php: Added new snippet.
1 parent f87e715 commit 836af8d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Gravity Wiz // Gravity Forms // Remove Empty Emails from Notification Email Lists
4+
* https://gravitywiz.com/
5+
*
6+
* If you're passing merge tags as an email list (e.g. {admin_email},{Email:1},{Alternate Email:3}) and one of those
7+
* emails is empty, Gravity Forms won't send the email to any of the emails in the list.
8+
*
9+
* This snippet intercepts notifications and processes the `to`, `cc` and `bcc` properties, removing any empty emails.
10+
*/
11+
add_filter( 'gform_notification', function( $notification, $form, $entry ) {
12+
foreach ( array( 'to', 'cc', 'bcc' ) as $key ) {
13+
if ( ! empty( $notification[ $key ] ) ) {
14+
$notification[ $key ] = GFCommon::replace_variables( $notification[ $key ], $form, $entry, false, false, false, 'text' );
15+
$emails = array_filter( explode( ',', $notification[ $key ] ) );
16+
$notification[ $key ] = implode( ',', $emails );
17+
}
18+
}
19+
return $notification;
20+
}, 10, 3 );

0 commit comments

Comments
 (0)