Skip to content

Instantly share code, notes, and snippets.

@contemplate
Last active April 25, 2026 20:51
Show Gist options
  • Select an option

  • Save contemplate/4fa9ada2c6bdcabd18d281054f199b3f to your computer and use it in GitHub Desktop.

Select an option

Save contemplate/4fa9ada2c6bdcabd18d281054f199b3f to your computer and use it in GitHub Desktop.
BPGES integration with BuddyBoss
/**
* Prevent duplicate emails between BPGES and BuddyBoss Group Subscriptions.
*
* The problem: Both systems send emails on group activity.
* - BuddyBoss hooks bp_groups_posted_update → sends 'groups-new-activity' immediately
* - BPGES hooks bp_activity_after_save → sends 'bp-ges-single' immediately for supersub/sub users
* Result: Users on "All Email" or "New Topics" get two emails per post.
*
* The solution: Let each system handle what it does best.
* - 'supersub' (All Email) → BuddyBoss sends immediate email, BPGES is blocked
* - 'sub' (New Topics) → BuddyBoss sends immediate email, BPGES is blocked
* - 'dig' (Daily Digest) → BPGES handles digest, BuddyBoss is blocked
* - 'sum' (Weekly Summary) → BPGES handles summary, BuddyBoss is blocked
* - 'no' (No Email) → Both are blocked
*
* Web/app notifications from BuddyBoss are NOT affected.
*
* Filter references in BuddyBoss source:
* bb_send_subscribed_group_email_notifications
* → bp-groups/classes/class-bp-groups-notification.php
* inside bb_send_subscribed_group_notifications()
*
* Filter references in BPGES source:
* bp_ass_send_activity_notification_for_user
* → bp-activity-subscription-functions.php
* inside ass_group_notification_activity()
*/
// ──────────────────────────────────────────────────────────────────────
// 1. Block BuddyBoss immediate emails for digest, summary, and no-email users.
// Only allow BuddyBoss emails when BPGES is set to All Email or New Topics.
// ──────────────────────────────────────────────────────────────────────
add_filter( 'bb_send_subscribed_group_email_notifications', 'bpges_block_bb_group_sub_emails', 10, 2 );
function bpges_block_bb_group_sub_emails( $send_mail, $args ) {
if ( false === $send_mail ) {
return $send_mail;
}
if ( ! function_exists( 'ass_get_group_subscription_status' ) ) {
return $send_mail;
}
$user_id = ! empty( $args['recipient_user_id'] ) ? (int) $args['recipient_user_id'] : 0;
$group_id = ! empty( $args['group_id'] ) ? (int) $args['group_id'] : 0;
if ( empty( $user_id ) || empty( $group_id ) ) {
return $send_mail;
}
$sub_status = ass_get_group_subscription_status( $user_id, $group_id );
// Only allow BuddyBoss immediate emails for instant-notification users.
$allow_immediate = array( 'supersub', 'sub' );
if ( ! in_array( $sub_status, $allow_immediate, true ) ) {
return false;
}
return $send_mail;
}
// ──────────────────────────────────────────────────────────────────────
// 2. Block BPGES immediate emails for supersub/sub users when BuddyBoss
// Group Subscriptions is active (to prevent duplicates).
// BPGES still handles digest and summary — those are unaffected.
// ──────────────────────────────────────────────────────────────────────
add_filter( 'bp_ass_send_activity_notification_for_user', 'block_bpges_immediate_when_bb_subscriptions_active', 10, 4 );
function block_bpges_immediate_when_bb_subscriptions_active( $send_immediately, $activity, $user_id, $subscription_type ) {
// Only intervene if BuddyBoss Group Subscriptions is active.
if ( ! function_exists( 'bb_is_enabled_subscription' ) || ! bb_is_enabled_subscription( 'group' ) ) {
return $send_immediately;
}
// Only block immediate sends — digest/summary queueing is separate.
if ( false === $send_immediately ) {
return $send_immediately;
}
// For supersub and sub users, BuddyBoss handles the immediate email.
// Block BPGES from sending a duplicate.
if ( in_array( $subscription_type, array( 'supersub', 'sub' ), true ) ) {
return false;
}
return $send_immediately;
}
@contemplate
Copy link
Copy Markdown
Author

BPGES + BuddyBoss Group Subscription Email Deduplication

The Problem

Both systems send emails on group activity:

  • BuddyBoss hooks bp_groups_posted_update → sends groups-new-activity immediately
  • BPGES hooks bp_activity_after_save → sends bp-ges-single immediately for supersub/sub users

Result: Users on "All Email" or "New Topics" get two emails per post.

The Solution

Let each system handle what it does best. BuddyBoss handles immediate emails (nicer templates). BPGES handles digests and summaries (BuddyBoss doesn't have this feature).

BPGES Setting Code BB Email BPGES Email Result
All Email supersub ✅ Sends ❌ Blocked One immediate email via BuddyBoss
New Topics sub ✅ Sends ❌ Blocked One immediate email via BuddyBoss
Daily Digest dig ❌ Blocked ✅ Queued Daily digest via BPGES
Weekly Summary sum ❌ Blocked ✅ Queued Weekly summary via BPGES
No Email no ❌ Blocked ❌ Blocked No emails

Note: BuddyBoss web/app notifications are NOT affected by any of this — only emails.

Filters Used

Filter 1: bb_send_subscribed_group_email_notifications

  • Location: bp-groups/classes/class-bp-groups-notification.phpbb_send_subscribed_group_notifications()
  • Purpose: Block BuddyBoss emails for dig, sum, and no users

Filter 2: bp_ass_send_activity_notification_for_user

  • Location: bp-activity-subscription-functions.phpass_group_notification_activity()
  • Purpose: Block BPGES immediate emails for supersub and sub users (BuddyBoss handles these instead)

Related Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment