[buddypress-trac] [BuddyPress Trac] #8343: Custom Post Type activity in groups create duplicates

buddypress-trac noreply at wordpress.org
Fri Aug 7 21:23:49 UTC 2020


#8343: Custom Post Type activity in groups create duplicates
--------------------------+------------------------------
 Reporter:  etatus        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Activity      |     Version:  6.1.0
 Severity:  major         |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by etatus):

 I found a workaround. It is not elegant, but it seems to avoid the
 creation of duplicate activities for the same cpt post on updating.
 {{{#!php
 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';
                         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);
 }}}

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8343#comment:2>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list