Skip to content

Hooks & Filters

All hooks listed here are grep-verified against the plugin source. The exact do_action or apply_filters call is noted after each entry so you can locate it in the code.

All hooks use the add_action / add_filter API. Place code in your theme’s functions.php or a custom plugin.

Source files: bp-anonymous-activities.php, includes/bp-anonymous-general-functions.php, public/class-bp-anonymous-activities-public.php, admin/class-bp-anonymous-activities-admin.php, includes/class-bp-anonymous-bbpress-integration.php, includes/class-bp-anonymous-buddyboss-forums-integration.php.


Fires inside bp_anonymous_activity_add_activity_checkbox() before the checkbox HTML is output into the activity post form.

Parameters: none Source: public/class-bp-anonymous-activities-public.php:196

add_action( 'bp_anonymous_activity_before_checkbox', function() {
echo '<p class="anonymous-notice">Your identity will not be visible to other members.</p>';
} );

Fires after the anonymous checkbox HTML is echoed into the activity post form.

Parameters: none Source: public/class-bp-anonymous-activities-public.php:205

add_action( 'bp_anonymous_activity_after_checkbox', function() {
echo '<small>Admins can still see who posted.</small>';
} );

Fires after an activity is saved and its is_anonymous meta is written. Only fires when the user checked the anonymous checkbox.

Parameters:

  • $activity_id (int) — BuddyPress activity ID
  • $activity (BP_Activity_Activity) — The activity object

Source: public/class-bp-anonymous-activities-public.php:263

add_action( 'bp_anonymous_activity_created', function( $activity_id, $activity ) {
bp_activity_update_meta( $activity_id, 'flagged_for_review', 1 );
}, 10, 2 );

Fires at the end of bp_anonymous_activity_save_metadata() for every activity save attempt that passed the nonce check, whether or not the anonymous checkbox was ticked.

Parameters:

  • $activity (BP_Activity_Activity) — The activity object

Source: public/class-bp-anonymous-activities-public.php:267


Fires before the anonymous comment checkbox HTML is returned by bp_anonymous_activity_comment_button_html().

Parameters: none Source: includes/bp-anonymous-general-functions.php:314


Fires after the anonymous comment checkbox HTML is prepared (but the function returns HTML rather than echoing it, so this fires while still inside the function call).

Parameters: none Source: includes/bp-anonymous-general-functions.php:326


Fires after an activity comment is saved with is_anonymous = true meta.

Parameters:

  • $comment_id (int) — BuddyPress activity comment ID

Source: public/class-bp-anonymous-activities-public.php:287

add_action( 'bp_anonymous_comment_created', function( $comment_id ) {
bp_activity_update_meta( $comment_id, 'review_required', 1 );
} );

bp_anonymous_activity_save_comment_metadata

Section titled “bp_anonymous_activity_save_comment_metadata”

Fires at the end of the comment metadata handler after the nonce check, for every comment save (anonymous or not).

Parameters:

  • $comment_id (int) — BuddyPress activity comment ID

Source: public/class-bp-anonymous-activities-public.php:291


Fires before the anonymous checkbox is output on bbPress topic and reply forms, and on BuddyBoss Forums forms.

Parameters: none Source: includes/class-bp-anonymous-bbpress-integration.php:134, includes/class-bp-anonymous-buddyboss-forums-integration.php:434


Fires after the anonymous checkbox HTML on forum forms.

Parameters: none Source: includes/class-bp-anonymous-bbpress-integration.php:145, includes/class-bp-anonymous-buddyboss-forums-integration.php:446


Fires after an anonymous forum topic has been created and its post meta written.

Parameters:

  • $topic_id (int) — bbPress topic post ID
  • $forum_id (int) — bbPress forum post ID
  • $original_author (int) — Real user ID of the author

Source: includes/class-bp-anonymous-bbpress-integration.php:244, includes/class-bp-anonymous-buddyboss-forums-integration.php:487

add_action( 'bp_anonymous_forum_topic_created', function( $topic_id, $forum_id, $original_author ) {
update_post_meta( $topic_id, 'my_moderation_queue', 1 );
}, 10, 3 );

Fires after an anonymous forum reply has been created and its post meta written.

Parameters:

  • $reply_id (int) — bbPress reply post ID
  • $topic_id (int) — bbPress topic post ID
  • $forum_id (int) — bbPress forum post ID
  • $original_author (int) — Real user ID of the author

Source: includes/class-bp-anonymous-bbpress-integration.php:304, includes/class-bp-anonymous-buddyboss-forums-integration.php:545


Fires after a BuddyBoss Forums topic creates or updates its corresponding BuddyPress activity item.

Parameters:

  • $activity_id (int) — BuddyPress activity ID
  • $post_id (int) — bbPress topic post ID
  • $activity (BP_Activity_Activity) — The activity object

Source: includes/class-bp-anonymous-buddyboss-forums-integration.php:174


Fires after a BuddyBoss Forums reply creates or updates its BuddyPress activity item.

Parameters:

  • $activity_id (int) — BuddyPress activity ID
  • $post_id (int) — bbPress reply post ID
  • $activity (BP_Activity_Activity) — The activity object

Source: includes/class-bp-anonymous-buddyboss-forums-integration.php:176


Fires after the settings partial is included on the plugin’s admin settings page. Use this to append custom tab content rendered by the bp_anonymous_activity_admin_setting_tabs filter.

Parameters: none Source: admin/class-bp-anonymous-activities-admin.php:249


Controls whether the anonymous checkbox appears for the current user and context. The plugin runs all its context checks (directory / group / profile setting, BP Verified Member, user role, member type) and then passes the result through this filter. Return false to suppress the checkbox; return true to force it on regardless of settings.

Parameters:

  • $enabled (bool) — Result after all built-in checks

Returns: bool Source: includes/bp-anonymous-general-functions.php:213

// Disable anonymous posting during maintenance
add_filter( 'bp_anonymous_activity_enable', function( $enabled ) {
if ( get_option( 'maintenance_mode' ) ) {
return false;
}
return $enabled;
} );
// Disable for users who have been warned
add_filter( 'bp_anonymous_activity_enable', function( $enabled ) {
if ( get_user_meta( get_current_user_id(), 'anon_posting_suspended', true ) ) {
return false;
}
return $enabled;
} );

Controls whether the current user’s role and member type pass the role check used by comments and forums. The plugin evaluates role and member type restrictions before calling this filter with its result.

Parameters:

  • $allowed (bool) — Result after built-in role checks

Returns: bool Source: includes/bp-anonymous-general-functions.php:135

// Require a custom capability
add_filter( 'bp_anonymous_activity_check_user_role', function( $allowed ) {
if ( current_user_can( 'post_anonymously' ) ) {
return true;
}
return $allowed;
} );

Controls whether a given activity ID is treated as anonymous. The default is the value of the is_anonymous activity meta. Override this when your site stores anonymity in a different location.

Parameters:

  • $is_anonymous (mixed) — Value of is_anonymous activity meta (string "1" or empty string)

Returns: bool|string Source: includes/bp-anonymous-general-functions.php:256


Filters the full checkbox <div> HTML for activity post forms before it is passed through wp_kses and echoed.

Parameters:

  • $html (string) — Complete checkbox wrapper HTML
  • $location (string) — Always 'activity' when called from the post form

Returns: string Source: public/class-bp-anonymous-activities-public.php:200

add_filter( 'bp_anonymous_activity_checkbox_html', function( $html, $location ) {
return str_replace( '<input', '<input data-anon-location="' . esc_attr( $location ) . '"', $html );
}, 10, 2 );

Filters the checkbox HTML for activity comment forms. The second parameter is always 'comment'.

Parameters:

  • $html (string) — Complete checkbox wrapper HTML
  • $location (string) — Always 'comment'

Returns: string Source: includes/bp-anonymous-general-functions.php:321


Filters the final activity action string (the line of text shown after the author’s name, e.g. “posted an update”) after the plugin has replaced the author link with the anonymous text.

Parameters:

  • $action (string) — Activity action text (may contain HTML)
  • $activity (BP_Activity_Activity) — The activity object

Returns: string Source: public/class-bp-anonymous-activities-public.php:318


Filters the profile URL that the activity stream uses for the author link. When the activity is anonymous, the plugin has already set this to the default_user_link setting value ('#' by default) before the filter fires.

Parameters:

  • $user_link (string) — The author profile URL
  • $activity (BP_Activity_Activity) — The activity object

Returns: string Source: public/class-bp-anonymous-activities-public.php:341

add_filter( 'bp_anonymous_activity_change_user_link', function( $link, $activity ) {
if ( bp_anonymous_is_anonymous( $activity->id ) ) {
return home_url( '/anonymous-author/' );
}
return $link;
}, 10, 2 );

Filters the avatar <img> HTML used in the activity stream for the author. When the activity is anonymous, the plugin has already swapped in the configured anonymous avatar before the filter fires.

Parameters:

  • $gravatar_image (string) — Avatar HTML
  • $current_activity_item (object) — The activity or comment item from $activities_template

Returns: string Source: public/class-bp-anonymous-activities-public.php:364


bp_anonymous_activity_modify_comment_action

Section titled “bp_anonymous_activity_modify_comment_action”

Filters the comment action string for BuddyPress Nouveau after the plugin has replaced the commenter’s display name with anonymous text.

Parameters:

  • $action (string) — Comment action text
  • $comment (object) — The current comment item

Returns: string Source: public/class-bp-anonymous-activities-public.php:389


Filters the profile URL for anonymous comment authors. Behaves like bp_anonymous_activity_change_user_link but applies to comments.

Parameters:

  • $user_link (string) — The commenter profile URL
  • $comment (object) — The current comment item

Returns: string Source: public/class-bp-anonymous-activities-public.php:413


bp_anonymous_activity_modify_user_display_name

Section titled “bp_anonymous_activity_modify_user_display_name”

Filters the activity action string specifically to replace <a> author links on group pages (BuddyBoss unique-identifier profile URLs). Runs at priority 999 via the bp_get_activity_action core hook.

Parameters:

  • $action (string) — Activity action HTML

Returns: string Source: public/class-bp-anonymous-activities-public.php:1008


bp_anonymous_activity_get_reply_author_display_name

Section titled “bp_anonymous_activity_get_reply_author_display_name”

Filters the display name returned by bp_core_get_user_displayname when called in the context of an anonymous activity’s comment thread.

Parameters:

  • $author_name (string) — The display name (anonymous text or real name)
  • $user_id (int) — The user whose name was resolved
  • $current_id (int) — The current context user ID

Returns: string Source: public/class-bp-anonymous-activities-public.php:960, public/class-bp-anonymous-activities-public.php:964


bp_anonymous_activity_bp_get_activity_action_pre_meta

Section titled “bp_anonymous_activity_bp_get_activity_action_pre_meta”

Filters the activity action string after the plugin removes the secondary (group/friend) avatar for RTMedia anonymous activities.

Parameters:

  • $action (string) — Activity action HTML
  • $activity (BP_Activity_Activity) — The activity object
  • $secondary_avatar (string) — The secondary avatar HTML

Returns: string Source: public/class-bp-anonymous-activities-public.php:1113, public/class-bp-anonymous-activities-public.php:1129


Filters the replacement value for the secondary (group/friend) avatar in RTMedia activity items that are anonymous. Default replacement is an empty string.

Parameters:

  • $replacement (string) — The HTML to substitute for the real secondary avatar (default '')
  • $secondary_avatar (string) — The original secondary avatar HTML
  • $activity (BP_Activity_Activity) — The activity object

Returns: string Source: public/class-bp-anonymous-activities-public.php:1106, public/class-bp-anonymous-activities-public.php:1122


Filters the pixel size passed to Gravatar when building the default anonymous avatar URL. Default: 150.

Parameters:

  • $size (int) — Avatar size in pixels

Returns: int Source: includes/bp-anonymous-general-functions.php:273

add_filter( 'bp_anonymous_activity_default_avatar_size', function( $size ) {
return 100;
} );

bp_anonymous_activity_change_default_avatar

Section titled “bp_anonymous_activity_change_default_avatar”

Filters the Gravatar default image type parameter (d= query string) used in the anonymous avatar URL. Default: 'mystery'. Other Gravatar types include 'identicon', 'monsterid', 'retro', 'robohash', 'wavatar'.

Parameters:

  • $type (string) — Gravatar default type slug

Returns: string Source: includes/bp-anonymous-general-functions.php:274

add_filter( 'bp_anonymous_activity_change_default_avatar', function( $type ) {
return 'robohash';
} );

bp_anonymous_activity_default_avatar_image_url

Section titled “bp_anonymous_activity_default_avatar_image_url”

Filters the full anonymous avatar URL before it is used to build the <img> tag or stored in settings.

Parameters:

  • $url (string) — Full avatar URL

Returns: string Source: includes/bp-anonymous-general-functions.php:275

add_filter( 'bp_anonymous_activity_default_avatar_image_url', function( $url ) {
return 'https://example.com/anon-avatar.png';
} );

Filters the complete anonymous avatar <img> HTML tag returned by bp_anonymous_activity_default_gravatar( true ).

Parameters:

  • $html (string) — <img> tag HTML

Returns: string Source: includes/bp-anonymous-general-functions.php:282

add_filter( 'bp_anonymous_activity_default_gravatar', function( $html ) {
return '<img src="' . get_stylesheet_directory_uri() . '/images/anon-avatar.png" class="avatar photo" width="150" height="150" alt="" />';
} );

bp_anonymous_activity_default_gravatar_url

Section titled “bp_anonymous_activity_default_gravatar_url”

Filters the anonymous avatar URL string returned by bp_anonymous_activity_default_gravatar( false ).

Parameters:

  • $url (string) — Escaped avatar URL

Returns: string Source: includes/bp-anonymous-general-functions.php:284


bp_anonymous_activity_modify_notification_gravatar

Section titled “bp_anonymous_activity_modify_notification_gravatar”

Filters the avatar URL shown in the BuddyBoss notification panel for notifications that originate from an anonymous activity.

Parameters:

  • $gravatar (string) — Avatar URL
  • $notification (object) — Notification object; use $notification->item_id for the activity ID

Returns: string Source: public/class-bp-anonymous-activities-public.php:845


bp_anonymous_activity_modify_email_subject

Section titled “bp_anonymous_activity_modify_email_subject”

Filters the email subject after the plugin has replaced {{poster.name}} with the anonymous text in emails triggered by an anonymous activity.

Parameters:

  • $subject (string) — Email subject
  • $email (BP_Email) — BuddyPress email object

Returns: string Source: public/class-bp-anonymous-activities-public.php:870

add_filter( 'bp_anonymous_activity_modify_email_subject', function( $subject, $email ) {
return '[Community] ' . $subject;
}, 10, 2 );

bp_anonymous_activity_modify_email_content

Section titled “bp_anonymous_activity_modify_email_content”

Filters the email HTML content after the plugin has replaced the poster name and profile link with the anonymous text.

Parameters:

  • $content (string) — Email HTML body
  • $email (BP_Email) — BuddyPress email object

Returns: string Source: public/class-bp-anonymous-activities-public.php:896


bp_anonymous_activity_modify_email_post_content

Section titled “bp_anonymous_activity_modify_email_post_content”

Filters the user domain (profile URL) resolved by bp_core_get_user_domain. Override if you need to substitute the anonymous author’s link in email content.

Parameters:

  • $domain (string) — User profile URL
  • $user_id (int) — WordPress user ID
  • $nicename (string) — User nicename
  • $user_login (string) — User login

Returns: string Source: public/class-bp-anonymous-activities-public.php:917


Filters the formatted email token array before BuddyPress renders the email. The plugin replaces poster.name with the anonymous text for anonymous activities.

Parameters:

  • $formatted_token (array) — Map of token name to rendered value
  • $token (array) — Raw token map
  • $email (BP_Email) — BuddyPress email object

Returns: array Source: public/class-bp-anonymous-activities-public.php:1046


Filters the raw (pre-render) email token array (BuddyBoss bb_email_set_original_tokens hook).

Parameters:

  • $token (array) — Raw token map
  • $email (BP_Email) — BuddyPress email object

Returns: array Source: public/class-bp-anonymous-activities-public.php:1081


Filters the complete settings array after it is read from get_option( 'bp_anonymous_activity_settings' ) and defaults are applied.

Parameters:

Returns: array Source: includes/bp-anonymous-general-functions.php:51

add_filter( 'bp_anonymous_activity_settings', function( $settings ) {
$settings['anonymous_text'] = 'Mystery Member';
return $settings;
} );

Filters the list of WordPress role slugs that appear in the admin role selector. Useful for hiding custom roles that should never appear in the restriction UI.

Parameters:

  • $roles (array) — Array of role slugs (keys from $wp_roles->roles)

Returns: array Source: includes/bp-anonymous-general-functions.php:391

add_filter( 'bp_anonymous_activity_get_editable_roles', function( $roles ) {
return array_diff( $roles, array( 'shop_manager' ) );
} );

Filters the array of tabs displayed on the plugin’s admin settings page. The default tabs are welcome, general, and faq.

Parameters:

  • $tabs (array) — Associative array of tab_slug => Tab Label

Returns: array Source: admin/class-bp-anonymous-activities-admin.php:195

add_filter( 'bp_anonymous_activity_admin_setting_tabs', function( $tabs ) {
$tabs['my_extra_tab'] = __( 'My Settings', 'my-plugin' );
return $tabs;
} );
// Render content for the new tab
add_action( 'bp_anonymous_activity_tab_contents', function() {
$current = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'welcome'; // phpcs:ignore
if ( 'my_extra_tab' === $current ) {
echo '<div class="wbcom-tab-content">';
// your settings form here
echo '</div>';
}
} );

Filters the $allowed_html array used by wp_kses when printing checkbox output. Extend this if your bp_anonymous_activity_checkbox_html or bp_anonymous_activity_comment_button_html filter adds HTML elements that wp_kses would strip.

Parameters:

  • $tags (array) — wp_kses-style allowed tags array

Returns: array Source: includes/bp-anonymous-general-functions.php:515


Filters the $activities_template object after the plugin rebuilds the activity query to include or exclude anonymous items (e.g. when the activity filter dropdown is set to “Anonymous”).

Parameters:

  • $activities_template (BP_Activity_Template) — The rebuilt template object
  • $template_args (array) — The query args used for the rebuild

Returns: BP_Activity_Template Source: public/class-bp-anonymous-activities-public.php:473


bp_anonymous_activity_get_activity_template

Section titled “bp_anonymous_activity_get_activity_template”

Filters the rebuilt $activities_template object returned by the internal helper function bp_anonymous_activity_get_activity_template(). Use this to modify the activity query result after the plugin has applied its meta query.

Parameters:

  • $activities_template (BP_Activity_Template) — The template object after the plugin’s meta query
  • $template_args (array) — The args passed to BP_Activity_Template

Returns: BP_Activity_Template Source: includes/bp-anonymous-general-functions.php:369


Filters the <option> HTML for the “Anonymous” entry added to the BuddyPress activity type filter dropdown.

Parameters:

  • $option_html (string) — The <option> element HTML

Returns: string Source: public/class-bp-anonymous-activities-public.php:492


bp_anonymous_activity_get_notifications_for_user

Section titled “bp_anonymous_activity_get_notifications_for_user”

Filters the array of renderable notification objects returned to the current user after the plugin has removed notifications whose activity item is anonymous.

Parameters:

  • $notifications (array) — Filtered notification objects
  • $user_id (int) — User ID
  • $format (string) — Format requested ('object' or 'string')

Returns: array Source: public/class-bp-anonymous-activities-public.php:799


Filters the prefix string used when generating the anonymous_slug meta value. Default: 'anon'.

Parameters:

  • $prefix (string) — Slug prefix

Returns: string Source: public/class-bp-anonymous-activities-public.php:256

add_filter( 'bp_anonymous_activity_slug', function( $prefix ) {
return 'ghost';
} );
// Results in slugs like: ghost3f9a2c4b1d

The following priorities are used internally and matter when you need to run before or after the plugin’s own callbacks:

Hook Internal priority Notes
bp_activity_before_save 1 Suppress notification headers before BP processes the activity
bp_activity_after_save (metadata) 1 Write is_anonymous meta as early as possible
bp_activity_after_save (cleanup) 999 Notification cleanup runs last
bp_activity_comment_posted (metadata) 1 Write comment meta early
bp_activity_comment_posted (cleanup) 999 Notification cleanup runs last
bbp_new_topic / bbp_new_reply (notifications) 1 (bbPress), 9 (BuddyBoss) Must run before bbPress or BuddyBoss notification callbacks
bbp_new_topic / bbp_new_reply (meta) 10 Standard priority
bp_get_activity_action (display) 10 Replace author link
bp_get_activity_action (BuddyBoss unique IDs) 999 Run last to catch any remaining author link
bp_notifications_get_notifications_for_user 99 Run after all other notification filters
bp_activity_new_comment_notification_helper 1 Block early, before BuddyBoss sends the notification
Section titled “Recommended priorities for custom callbacks”
// Run BEFORE the plugin's permission check (to add restrictions)
add_filter( 'bp_anonymous_activity_enable', 'my_extra_check', 5 );
// Run AFTER the plugin's permission check (to override the result)
add_filter( 'bp_anonymous_activity_enable', 'my_vip_override', 15 );
// Run as the final decision
add_filter( 'bp_anonymous_activity_enable', 'my_final_gate', 9999 );

// Allow each user at most 3 anonymous activities per day
add_filter( 'bp_anonymous_activity_enable', function( $enabled ) {
if ( ! $enabled ) {
return false;
}
$user_id = get_current_user_id();
$key = 'anon_count_' . $user_id . '_' . gmdate( 'Y-m-d' );
if ( (int) get_transient( $key ) >= 3 ) {
return false;
}
return $enabled;
} );
add_action( 'bp_anonymous_activity_created', function( $activity_id, $activity ) {
$key = 'anon_count_' . $activity->user_id . '_' . gmdate( 'Y-m-d' );
$count = (int) get_transient( $key );
set_transient( $key, $count + 1, DAY_IN_SECONDS );
}, 10, 2 );

add_filter( 'bp_anonymous_activity_change_avatar_image', function( $html, $item ) {
if ( bp_is_group() ) {
$group_id = bp_get_current_group_id();
$custom = groups_get_groupmeta( $group_id, 'anon_avatar_url' );
if ( $custom ) {
return '<img src="' . esc_url( $custom ) . '" class="avatar photo" />';
}
}
return $html;
}, 10, 2 );

add_filter( 'bp_anonymous_activity_default_avatar_image_url', function( $url ) {
return get_stylesheet_directory_uri() . '/images/anonymous.svg';
} );

Previous: Developer Overview | Next: Third-Party Integrations