1212add_filter ( 'gform_notification ' , function ( $ notification , $ form , $ entry ) {
1313
1414 $ notification_name = 'Notification A ' ;
15- $ upload_field_id = 1 ;
15+ $ upload_field_ids = array ( 1 ) ;
1616
1717 return gw_add_attachments_by_field ( $ notification , $ form , $ entry , $ notification_name , $ upload_field_id );
1818}, 10 , 3 );
1919
2020add_filter ( 'gform_notification ' , function ( $ notification , $ form , $ entry ) {
2121
2222 $ notification_name = 'Notification B ' ;
23- $ upload_field_id = 2 ;
23+ $ upload_field_ids = array ( 2 , 3 ) ;
2424
25- return gw_add_attachments_by_field ( $ notification , $ form , $ entry , $ notification_name , $ upload_field_id );
25+ return gw_add_attachments_by_field ( $ notification , $ form , $ entry , $ notification_name , $ upload_field_ids );
2626}, 10 , 3 );
2727
28- function gw_add_attachments_by_field ( $ notification , $ form , $ entry , $ notification_name , $ upload_field_id ) {
28+ function gw_add_attachments_by_field ( $ notification , $ form , $ entry , $ notification_name , $ upload_field_ids ) {
2929
3030 if ( $ notification ['name ' ] !== $ notification_name ) {
3131 return $ notification ;
@@ -34,22 +34,24 @@ function gw_add_attachments_by_field( $notification, $form, $entry, $notificatio
3434 $ notification ['attachments ' ] = rgar ( $ notification , 'attachments ' , array () );
3535 $ upload_root = RGFormsModel::get_upload_root ();
3636
37- $ field = GFAPI ::get_field ( $ form , $ upload_field_id );
38- $ url = rgar ( $ entry , $ field ->id );
37+ foreach ( $ upload_field_ids as $ upload_field_id ) {
38+ $ field = GFAPI ::get_field ( $ form , $ upload_field_id );
39+ $ url = rgar ( $ entry , $ field ->id );
3940
40- if ( empty ( $ url ) ) {
41- return $ notification ;
42- }
41+ if ( empty ( $ url ) ) {
42+ continue ;
43+ }
4344
44- if ( $ field ->multipleFiles ) {
45- $ uploaded_files = json_decode ( stripslashes ( $ url ), true );
46- foreach ( $ uploaded_files as $ uploaded_file ) {
47- $ attachment = preg_replace ( '|^(.*?)/gravity_forms/| ' , $ upload_root , $ uploaded_file );
45+ if ( $ field ->multipleFiles ) {
46+ $ uploaded_files = json_decode ( stripslashes ( $ url ), true );
47+ foreach ( $ uploaded_files as $ uploaded_file ) {
48+ $ attachment = preg_replace ( '|^(.*?)/gravity_forms/| ' , $ upload_root , $ uploaded_file );
49+ $ notification ['attachments ' ][] = $ attachment ;
50+ }
51+ } else {
52+ $ attachment = preg_replace ( '|^(.*?)/gravity_forms/| ' , $ upload_root , $ url );
4853 $ notification ['attachments ' ][] = $ attachment ;
4954 }
50- } else {
51- $ attachment = preg_replace ( '|^(.*?)/gravity_forms/| ' , $ upload_root , $ url );
52- $ notification ['attachments ' ][] = $ attachment ;
5355 }
5456
5557 return $ notification ;
0 commit comments