• Resolved nfranklin

    (@nfranklin)


    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 );
    
    			}
    
    		}
    	}

    http://wordpress.org/extend/plugins/edit-flow/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nfranklin

    (@nfranklin)

    It would be great to see this in the notification module (if that is the direction that you guys want to take)

    Ideally, I want to be able to approve updates before they happen, however, at the moment, I think sending an email to the reviewers when a post is updated combined with viewing post revisions should do the trick for now.

    In order to put a post through the approval workflow after it has already been published, it first needs to be unpublished. This functionality is not ideal, but would love to be able to send the proposed updates for review while maintaining the existing published version online. Is there any plans to better integrate post update revisions in this way?

    Thanks for a great plugin too! Good work!

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    Sorry, I’m not following what this does. Could you explain a bit further about how it differs from the native Edit Flow notifications functionality?

    Ideally, I want to be able to approve updates before they happen, however, at the moment, I think sending an email to the reviewers when a post is updated combined with viewing post revisions should do the trick for now.

    This is probably outside the scope of what Edit Flow is intended for. Revisionary would suit the bill if you’re looking at content that’s already been published.

    Also, I’d love to show a diff of the text changes in the email sent out when the post status changes. Pull requests are more than welcome 🙂

    Thread Starter nfranklin

    (@nfranklin)

    Hi Daniel,

    This code will simply email the notifications group when updates are made to the post AFTER the post has already been published.

    I have looked at revisionary, but it still has a little way to go before I could use it. It’s a nice plugin, but needs additional work such as custom fields revision.

    I would love to find a complete wordpress workflow plugin (multiple level approval, updating approval etc..).

    Thanks again for EditFlow, it’s been great for me 🙂

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.