Skip to content

Developer Overview

BuddyPress Anonymous Activity is built as a standard WordPress plugin that hooks into BuddyPress (or BuddyBoss Platform) at the display layer. Anonymity is enforced by filtering what the visitor sees — the real author’s user_id remains intact in the database.

The plugin uses a loader pattern. Bp_Anonymous_Activities is the main controller class. It instantiates Bp_Anonymous_Activities_Loader, then registers all action and filter hooks through it. The loader defers add_action / add_filter calls until run() is called, which happens on plugin boot.

Key classes:

Class File Role
Bp_Anonymous_Activities includes/class-bp-anonymous-activities.php Boot, hook wiring
Bp_Anonymous_Activities_Admin admin/class-bp-anonymous-activities-admin.php Settings page, sanitization
Bp_Anonymous_Activities_Public public/class-bp-anonymous-activities-public.php Frontend display filters, AJAX, notification suppression
Bp_Anonymous_Buddyboss_Forums_Integration includes/class-bp-anonymous-buddyboss-forums-integration.php BuddyBoss forum anonymous topics/replies
Bp_Anonymous_Bbpress_Integration includes/class-bp-anonymous-bbpress-integration.php Standalone bbPress anonymous topics/replies

When a logged-in user submits an activity post or comment with the “Post as Anonymous User” checkbox checked, the plugin:

  1. Stores is_anonymous = true in BuddyPress activity meta (bp_activity_meta).
  2. Generates a short anonymous slug (e.g. anon3f9a2c) and stores it as anonymous_slug meta on the same activity.
  3. Leaves bp_activity.user_id pointing to the real author — the real user ID is never replaced in the database.
  4. At display time, filters on bp_get_activity_action, bp_get_activity_avatar, bp_get_activity_user_link, and related hooks swap the real author’s name and avatar for the configured anonymous text and avatar.
  5. Notification and email hooks fire early (priority 1) to prevent any BuddyPress or BuddyBoss notification from revealing the author before the display layer can mask them.

This approach means the real author can still edit or delete their own activity, profile permission checks continue to work, and admin users can always see who posted via the original user_id.

Meta key Location Type Notes
is_anonymous bp_activity_meta bool (true) Set when an activity or comment is posted anonymously. Absent when not anonymous.
anonymous_slug bp_activity_meta string Short opaque token. Format: anon prefix + 8 chars from SHA1. Filterable via bp_anonymous_activity_slug.
original_user_id bp_activity_meta int Legacy — written by older versions that used a sentinel user_id. A one-time migration on init restores the real user_id from this value and removes the need for it.
_bp_is_anonymous post_meta bool Set on bbp_topic / bbp_reply posts when the bbPress or BuddyBoss Forums integration handles an anonymous submission.
_bp_anonymous_user_id post_meta int Stores the real author’s user ID on bbPress / BuddyBoss Forums posts for admin reference.
_bbp_anonymous_name post_meta string Standard bbPress anonymous name field. Plugin writes 'Anonymous' so bbPress treats the post as anonymous.
_bbp_anonymous_email post_meta string Standard bbPress anonymous email field. Plugin writes anonymous@example.com.

Read settings with the bundled helper rather than calling get_option directly. The helper applies defaults for any missing keys and runs the bp_anonymous_activity_settings filter:

$settings = bp_anonymous_activity_settings();

The returned array has these keys:

bp_anonymous_user_role array Allowed roles (empty = all)
bp_anonymous_member_type array Excluded member types
bp_anonymous_enable_verified string 'yes' | 'no'
bp_anonymous_enable_groups string 'yes' | 'no'
bp_anonymous_enable_members string 'yes' | 'no'
bp_anonymous_enable_profile string 'yes' | 'no'
bp_anonymous_enable_comment string 'yes' | 'no'
bp_anonymous_enable_forums string 'yes' | 'no'
activity_field_label string Checkbox label text
comment_field_label string Comment checkbox label text
anonymous_text string Display name for anonymous authors
default_user_link string URL for anonymous profile link
default_gravatar_url string Anonymous avatar URL
default_gravatar string Anonymous avatar <img> HTML

The array is passed through the bp_anonymous_activity_settings filter before being returned, so downstream code can inspect or override any key.

For the full list of keys and their default values, see Settings Reference.

Function Description
bp_anonymous_activity_settings() Returns the settings array. Applies bp_anonymous_activity_settings filter.
bp_anonymous_activity_enable() Returns true when the current context (directory/group/profile) and user role permit anonymous posting. Applies bp_anonymous_activity_enable filter.
bp_anonymous_activity_check_user_role() Returns true when the current user’s role and member type are allowed. Applies bp_anonymous_activity_check_user_role filter. Used by forums and comments.
bp_anonymous_is_anonymous( $activity_id ) Returns true when the given activity has is_anonymous meta set. Applies bp_anonymous_is_anonymous filter.
bp_anonymous_activity_default_gravatar( $image = true ) Returns the anonymous avatar as an <img> tag ($image = true) or a URL string ($image = false).
bp_anonymous_activity_get_editable_roles() Returns the list of role slugs that appear in the role selector. Applies bp_anonymous_activity_get_editable_roles filter.
bp_anonymous_activity_allowed_html_tags() Returns the $allowed_html array passed to wp_kses when outputting checkbox HTML. Applies bp_anonymous_activity_allowed_html_tags filter.
bp_anonymous_is_anonymous_screen() Returns true when the current page is the single-activity permalink for an anonymous activity.
if ( bp_anonymous_is_anonymous( $activity_id ) ) {
// This activity is anonymous
}

Checking whether the current user can post anonymously

Section titled “Checking whether the current user can post anonymously”
// Context-aware check (respects location settings + roles + member types)
if ( bp_anonymous_activity_enable() ) {
// Show the checkbox
}
// Role-only check (no location context)
if ( bp_anonymous_activity_check_user_role() ) {
// User's role allows anonymous posting
}

The plugin registers one AJAX action used by the frontend JavaScript for edit-mode detection:

Action Availability Purpose
check_activity_anonymous logged-in + logged-out Returns whether a given activity ID is anonymous

The request is a POST to admin-ajax.php with action=check_activity_anonymous and activity_id. The response is 1 (anonymous) or 0 (not anonymous). Nonce verification applies via the bp_anonymous_activity nonce.

The plugin provides action hooks and filter hooks you can use to extend or modify its behavior without editing core files. These are documented in detail in Hooks & Filters.

Third-party plugin integrations (BuddyBoss Forums, bbPress, BP Verified Member, RTMedia) are covered in Third-Party Integrations.


Next: Hooks & Filters