Hello @mitys ,
Please try the following code snippet as a MU plugin (https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins )
<?php
add_filter( 'forminator_form_get_admin_email_recipients', 'wpmudev_csv_email_recipients', 10, 5 );
function wpmudev_csv_email_recipients( $email, $notification, $prepared_data, $module, $entry ) {
if ( $module->id != 4620 ) {
return $email;
}
$email = array();
$recipients = array();
$i = 0;
$nf_routing = array();
$file = fopen( 'https://docs.google.com/spreadsheets/d/1ov51zLpOiPqjpEV1D_GOqSNI6WK7x-_d/export?format=csv&id=1ov51zLpOiPqjpEV1D_GOqSNI6WK7x-_d', 'r' );
while ( ( $line = fgetcsv( $file, 1000, "," ) ) !== false ) {
if ( $i > 0 ) {
$nf_routing[] = array( 'email' => $line[0], 'element_id' => $line[1], 'rule' => $line[2], 'value' => $line[3] );
}
$i++;
}
if ( ! empty( $nf_routing ) ) {
foreach ( $nf_routing as $routing ) {
if ( Forminator_Field::is_condition_matched( $routing ) ) {
if ( false !== strpos( $routing['email'], ',' ) ) {
$recipients = array_merge( array_map( 'trim', explode( ',', $routing['email'] ) ), $recipients );
} else {
$recipients[] = trim( $routing['email'] );
}
}
}
}
if ( ! empty( $recipients ) ) {
foreach ( $recipients as $key => $recipient ) {
$mail_sender = new Forminator_CForm_Front_Mail();
$recipient = $mail_sender->get_recipient( $recipient, $module, $entry, array() );
if ( false !== strpos( $recipient, ',' ) ) {
$emails = array_map( 'trim', explode( ',', $recipient ) );
if ( ! empty( $emails ) ) {
foreach ( $emails as $email_key => $email_recipient ) {
if ( is_email( $email_recipient ) ) {
$email[] = $email_recipient;
}
}
}
} else {
if ( is_email( $recipient ) ) {
$email[] = $recipient;
}
}
}
}
return $email;
}
In the code 4620 should be changed to your form’s ID. The code will read the routing conditions from the google doc(shared in this task) and set the recipient if the rule matches.
kind regards,
Kasia