Reply To: New Activity custom type groups
I found a workaround to avoid the creation of duplicate activities for the same cpt post on updating.
function me_activity_parse_args_filter( $args = array() ) {
if ( !empty( $args['type'] ) && $args['type'] == 'new_your-cpt' ) {
$activities = bp_activity_get(array(
'max' => 1,
'filter' => array(
'action' => 'new_your-cpt',
'secondary_id' => $args['secondary_item_id'],
),
) );
if (count($activities['activities'])==0) { // The cpt post doesn't have activity yet, so we set the group information
$args['component'] = 'groups'; // You could set this as 'component_id' in bp_activity_set_post_type_tracking_args
if ( !empty(bp_get_current_group_id()) ) $args['item_id'] = bp_get_current_group_id();
if (empty($args['content'])) $args['content'] = ' '; // To make sure content filter applies afterwards
} else { // Activity already exists
$args['type'] = false; // Delete duplicate activity
}
}
return $args;
}
add_filter('bp_after_activity_add_parse_args', 'me_activity_parse_args_filter',10,1);