Auto-subscribe user groups for notifications

A common request for Edit Flow is to auto-subscribe users and/or user groups for notifications. This would remove the repetition associated with the task, and reduces the likelihood of someone missing a notification when a post changes status or when an editorial comment is left.

Because of the complexity involved, Edit Flow doesn’t offer auto-subscription functionality through the admin. As of v0.7 it’s something you can easily do with a little bit of code.

First, read the introduction to extending Edit Flow. Once you’ve done so, you can modify the code snippet below to work for your needs. Think of this as a mini-framework for doing whatever you want to do at the action. The snippet below follows user groups for the specified status, but you could also have it unfollow other user groups, or define different statuses for each action to occur.

/**
 * Auto-subscribe or unsubscribe an Edit Flow user group when a post changes status
 *
 * @see http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/
 *
 * @param string $new_status New post status
 * @param string $old_status Old post status (empty if the post was just created)
 * @param object $post The post being updated
 * @return bool $send_notif Return true to send the email notification, return false to not
 */
function efx_auto_subscribe_usergroup( $new_status, $old_status, $post ) {
	global $edit_flow;

	// Choose the slug for whichever status you'd like to auto-subscribe on
	if ( 'assigned' == $new_status ) {
		// You'll need to get term IDs for your user groups and place them as
		// comma-separated values
		$usergroup_ids_to_follow = array(
				// 18,
			);
		$edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
	}
	// Return true to send the email notification
	return true;
}
add_filter( 'ef_notification_status_change', 'efx_auto_subscribe_usergroup', 10, 3 );