Hi wonderliza,
After a bit of trial and error, I found the solution to your problem (and my own). I’m assuming that your issue is the same as mine: You want to subscribe a group to a page/post when in a particular status. When the status of that page/post changes, you want to unsubscribe the current group and subscribe the new group relevant to the new status. Well, I managed to do that by doing the following…
I added the following in my theme’s functions.php file (You could also do this by creating a plugin for this):
function efx_auto_subscribe_usergroup( $new_status, $old_status, $post ) {
global $edit_flow;
// Remove existing user group(s) every time the status changes
if ( $new_status ) {
$usergroup_ids_to_follow = array();
$edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, false );
};
// "Editorial review" status subscribes "Content manager" group
if ( 'editorial-review' == $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(30);
$edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
};
// "Quality control" status subscribes "Quality assurance" group
if ( 'qa-review' == $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(11);
$edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
};
// "SEO review" status subscribes "SEO" group
if ( 'seo-check' == $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(16);
$edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
};
// "To be published" status subscribes "Content manager" group
if ( 'to-be-published' == $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(30);
$edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
};
// Return true to send the email notification
return $new_status;
};
add_filter( 'ef_notification_status_change', 'efx_auto_subscribe_usergroup', 10, 3 );
This listens for a change to a page/post status and then removes all the existing subscriptions. Based on the new status chosen, it then subscribes the user group.
I hope this helps.