• Hi,
    I added a function to automatically add or remove groups based on a specific status, as decribed on Edit Flow web site
    My problem is that the unfollow does not seem to work. Here is my code :

    if ( 'a-planifier' == $new_status ) {
    
             //unfollow for relecteurs
                $usergroup =  $edit_flow->user_groups ->get_usergroup_by( 'id', 487 );
    
                foreach( $usergroup->user_ids as $userID) {
                			$edit_flow->notifications->unfollow_post_user($post->ID, $userID);
                }			
    
            // follow for redaction
            $usergroup_ids_to_follow = array( 460 );
            $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Do you know what’s wrong with my code ?
    Thanks

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

    [No bumping, thank you.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter wonderliza

    (@wonderliza)

    Well I had no answer so it did it the dirty way !

    function efx_auto_subscribe_usergroup( $new_status, $old_status, $post ) {
        global $edit_flow;
        global $wpdb;
    
        if ( '1-brouillon' == $new_status ) {
    
        	//unfollow
                wp_delete_object_term_relationships( $post->ID,  'following_users');
                //wp_delete_object_term_relationships( $post->ID,  'ef_usergroup');
                $wpdb->query("DELETE FROM wp_term_relationships WHERE object_id = '" . $post->ID. "' AND term_taxonomy_id = 467 ");
                $wpdb->query("DELETE FROM wp_term_relationships WHERE object_id = '" . $post->ID. "' AND term_taxonomy_id = 516 ");
                $wpdb->query("DELETE FROM wp_term_relationships WHERE object_id = '" . $post->ID. "' AND term_taxonomy_id = 530 "); 		
    
            // follow for redaction
            $usergroup_ids_to_follow = array( 460 );
            $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
    
            $edit_flow->notifications->follow_post_user( $post->ID, $post->post_author, true );
        }
    
        if ( '2-relecture' == $new_status ) {
    
        	//unfollow
                wp_delete_object_term_relationships( $post->ID,  'following_users');
               // wp_delete_object_term_relationships( $post->ID,  'ef_usergroup');
                $wpdb->query("DELETE FROM wp_term_relationships WHERE object_id = '" . $post->ID. "' AND term_taxonomy_id = 467 ");
                $wpdb->query("DELETE FROM wp_term_relationships WHERE object_id = '" . $post->ID. "' AND term_taxonomy_id = 516 ");
                $wpdb->query("DELETE FROM wp_term_relationships WHERE object_id = '" . $post->ID. "' AND term_taxonomy_id = 530 "); 		
    
            //follow for relecteurs
        	$usergroup_ids_to_follow = array( 487 );
            $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
    
             // follow for redaction
            $usergroup_ids_to_follow = array( 460 );
            $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
    
            $edit_flow->notifications->follow_post_user( $post->ID, $post->post_author, true );
    
        }
    
     // Return true to send the email notification
        return true;
    
    }
    add_filter( 'ef_notification_status_change', 'efx_auto_subscribe_usergroup', 10, 3 );

    Seems to work, but i’m really not a fan of manually delete records on the table 😉

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Unfollow a post for a group’ is closed to new replies.