WordPress.org

Ready to get started?Download WordPress

Forums

Author notification (6 posts)

  1. leemustard
    Member
    Posted 1 year ago #

    Hi , Is there a plugin that can notify a post author once they edit/modify their post.

    So basically once the user(author) logs in, and edits his/her post, i want to fire off an email, now ive found a script online but it doesnt seem to work, i have also added a a function (to functions.php) once the user role has been changed, but need one for post edits.

    Any plugins,code snippets or help will be appreciated

    Thanks Guys

  2. Chris
    Member
    Posted 1 year ago #

    You can hook into process of saving a post or page and then send an email to the author:

    add_action( 'save_post', 'notifyAuthorOnPostModification' );
    
    function notifyAuthorOnPostModification() {
    
      global $post;
    
      $author   = get_user_by( 'id', (int) $post->post_author );
    
      $to       = $author->data->user_email;
    
      $subject  = 'A post of yours has been modified';
    
      $message  = "Your Article '" . $post->post_title . "' (" . get_permalink( $post->ID ) . ') has been modified on ' . date( 'Y-m-d (H:i:s)', time() ); // Or something like that
    
      wp_mail( $to, $subject, $message );
    
    }
  3. leemustard
    Member
    Posted 1 year ago #

    Thanks i will test this and revert. Appreciate it

  4. mustardmarketing
    Member
    Posted 1 year ago #

    Hi Chris

    This code works 100% perfectly when editing the posts from the back-end - thank you!

    But to throw a spanner in the works now - we actually block the WordPress backend from the users and they modify their posts using the WP User Front-end plugin.

    When we update posts from the front-end, we still receive the notification emails, however because the "edit post" page itself was created by the site administrator, that is where the emails go - instead of the post author.

    Any idea how we could resolve this?

  5. Chris
    Member
    Posted 1 year ago #

    I'm not exactly familiar with the WP Use Front-end plugin but from what I see, it offers it's own hook for after saving a post.

    So instead of add_action( 'save_post', 'notifyAuthorOnPostModification' );
    you could test add_action( 'wpuf_add_post_after_insert', 'notifyAuthorOnPostModification' ); and see if this will do the trick.

  6. mustardmarketing
    Member
    Posted 1 year ago #

    Hi Chris

    Unfortunately this didn't seem to work - but since in order to edit a post you first need to be signed in, we simply grabbed the current logged in user's details and fired off the mail to him/her. (We have locked it down so that only logged in users can edit/delete their own posts.

    Here is the code we used:

    function notifyAuthorOnPostModification() {

    global $post;

    $username = wp_get_current_user();
    $to = $username->data->user_email;
    $subject = 'Subject lines goes here';
    $user = $user_info->display_name;
    $message = 'Message goes here';

    wp_mail( $to, $subject, $message );

    Thanks for your assistance!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.