Eliminate Forgotten Friend Requests in BuddyBoss: A Step-by-Step Guide to Automated 3-Day Reminders

In an online community, unanswered friend requests can quickly pile up, leading to missed connections and less engagement. If you’re running BuddyBoss, you already know it provides excellent social features. But what if users forget about pending requests for days on end?

In this guide, you’ll learn how to:

  • Scan daily for pending friend requests older than 3 days.
  • Send a single email + notification to each user with such requests, preventing spam.
  • Integrate this logic into BuddyBoss’s native email/notification system so you can manage it from the WordPress admin.

The result? A more active, engaged community where friend requests don’t fall through the cracks.


1. Understanding the BuddyBoss Email “Situation”

Before we dive into the code, let’s clarify how BuddyBoss handles emails. BuddyBoss (and BuddyPress) uses a concept called an “Email Situation.” Think of it as a “trigger” or “scenario” that defines:

  1. When the email is sent (e.g., “A user is mentioned,” “A user’s request is accepted,” etc.).
  2. What the default subject, body, and plain-text content look like.
  3. Which tokens (placeholders like {{poster.name}}) can be merged into the email content.

Why it’s helpful: Once you define a custom situation, you’ll see it in BuddyBoss → Emails, where admins can edit the email subject, body, or design—just like built-in BuddyBoss emails.


2. The Daily Cron Logic

Cron (short for “chronograph”) is a scheduling mechanism. In WordPress, WP-Cron runs automatically when your site gets traffic, triggering scheduled tasks. We’ll use it to:

  1. Once a day, query the database for friend requests that are still pending (is_confirmed = 0) and older than 3 days (date_created < (now - 3 days)).
  2. Group these requests by the user who needs to respond.
  3. Send a single consolidated notification + email to that user—only if we haven’t emailed them in the last 3 days.

Result: No spamming. If they ignore the requests for multiple days, they’ll get one reminder every 3 days until they accept or reject.


3. The Notification System

BuddyBoss extends BuddyPress’s in-app notification feature. Usually, you see these notifications in the user’s toolbar or notifications menu. Our code will:

  1. Add a custom notification type with register_notification_type()—this is the “3-Day Friend Requests” type.
  2. Fire a new notification with bp_notifications_add_notification() whenever we detect old requests.
  3. Link that notification to a custom page (or the default friend requests page) so the user can see and act on them.

Why it’s important: Some users check their notifications more often than email, so hitting both channels ensures maximum reach.


4. Putting It All Together (Step-by-Step)

Below is a high-level overview of the code you’ll include in a single-file plugin (e.g., buddyboss-3day-friend-requests.php). We’ll break it into logical sections:

4.1 Plugin Header & Basic Setup

  • Plugin Header: Tells WordPress your plugin’s name, description, and text domain (for translations).
  • Activating it in WordPress will run our hooks.

4.2 Activation Hook

  • BuddyBoss Check: If BuddyBoss isn’t active, we bail.
  • Daily Cron: Schedules bb_3day_friend_check_event once a day.

4.3 Deactivation Hook

  • Cleanup: Prevents leftover cron tasks when your plugin is turned off.

4.4 Defining the Notification Class

Key Points:

  • register_email_type() defines the “Email Situation” for BuddyBoss → Emails.
  • register_notification_type() sets up a “3-Day Friend Requests” type in BuddyBoss → Settings → Notifications.
  • format_notification() returns the link/text for the in-app notice.

4.5 Triggering the Notification + Email

What Happens:

  1. bp_notifications_add_notification(): Creates a new BuddyBoss in-app notification.
  2. bp_send_email(): Fires off the “3-day requests” email using the tokens we pass.
  3. update_user_meta(): Records the timestamp so we only send again if 3 more days pass.

4.6 The Daily Cron Function

Key Points:

  • SQL Query: Looks in bp_friends for is_confirmed = 0 (pending) and date_created older than 3 days.
  • Grouping: We store each initiator link in $pending_requests[ $friend_user_id ].
  • Check Timestamp: If the user was emailed in the last 3 days, skip. Otherwise, call our trigger function.

5. Testing & Tweaks

  • Change -3 days to -10 minutes for quick tests.
  • Manually run the cron function by hooking it into an admin page or using WP-CLI:
  • Shortcode: If you want a simple [pending_requests_count] on a page, you can write a small function to query how many 3-day-old requests the current user has.

Conclusion

By defining a custom email situation, hooking a daily cron job, and sending one notification/email per user, you ensure:

  1. No spam: The user only sees one reminder every 3 days if they still have old requests.
  2. Better engagement: Friend requests aren’t forgotten indefinitely.
  3. Admin control: You can edit the email’s subject/body in BuddyBoss → Emails and toggle the notification in BuddyBoss → Settings → Notifications.

Try it out, and watch your BuddyBoss community become more responsive, more engaged, and free of neglected friend requests!

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *