Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to remove topics from digest when trashed #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bp-activity-subscription-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,35 @@ function bpges_delete_queued_items_for_activity_ids( $activity_ids ) {
}
add_action( 'bp_activity_deleted_activities', 'bpges_delete_queued_items_for_activity_ids' );

/**
* When a forum topic is deleted (trashed), Buddypress
* does not remove the corresponding activity from the activities table,
* but we still want to remove it from the digest. Hence this code, which
* deletes queued items for activities relating to the specified post id.
*
*
* @since ???
*/
function bpges_delete_queued_items_for_post_id( $post_id ) {
// get the activity id for the post. (The "show_hidden" is important because by
// default bp_activity_get ignores activities with the "hide_sitewide" setting on, such
// as those in private groups!)
$result = bp_activity_get(['show_hidden' => true, 'filter' => ['secondary_id' => $post_id]]);
foreach ( $result['activities'] as $activity ) {
// find the queued items for the activity and delete them.
$query = new bpges_queued_item_query( array(
'activity_id' => $activity->id,
) );

$queued_ids = array_keys( $query->get_results() );
if ( empty( $queued_ids ) ) {
return;
}
bpges_queued_item::bulk_delete( $queued_ids );
}
}
add_action( 'wp_trash_post', 'bpges_delete_queued_items_for_post_id' );

/**
* Queue an activity item for sending.
*
Expand Down