[Plugin: Edit Flow] Send email on every post update to notification groups.
-
Hi all,
Here’s a quick tip to extend notification functionality to notify users when updates occur to the actual post. This code kicks in after the post has been published.
I’m sure it could be written bettter, but it works for me ??
$post_props = array(); // add some actions for when a post is updated add_action("edit_post", "nt_send_edit_post"); add_action("pre_post_update", "nt_send_pre_post_update"); function nt_send_pre_post_update($post_id) { $post_status = get_post_status($post_id); $post_props[$post_id] = $post_status; } function nt_send_edit_post($post_id) { $post = get_post($post_id); $post_title = $post->post_title; $post_type = ucwords( $post->post_type ); $post_status = $post->post_status; $post_author = get_userdata( $post->post_author ); $blogname = get_option('blogname'); $edit_link = htmlspecialchars_decode( get_edit_post_link( $post_id ) ); $view_link = htmlspecialchars_decode( get_permalink( $post_id ) ); // Get current user $current_user = wp_get_current_user(); if($post_props[$post_id] == "publish" && $post_status == $post_props[$post_id]) { // the post was updated, we need to send out a notification to all the subscribed users if the functionality is available if(class_exists("EF_Notifications")) { $note = new EF_Notifications(); $subject = sprintf( __( '[%1$s] %2$s updated: "%3$s"', 'edit-flow' ), $blogname, $post_type, $post_title ); $body = sprintf( __( 'A %1$s (#%2$s "%3$s") was updated by %4$s %5$s', 'edit-flow' ), $post_type, $post_id, $post_title, $current_user->display_name, $current_user->user_email ) . "\r\n"; /* translators: 1: date, 2: time, 3: timezone */ $body .= sprintf( __( 'This action was taken on %1$s at %2$s', 'edit-flow' ), date( get_option( 'date_format' ) ), date( get_option( 'time_format' ) )) . "\r\n"; // Email body $body .= "\r\n"; $body .= "--------------------\r\n\r\n"; $body .= sprintf( __( '== %s Details ==', 'edit-flow' ), $post_type ) . "\r\n"; $body .= sprintf( __( 'Title: %s', 'edit-flow' ), $post_title ) . "\r\n"; /* translators: 1: author name, 2: author email */ $body .= sprintf( __( 'Author: %1$s (%2$s)', 'edit-flow' ), $post_author->display_name, $post_author->user_email ) . "\r\n"; $body .= "\r\n"; $body .= __( '== Actions ==', 'edit-flow' ) . "\r\n"; $body .= sprintf( __( 'Add editorial comment: %s', 'edit-flow' ), $edit_link . '#editorialcomments/add' ) . "\r\n"; $body .= sprintf( __( 'Edit: %s', 'edit-flow' ), $edit_link ) . "\r\n"; $body .= sprintf( __( 'View: %s', 'edit-flow' ), $view_link ) . "\r\n"; $body .= $note->get_notification_footer($post); $note->send_email( 'edit-update', $post, $subject, $body ); } } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘[Plugin: Edit Flow] Send email on every post update to notification groups.’ is closed to new replies.