Tell us what you are trying to do? I am using forminator pro that is a plugin from WPMUDEV and it sends email from the form to an admin email id but they are trying to help me send it to a custom field created in Toolset.. here's a link to support ticket.. hidden link .. and here's the page that I am trying to use it on.. hidden link
are we on the right track?
Is there any documentation that you are following?
Hello and thank you for contacting the Toolset support.
I assume you are talking about the code on this reply hidden link right?
I see possible errors:
- The value returned from types_render_field may be formatted, you may need to use the argument "output=raw" to get the raw value, check the documentation here https://toolset.com/documentation/customizing-sites-using-php/functions/
- The value returned is not an email and must not get added to "$recipients", you may need to use get_userdata($user_id)->user_email, check the documentation of this function here https://developer.wordpress.org/reference/functions/get_userdata/
- The value returned has probably multiple values separated by (,), you may need to explode it.
Have forwarded the code to WPMU team and they confirmed it was all good..
But when I tested with multiple email ids it didn't seem to work.. I made the email custom field as 'Allow to add multiple instances' .. that's fine.. right? (screenshot attached)
Please do check the ticket at this URL to see if you can help the WPMU team
Hello Alim and thank you for your feedback. As the field stores emails instead of user IDs, we can omit the use of get_userdata/. I have also a mistake in the get_post_meta, it should take the post_id as the first argument and false as 3rd argument to return an array. We can use the $post for post_id, but I am not sure, maybe the WPMU team can help us get the ID of the created post.
The sample code will be:
add_filter( 'forminator_get_admin_email_recipients', function( $recipients ) {
global $post;
// get an array of emails from the custom field
$custom_emails = get_post_meta( $post->ID, 'wpcf-notification-email', false ); // <= change $post->ID with the ID of the created post.
if ( count( $custom_emails ) > 0 ) {
unset( $recipients );
foreach ($custom_emails as $custom_email) {
$recipients[] = $custom_email;
}
}
return $recipients;
} );