Send mail when private page is updated
-
Is it possible to send an e-mail to the user every time their private page is updated?
-
Hello @dogmadesign,
This can be done with some custom code:
//Send an email to the user when his private page was updated function cpc_send_email_on_page_update($post_id) { $author_id = get_post_field('post_author', $post_id); $user = get_userdata($author_id); $to = $user->user_email; $site_name = get_bloginfo('name'); $subject = '['.$site_name.'] Private page updated !'; $message = 'Your private page was just updated !'; wp_mail($to, $subject, $message); } add_action( 'save_post_private-page', 'cpc_send_email_on_page_update' );
Either add this inside the
functions.php
file from your theme or follow the instructions found at the top of this page.If you changed the default slug of the private page, you need to change it on this line as well:
add_action( 'save_post_private-page', 'cpc_send_email_on_page_update' );
Replace
private-page
with it.Let me know if this works.
Regards.
- This reply was modified 7 years, 1 month ago by Georgian Cocora.
Unfortunately it is not working. I made a plugin and activated it, but when I change and save a private page, no e-mail is sent.
Click here for the screenshot.
This is in my plugin file:
<?php /** * Plugin Name: Mail bij update private pages * Plugin URI: https://www.dogmadesign.nl * Description: Er wordt een e-mail verzonden als de private page van een van uw gebruikers wordt bijgewerkt. * Version: 1.0 * Author: DogMa Design * Author URI: https://www.dogmadesign.nl * License: GPL2 */ /* Copyright YEAR PLUGIN_AUTHOR_NAME (email : PLUGIN AUTHOR EMAIL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // Start writing code after this line! //Send an email to the user when his private page was updated function cpc_send_email_on_page_update($post_id) { $author_id = get_post_field('post_author', $post_id); $user = get_userdata($author_id); $to = $user->user_email; $site_name = get_bloginfo('name'); $subject = '['.$site_name.'] Uw klantportaal is bijgewerkt !'; $message = 'Uw klantportaal is zojuist door DogMa Design bijgewerkt. U kunt inloggen om de wijzigingen te bekijken. Weet u de link niet meer? Mail ons gerust!'; wp_mail($to, $subject, $message); } add_action( 'save_post_klantportaal', 'cpc_send_email_on_page_update' );
Hello @dogmadesign,
Please open a support ticket on our website so we can pursue this further.
Regards.
Can you please share how you made this work?
I need this also!!!Thank you!
I didn’t make it work. They asked me to open a support ticket and I did, but I never heard anything after that.
I got to work by adding the above custom code to the function.php in my theme.
Works great now!Maybe it is because I used Themler to build the theme or because I use Visual Composer
- This reply was modified 7 years ago by RianneTemmen.
Hello @dogmadesign,
I can’t find the ticket anymore. But I remember answering it myself. The code works as it is, it needs to be debugged on your website so we can find out why it breaks.
If you wish to open another ticket go ahead, just make sure you supply a correct email address that we can reply to.
@chuckglenn,
That’s all you have to do, add it to your website. I’m glad that it’s working.Regards.
- This reply was modified 7 years ago by Georgian Cocora.
I tried with another theme and then it works fine. So there must be something in my theme causing a problem.
It was indeed a Themler thing. In Themler you cannot add code to the functions.php, but you have to add the code in the theme in Themler:
https://answers.themler.io/questions/148287/functions-php-added-code-not-working?page=1
It is working great now!
Great that it’s working.
Regards.
- The topic ‘Send mail when private page is updated’ is closed to new replies.