BuddyDev

Search

[Resolved] Request to add 'Left group' activity entry to BuddyPress

  • Participant
    Level: Initiated
    Posts: 5
    Tony on #2708

    When a user joins a group, this is recorded in the activity stream:
    <user> joined the group <group name>

    When a user leaves a group no corresponding activity is recorded. I think it should record
    <user> left the group <group name>

    Rational:
    (1) just as it is useful to know who has joined, so it is useful to know when someone leaves.
    (2) I have seen a user join, make a posting and then leave. I doubt they intended to. It is not clear whether that was deliberate or they happened to click on ‘leave group’ when they just meant to quit the screen. If they had seen an activity record saying they had left, they might have realised what they had done.

    thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #2713

    Hi Tony,
    Thank you.

    I understand your point and will post the code sometime later today 🙂

  • Participant
    Level: Initiated
    Posts: 11
    rugwarrior on #2976

    Was this code published somewhere?

  • Participant
    Level: Initiated
    Posts: 5
    Tony on #2980

    @rugwarrior…Not leaned of any code for this.

    I think it should become standard in BuddyPress and hope this thread has led to a change request.

  • Participant
    Level: Initiated
    Posts: 11
    rugwarrior on #2983

    @Tony The BuddyPress people are good guys (and girls). If it is not available I might post it as an idea.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #2995

    Hi,
    I am sorry, I missed to post.

    You can use the following code in your bp-custom.php to add a left group activity

    
    
    function buddydev_group_leave_group_activity(  $group_id, $user_id ) {
    
    	// Bail if Activity is not active
    	if ( ! bp_is_active( 'activity' ) ) {
    		return false;
    	}
    
    	// Get the group so we can get it's name
    	$group = groups_get_group( array( 'group_id' => $group_id ) );
    
    	$action = apply_filters_ref_array( 'groups_activity_left_group_action', array( sprintf( __( '%1$s left the group %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $user_id, &$group ) );
    
    	// Record in activity streams
    	groups_record_activity( array(
    		'action'  => $action,
    		'type'    => 'left_group',
    		'item_id' => $group_id,
    		'user_id' => $user_id
    	) );
    }
    
    add_action( 'groups_leave_group', 'buddydev_group_leave_group_activity', 10, 2 );
    
    

    Hope that helps.

    • This reply was modified 8 years, 9 months ago by Brajesh Singh. Reason: Updated the name of function to fix typo
  • Participant
    Level: Initiated
    Posts: 11
    rugwarrior on #2999

    Thanks 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #3001

    You are most welcome Rug 🙂

  • Participant
    Level: Initiated
    Posts: 5
    Tony on #3090

    Thank you Brajesh – that works well.

    • This reply was modified 8 years, 9 months ago by Tony.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #3092

    Thank you Tony 🙂

You must be logged in to reply to this topic.

This topic is: resolved