Disallowing Activity recording for components or some activity types in BuddyPress

In BuddyPress, we have an action hook "bp_activity_before_save" that allows us to work with the activity object before it is saved in the database. The good thing is, After this hook is fired, BuddyPress checks for the component and type, and if any of these two is not set, BuddyPress will not record activity.

How do you stop recording activity:-

You hook to "bp_activity_before_save" and reset either component or type on the passed activity object.

Example 1:- Disallowing activity for certain component(s)

In this example, we will disallow recording of any activity related to groups component.

That will stop BuddyPress from recording any group activity. You can modify the code to disallow multiple components to change the component.

Example 2:- Stop recording activity for certain activity types

In BuddyPress, each activity has certain type associated with it. A few example of types will be updated_profile, new_avatar, created_group, joined_group, group_details_updated, friendship_created.

In this example, we will be asking BuddyPress to not record activity when a profile is updated or user joins a group. Our types are "joined_group" and "updated_profile"

You should put the code in your bp-custom.php and you will be good to go.

That's all for today folks. Good-bye until next time.

4 Responses to Disallowing Activity recording for components or some activity types in BuddyPress

  • Thanks for this Brajesh,
    This has proved to be very useful, Helps to keep the clutter from the activity page.

  • Where can I get all the available activity types?

    • Please try running this against your BuddyPress database

      SELECT DISTINCT(type) FROM wp_bp_activity

      You may need to change the table prefix though bade on your installation.