Accueil › Toolset Professional Support › [Résolu] Email notification to parents post authors on many to many relationship
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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
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)
Marqué : Content-submission forms, CRED API, Toolset Forms, Views plugin
Documentation connexe :
Ce sujet contient 30 réponses, a 2 voix.
Dernière mise à jour par Minesh Il y a 4 années et 5 mois.
Assisté par: Minesh.
Hi, I've made a test on a new server.
This is the recap.
Posts type:
Relationship between post type 1 and post type 2: many to many (post type 1 is parent, post type 2 is child):
Relationship between post type 2 and post type 3: one to many (post type 2 is parent, post type 3 is child).
Now I have a post form that creates a new post (a new post of the post type 3) where I have a field for selecting the parent (post type 2) for the post being created.
I want to send the notification email to all the authors of the parents (post type 1) of the parent (post type 2) when a new post is created.
I'll trigger the function only when the notification's name is 'Notifica ricambisti'
add_filter('cred_notification_recipients', 'ts_cred_notification_recipient_19', 10, 4); function ts_cred_notification_recipient_19($recipients, $notification, $form_id, $post_id){ $which_notifications = array( 'Notifica ricambisti' ); // which notifications this applies to // Check notification name matches target notification if ( isset( $notification['name'] ) && in_array( $notification['name'], $which_notifications ) ) {
I'll get the ID of the parent post (case automobilistiche) from the relationship between post type 2 and post type 3
$case_automobilistiche_id = toolset_get_related_post($post_id, 'marca-contatto-generico-ricambio' );
I'll extract the post objects from the relationship between post type 1 and post type 2
$ricambisti = toolset_get_related_posts( $case_automobilistiche_id, 'ricambista-casa-automobilistica', 'child', 100000, 0, array(), 'post_object', 'parent' );
And extract the authors email of the post type 1 related to the post type 2 which is related to the post type 3
// Start with an empty list of email addresses and empty list of post author IDs $emails = array(); $authors = array(); // Loop over each parent post and get the post authors foreach ($ricambisti as $ricambista) { $authors[] = get_post_field ('post_author', $ricambista); } // Ignore duplicates $authors = array_unique( $authors ); // Get email address of authors and create comma separated list foreach ($authors as $author) { $emails[] = get_the_author_meta( "user_email", $author ); } //error_log(print_r($emails, true)); // Add recipients by BCC if (!empty($emails)) { $recipients[] = array( 'to' => 'bcc', 'address' => join(",",$emails), 'name' => '', 'lastname' => '' ); } //error_log("recipients---".print_r($recipients, true)); } return $recipients; }
If you want I can share with you FTP and admin credentials, so you can check.
The main thing I would like to know is - do you see the hook "cred_notification_recipients" is triggered when you submit the form?
No, it isn't triggered.
But only with this function..
I just tested with my test site and added the following hook to custom code section:
function tssupp_custom_form_recipients1( $recipients, $notification, $form_id, $post_id ){ error_log("MInesh: cred_notification_recipients: this is triggered successfully at time " . date("d-m-Y H:i:s") ); $recipients[] = array( 'to' => 'to', 'address' => "xxx@gmail.com", 'name' => '', 'lastname' => '' ); return $recipients; } add_filter( 'cred_notification_recipients', 'tssupp_custom_form_recipients1', 10, 4);
And I can confirm that when I submit the form I can see the line added to error log:
"MInesh: cred_notification_recipients: this is triggered successfully at time " . date("d-m-Y H:i:s")
And also the notification send to xxx email.
If you would like to check I can share the access details to my test site.
Then, I've added the same code I tried with my test site to your site's custom code section and also activated the debug but when I submit the form I do not see any error log entry added to error log file nor the email sent.
This certainly looks like issue from server. Do you have any other test site hosted on another server where I can run a test?
Ok, could you please share the access details to your test site.
Thank you.
Sure.
URL: lien caché
user: demo
pwd: Admin@999
The form is available here:
=> lien caché
You can see the notification settings and edit the form here:
=> lien caché
You can find the hook added with the following link and you can change the email to your desired email:
=> lien caché
Let me know if you need anything.
Is there a way to have toolset in English and not translated in Italian?
Do you mean in admin you want to display Toolset menu in English - if yes, what if you try to change your site language from Settings => General => Site Language and chose your site language.
Hi, I've tested on a new server.
The email is sent and the error is printed on the error_log file.
At this point, I think I'm not correctly triggering the function to send the email notification to the authors of the parent post.
Great - so finally we have a place where we can add the correct code.
Can you please send me access details of your server where the notification works. As well as share the page where you added the form.
I have set the next reply to private which means only you and I have access to it.
When I edit the page where you added the form: lien caché
I can see the two post relationship available - to which post relationship post author you want to send the email, Can you please clarify and once you share this information I will adjust to notification hook code accordingly.
=> lien caché
Also, I see you added two code snippet for notification hook, which I should use and adjust the code?
I'd like to send the email to the author of the post type "Ricambisti".
The hook is this one: notifica-ai-ricambisti
It works as expected I can see now.
I've added the new user test-notification-user1 and test-notification-user2.
Then, I've changed the post author of the following related posts:
=> lien caché - author: test-notification-user1
=> lien caché - author: test-notification-user2
And then submit the form:
=> lien caché
I received the notification to both post author's email for the author "test-notification-user1" and "test-notification-user2".
Can you please confirm now it works as your end, you should check spam folder as well for email. You can change the post author for the post and test it.
I've also set the my email address to section "Send notification to a specific email address: " to the notification "Notifica ricambisti", you should also change the email there as well.
=> lien caché
Please remove the users I've added test-notification-user1 and test-notification-user2 once the testing is complete. 🙂