Skip Navigation

[Resolved] notification of author of a Parent post when a child post is created

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to add custom email notification using CRED forms

Solution:
You can use CRED filter hook: 'cred_notification_recipients' to setup custom email notification to specific email.

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/notification-of-author-of-a-parent-post-when-a-child-post-is-created/#post-364785

Relevant Documentation:
https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

This support ticket is created 8 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

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)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by peterv-6 8 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#363479

I want CRED to generate a notification email to the email address of the author of a parent CPT ("company -profile") when a CRED form creating a related child post is submitted.

I found a relevant similar query in Paid support - https://toolset.com/forums/topic/send-cred-notification-to-parent-custom-email-field/. That query related to sending an email to an address specified in a field in the parent CPT). I cannot figure out how to apply that answer to my situation. What I want is to notify the author of the parent post...

Could you please tell me how I can achieve this?

Cheers

Peter

#363596

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You should add generic field as shown on following link to your CRED form:
=> https://toolset.com/forums/topic/send-cred-notification-to-parent-custom-email-field/#post-306256

And then setup email notification:
=> https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

If you still need further help, please do not hesitate to get in touch with us.

#363674

Thanks Minesh, I had read the post you referred me to but my situation is different. I am wanting to pick up the email of the author rather than an email specified in a custom field of the parent CPT.
I am also a little less proficient at programming than the last person you helped so could you please be more specific about what I should do?

Kind regards
\Peter

#364229

Minesh

I hadn't heard from you so I gave it a go...

This is the code I came up with - inserted into my CRED form:

[cred_generic_field field="parent-notification-email" type="email" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-author field="user_email" id='$parent']"
}
[/cred_generic_field]

The result I got was
-the option to send a notification to email specified in a form field
-the Username of the Author of the parent post was displayed on the CRED form
But not email was received by the Post Author.

Could you please advise how to fix this code so that notifications are sent to the author of the Parent post AND neither the author's username or email address appears in the CRED from.

Cheers

Peter

#364243

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please send me link of the page where you've added CRED form.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#364647

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To be more precise for this issue:

hidden link
I go to this company profile and added my email address to email address field - correct?

Now, I've added info about problem solver form and now I'm on connection form:
=> hidden link

On above form I can see that we can select company profiles from dorp-down box, you mean to say now if I select "wptypes-test" drom company profiles drop-down and submit the form you want to send email to email address which I've added to "wptypes-test" profile?

Could you please confirm.

#364688

Minesh

Correct. to your first Q.

And correct to your second Question. What I want to achieve is that when you may a connection to WP types a notification is sent to you as author of the WP Types Company profile so that you know you have a pending request to moderate.

Thanks

Peter

#364722

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please test now.

Sorry, as it take a bit time to solve your issue but this issue not straight forward. I've changed your CRED form field as given under:

[cred_generic_field field="parent-notification-email" type="hidden" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":""
}
[/cred_generic_field]

Then I've catch the field assigned company profile email using following code that is added to your current theme's functions.php file.

add_action('cred_before_save_data', 'my_before_save_data_action',10,1);
function my_before_save_data_action($form_data)
{
    // if a specific form
    if ($form_data['id']==5493)
    {
		if(isset($_POST['_wpcf_belongs_company-profile_id']) and $_POST['_wpcf_belongs_company-profile_id']!=""){
			$parent_post_id = $_POST['_wpcf_belongs_company-profile_id'];
			$x = get_post_meta($parent_post_id,'wpcf-email-address',true);
			$_POST['parent-notification-email'] = $x;
			
		}
	}
}

To test this you should again change email address from "wptypes Test" company to your email then you will receive notification and I hope your issue is resolved here as well as your another issue that was with me that also resolved here.

#364742

Minesh

Thank you for your efforts. But I am afraid what you have done doesn't work as required... I need an email to go to the email address of the Author of the Company Profile Parent. On reflection I wasn't sufficiently clear with my last response I am sorry...I should have asked you to add your email address to your the WP Types User, rather than the email field in the Company profile... Which I have now done for you. Hopefully it is not too much work to make it work as I hope it can.

Cheers

Peter

#364785

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

ok :).

I've again added following code to your functions.php file.

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']) && 5493 == $_POST['_cred_cred_prefix_form_id']){
		
		if(isset($_POST['_wpcf_belongs_company-profile_id']) and $_POST['_wpcf_belongs_company-profile_id']!=""){
			$parent_post_id = $_POST['_wpcf_belongs_company-profile_id'];
			$parent_post_obj = get_post($parent_post_id);
			$my_user_id = $parent_post_obj->post_author;
			//$email = get_user_meta( $user_id, 'user_email', true ); 
			$author_obj = get_user_by('id', $my_user_id);
			$_POST['parent-notification-email'] = $author_obj->data->user_email;
			$recipients[] = array('to'=>'to', 'name'=>'', 'lastname'=>'', 'address'=>$_POST['parent-notification-email'] );
			
		}
	}
    return $recipients;
}

Hope this time your issue is resolved and this is exactly what you are looking for.

#364871

Awesome... just ran a quick test and it works... Thanks for all your help.

Cheers

Peter

#365338
Screen Shot 2016-02-08 at 4.57.37 PM.png

Minesh

I have just been transferring this to my live site and have noticed that although it all works... the CRED plugin does not appear to recoginse the notification as being set up correctly... the notification was set to the checkbox for " Send notification to a specific email address:" and works.. but doesn't look like it is set up properly and generates alerts within the CRED Edit page when it is saved... see the attached screenshot.

I wonder how hard it would be to adjust the solution you developed to appear to be completed properly such as by coming up as an option to select under the checkbox for "Send notification to an email specified in a form field:"?

Cheers

Peter

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.