Home › Toolset Professional Support › [Resolved] Embedded CRED in CPT post allowing user to send message to post's contact person
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Related documentation:
This topic contains 22 replies, has 2 voices.
Last updated by Minesh 7 years, 7 months ago.
Assisted by: Minesh.
You mean to which user account email - currently logged in user email? Could you please tell me from where I can access email when you say your account email?
Yes.
Now, if I am connected, the notification is sent to the receivers' email, the senders' email AND the default email of the logged in user (me).
So if I was connected and sending the email for another person (name / email), I would also receive the notification even if my "data" is not added to the fields.
So you can add another notification - see code below:
add_filter('cred_notification_recipients', 'my_cred_notification_recipients_func', 10, 4); function my_cred_notification_recipients_func($recipients){ if (!is_array($recipients)) { $recipients=array(); } if (isset($_POST['_cred_cred_prefix_form_id']) && 99999== $_POST['_cred_cred_prefix_form_id']){ $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$_POST['post_auth_email'] ); // this is added for field - "wpcf-form-contact-courriel" - you can change the variable if required $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$_POST['wpcf-form-contact-courriel'] ); // Notification for loggedin user global $current_user; $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$current_user->user_email ); } } return $recipients; }
I hope now this is fully resolved 🙂
I hope this is resolved now.
Hi Minesh, hope you had a great weekend 🙂
I did not express myself righ. Actually, if I am connected, the notification is sent to 1) the receiver 2) the sender 3) the logged in user's email
What I would like is that in any case (logged in or not), the notification is sent only to 1) the receiver 2) the sender.
🙂
Yes - you just need to wrap the code to check if user login or not.
add_filter('cred_notification_recipients', 'my_cred_notification_recipients_func', 10, 4); function my_cred_notification_recipients_func($recipients){ if (!is_array($recipients)) { $recipients=array(); } if (isset($_POST['_cred_cred_prefix_form_id']) && 99999== $_POST['_cred_cred_prefix_form_id']){ $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$_POST['post_auth_email'] ); // this is added for field - "wpcf-form-contact-courriel" - you can change the variable if required $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$_POST['wpcf-form-contact-courriel'] ); // check if user login if(is_user_logged_in()) { // Notification for loggedin user global $current_user; $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$current_user->user_email ); } } } return $recipients; }
Now - if user login then the notification will be sent to 3 users otherwise 2 users as you required. Dont forget to change 999999 with your CRED form id.
Hi Minesh,
Actually, my problem is that the notification is sent to 3 users if I'm logged in. I want the notification to be sent to only 2 users, at any time 🙂
Then you should remove the code I've added - so check below code:
add_filter('cred_notification_recipients', 'my_cred_notification_recipients_func', 10, 4); function my_cred_notification_recipients_func($recipients){ if (!is_array($recipients)) { $recipients=array(); } if (isset($_POST['_cred_cred_prefix_form_id']) && 99999== $_POST['_cred_cred_prefix_form_id']){ $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$_POST['post_auth_email'] ); // this is added for field - "wpcf-form-contact-courriel" - you can change the variable if required $recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$_POST['wpcf-form-contact-courriel'] ); } return $recipients; }
As you can see above the notification set for only two users. do you have any additional notification setup in your CRED form?