Accueil › Toolset Professional Support › [Résolu] How to send auto notifications when deleting a post via CRED form
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.
Marqué : Toolset Forms
This topic contains 30 réponses, has 3 voix.
Last updated by jamesH-3 Il y a 7 années et 3 mois.
Assigned support staff: Shane.
Hi
I am using a CRED form delete content link (cred_delete_post_link) and I would like to be able send an auto notification to when this link is used and preferably with the deleted content included in the email.
Can you please direct me in the right direction?
I could not find any information on this on the Forum.
Thanks
Hi James,
Since this is not a function that is in our CRED form at the moment.
This can however be achieved by using a very basic custom hook.
Please see the function below.
add_action('trash_post','my_trash_post_function',1,1); function my_trash_post_function($post_id){ $deleted_post = get_post($post_id); $content = $deleted_post->post_content; $headers = 'From: My Name <myname@example.com>' . "\r\n"; wp_mail('test@gmail.com', 'A new Post has be Deleted', $content, $headers); }
Add this to your theme's function.php file and it will send a mail anytime a post is deleted.
Hi Shane
I am really sorry but I am not very good, in fact very bad, with coding.
How should I amend this code:
1- for the subject line of the email to say something like "Your Deleted Coupon - %%POST_TITLE%% - Coupon Number: %%POST_ID%%"
2- for the content of the email to
a - show only some of the CRED fields, instead of the full content, such as "[cred_field field="coupon-condition-1" post="coupon" value="" urlparam=""]"
b- show some additional text with multiple paragraphs, such as "Dear %%USER_LOGIN_NAME%%", "Paragraph1" and "Paragraph 2"
c- to include an image, e.g. "companylogo.png"
4- for the email to be sent to the email address of the Author and cc or bcc'ed to the email address of the admin (Please note this link will be used by individual users and send to email address will change depending on the email address of the logged in user/Author)
5- for this notification to be sent only when a specific custom post was deleted and not every time any post was deleted, e.g only "$coupon" posts of the logged in user/Author
Thanks
Hi James,
What I can provide is a basic email notification hook.
Which is this
add_action('trash_post','my_trash_post_function',1,1); function my_trash_post_function($post_id){ $deleted_post = get_post($post_id); $id = $deleted_post->id; $title = $deleted_post->post_title; $content = $deleted_post->post_content; if ($post->post_type == 'my-custom-post-type') { $headers = 'From: My Name <myname@example.com>' . "\r\n"; wp_mail('user@gmail.com', 'Your Deleted Coupon - {$title} - Coupon Number: {$id}', $content, $headers); } }
For a more comprehensive code based on your requirements I think it is best that you contact our custom development team.
You can contact them by going here : custom.wp-types.com
They should be able to give a more complete and better solution that I can.
Hi Shane
I have tried the code you provided but it does not seem to work. It cause delays in deleting the post and does not trigger any emails.
Thanks
add_action('trash_post','my_trash_post_function',1,1);
function my_trash_post_function($post_id){
$deleted_post = get_post($post_id);
$id = $deleted_post->id;
$title = $deleted_post->post_title;
$content = $deleted_post->post_content;
if ($post->post_type == 'coupon') {
$headers = 'From: My Name <xyz@gmail.com>' . "\r\n";
wp_mail('xyz@outlook.com', 'Your Deleted Coupon - {$title} - Coupon Number: {$id}', $content, $headers);
}
}
Hi James,
You in order for the email notifications to be sent you need to replace the emails in the code with the appropriate ones.
Right now I see that you have "xyz@gmail.com" and "xyz@outlook.com". I am not sure if these are legitimate emails or not but the issue could be with that.
In the code I used I used the correct email adresses.
Hi James,
Does your wordpress website send out email notifications normally, such as when a post is created or edited?
I would like to check on this but I need to have access to your website.
I will be enabling the private fields so you can supply me with the necessary information.
Hi James,
This seems to be an issue with your hosting provider.
What I need you to do is to check with them to ensure that the correct module for emailing is enabled on the server.
The code for sending the email works for me in a test environment and should work in your production environment.
Please check with them to see if this module is enabled.
Please let me know and we can move from there.
Hi Shane
I have just been in touch with the support team of the hosting provider.
They told me that you needed to be more specific about what module you wanted them to check.
They have also told me that you could check it yourself from the link below:
hidden link
Thanks
Hi James,
Tell them to check the sendmail_path module.
Also could you ask them to verify your the mailing on your website.
Ensure that you can send emails using your wordpress website.
Hi Shane I ll ask them today but can you please clarify what you mean by 'verify your the mailing on your website'? There may have been a typo there? Thanks
Hi James,
Sorry about that.
What I meant is that you should allow them to test your website to see if it can send out emails.
if it can't then the code I provided earlier won't work.
I need to check if emails can be sent 🙂
Please let me know once you have gotten an answer from your hosting company.
I dont know if it woukd help but I can confirm that when my regisration form (made with Gravity Forms) I do receive an auto email from wordpress@turkeytravelhub.com. does that mean emails can be sent?
Hi James,
Thanks for confirming this.
What I can do is to log into your website with the credentials that you had provided to see why this is not work.
Could you check your spam/junk mail to see if there is any mail that could've been generated from your site through the script I sent.
Thanks