Opened 4 years ago
Last modified 3 months ago
#8343 assigned defect (bug)
Custom Post Type activity in groups create duplicates
Reported by: | etatus | Owned by: | imath |
---|---|---|---|
Milestone: | 15.0.0 | Priority: | normal |
Severity: | normal | Version: | 2.2 |
Component: | Activity | Keywords: | needs-patch |
Cc: |
Description
If I add support for "buddypress-activity" to my CPT (with add_post_type_support()
and bp_activity_set_post_type_tracking_args()
functions) everything works fine.
If I especify 'component_id => 'groups'
in bp_activity_set_post_type_tracking_args()
, the tracking still works, but item_id
is by default the blog ID instead the group ID, so the activity is created but it will not be shown in group activity page.
If I fix this, using bp_after_activity_add_parse_args
filter to set item_id
to the group ID ($args['item_id'] = bp_get_current_group_id();
) the activity is created and it is shown in group activity page.
BUT...
The problem is everytime I update the post, a new activity is generated, so there will be several activities with exactly the same information for one single goup post.
Change History (10)
#3
@
3 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 10.0.0
- Severity changed from major to normal
- Version changed from 6.1.0 to 2.2
Hi @etatus
Thanks for your report. Reading your ticket, I realize the Post Type Activities API needs an improvement. Developers should be able to provide a new tracking argument: the callback function to use to get the single item_id for the selected component.
I'll try to have a look at it during 10.0.0. If someone wants to suggest a patch, they're very welcome 🙏.
#4
@
3 years ago
- Milestone changed from 10.0.0 to Up Next
I'm sad to write, I haven't found the time for this ticket, sorry about it. I'll come back to it during next major release.
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.
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);