为多站点配置 BuddyPress

为多站点配置 BuddyPress

Codex Home → Getting Started → Configure BuddyPress for Multisite
Configure BuddyPress for Multisite

After activating BuddyPress, you will be automatically redirected to the BuddyPress Welcome Screen if this is the first time you』ve activated BuddyPress or if you』ve just upgraded BuddyPress. After taking some time to check out the new features added to the plugin, go to Network Admin menu > Settings > Components to begin configuring your installation.

Network Admin > Settings > Components panel
Network Admin > Settings > Pages panel
Network Admin > Settings > Options panel

Network Admin > Settings > Components
By default, BuddyPress Core and the Members components are enabled (Must-Use). Extended Profiles, Account Settings, Activity Streams, Notifications, and Site Tracking components are activated for you.
You can however, selectively disable/enable any of the components later if you so choose by using the same form. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.

Available Components
Each component has a unique purpose, and your community may not need each one.

Extended Profiles
Customize your community with fully editable profile fields that allow your users to describe themselves.
Account Settings
Allow your users to modify their account and notification settings directly from within their profiles.
Friend Connections
Let your users make connections so they can track the activity of others and focus on the people they care about the most.
Private Messaging
Allow your users to talk to each other directly and in private. Not just limited to one-on-one discussions, messages can be sent between any number of members.
Activity Streams
Global, personal, and group activity streams with threaded commenting, direct posting, favoriting and @mentions, all with full RSS feed and email notification support.
User Groups
Groups allow your users to organize themselves into specific public, private or hidden sections with separate activity streams and member listings.
Site Tracking
Record activity for new posts and comments from a single site in your network or from all sites in your network depending on how you configured BuddyPress for your multisite installation. (「Multisite/Network」 is a feature of WordPress which needs to be manually enabled and configured first. Instructions for enabling this can be found at the WordPress codex WP Codex – Create A Network)

Required Components
The following components are required by BuddyPress and cannot be turned off.

BuddyPress Core: It『s what makes [time travel] BuddyPress possible!
Community Members: Everything in a BuddyPress community revolves around its members.

Network Admin > Settings > Pages
BuddyPress components are rendered as WordPress Pages. Make sure that activated components have corresponding pages assigned to each in this panel.

Directories
Associate a WordPress Page with each BuddyPress component directory.

Activity Streams
User Groups (if activated)
Members
Site Tracking (Blogs for Multisite)

Registration
Associate WordPress Pages with the following BuddyPress Registration pages if you want to enable registration.

Register
Activate

Network Admin > Settings > Options

Main Settings

Toolbar: Show the Toolbar for logged out users (default: enabled)
Account Deletion: Allow registered members to delete their own accounts (default: enabled)

Profile Settings

Profile Photo Uploads: Allow registered members to upload avatars (default: enabled)
Cover Image Uploads: Allow registered members to upload cover images (default: enabled)
Profile Syncing: Enable BuddyPress to WordPress profile syncing (default: enabled)

Groups Settings

Group Creation: Enable group creation for all users (default: enabled)
Administrators can always create groups, regardless of this setting.
Group Photo Uploads: Allow customizable avatars for groups (default: enabled)
Group Cover Image Uploads: Allow customizable cover images for groups (default: enabled)

Activity Settings

Blog & Forum Comments: Allow activity stream commenting on blog and forum posts (default: disabled)
Activity Auto Refresh: Automatically check for new items by viewing the activity stream (default: enabled)

适度的活动流

适度的活动流

Codex Home → Administrator Guide → Moderate Activity Streams
Moderate Activity Streams

BuddyPress provides admin dashboard panels to help you manage all the different activities throughout the site, similar to the way you manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on activities using the on-hover action links or the Bulk Actions.
There are many different types of activities. Some are generated automatically by BuddyPress and other plugins, and some are entered directly by a user in the form of status update. To help manage the different activity types, use the filter dropdown box to switch between them.
In the Activity column: above each activity it says 「Submitted on,」 followed by the date and time the activity item was generated on your site. Clicking on the date/time link will take you to that activity on your live site. Hovering over any activity gives you options to reply, edit, spam mark, or delete that activity.
In the In Response To column: if the activity was in reply to another activity, it shows that activity』s author』s picture and name, and a link to that activity on your live site. If there is a small bubble, the number in it shows how many other activities are related to this one; these are usually comments. Clicking the bubble will filter the activity screen to show only related activity items.
Activity Management Screen. Click on image to enlarge.
Sections
General type
Options
All
Spam

Search All Activity form
Bulk Actions (Apply)
Options
Mark As Spam
Not Spam
Delete Permanently

Show All Activity Types (Filter)
Options
Created a group
Friendships accepted
Joined a group
Member changed profile pPicture
New friendships
New group forum post
New group forum topic
New member registered
New post comment posted
New post published
New site created (multisite only)
Posted a status update
Replied to a status update

Pagination
List of Sitewide Activities
Columns Activity Management Screen: Multisite-Network. Click on image to enlarge.
Author: Username and Avatar
Activity: Date and Excerpt of Activity
Options
Reply
Edit
Spam
Delete Permanently

In Response To

View Activity link only (for original posts)
For replies to original posts:
Elements
Original Poster』s Avatar
Original Poster』s Username
View Activity link (of original post)
Comment bubble link with number of related activities to that original post ID => goes to a new Activity Management Screen panel: 「Activity related to ID #__」 with a list of all the activities related to the original post

⇒ Related: Activity Streams – Front End

使用带有 BuddyPress 的 S2member 时的有用功能和技巧

使用带有 BuddyPress 的 S2member 时的有用功能和技巧

Codex Home → Developer Resources → User Submitted Guides → Useful Functions and Hacks When Using S2member w/ BuddyPress
Useful Functions and Hacks When Using S2member w/ BuddyPress

Hey there guys, i』m working on a website where i』m integrating s2member functionality with buddypress. I thought some of the things I』ve come across may be useful to other people.
1. Filter Users Displayed in Members Directory by s2member role.
In your plugins/buddypress/bp-templates/bp-legacy/buddypress/members/ folder edit the file 「members-loop.php」. Just under
at the top 20 lines of the file we need to write some PHP code to build a comma separated list of ID』s based on the s2member role or roles that we want. In my case I wanted only members of 「s2member_level2″.
It is recommended to only ever edit a copy of template file that you have copied over to your theme or child theme otherwise your changes will be overwritten on updates.
$args = array('role' => 's2member_level2', 'fields' => array('id'));
// The User Query
$user_query = new WP_User_Query( $args );
$custom_ids = '';
for($i = 0;$i results); $i++){
$a = $user_query->results[$i]->id;
$custom_ids .= $a.",";
}

Now that we』ve made a comma separated string of ids ($custom_ids), we need to pass it to the members loop.
Change
if(bp_has_members( bp_ajax_querystring( 'members' ) ) ) :
to
if(bp_has_members('per_page=30&type=alphabetical&'.'include='.$custom_ids ) ) :
In my case I wanted to make sure at most 30 members showed up, and that they were in alphabetical order.
Done.
2. Importing s2member custom fields to buddypress fields
You may be asking; why??? Well, it turns out that when you have the s2member option to integrate with buddypress it doesn』t actually import it』d data to the buddypress tables. It just binds it』s self to the 『Base』 group, Which will show up by default in buddypress profiles. When it doesn』t import to the buddypress tables, it was very difficult for me to manipulate how the information showed up. Particularly the fact that I have the users give me their address information, and I don』t want that to even be an option to show in user profiles.
So instead of using s2member to integrate automatically, I wrote a function that would check a users information when they login. If they have certain information in s2member that is not in their BP Profile, it will add it automatically.
Option 1:
in functions.php add the code:
<?php

add_action('wp_head','s2_profile_field_update',10,2);
function s2_profile_field_update() {
global $current_user;
get_currentuserinfo();
if(current_user_is("s2member_level2")){
if(get_user_field("s2member_login_counter") id) == '' && get_user_field('nationality') != '') {
xprofile_set_field_data('Nationality', $current_user->id, get_user_field('nationality'));
}

if(xprofile_get_field_data('Age', $current_user->id) == '' && get_user_field('age') != '') {
xprofile_set_field_data('Age', $current_user->id, get_user_field('age'));
}

if(xprofile_get_field_data('School', $current_user->id) == '' && get_user_field('school') != '') {
xprofile_set_field_data('School', $current_user->id, get_user_field('school'));
}
}
}
}

?>
You can change Nationality to what ever the name is of the extended BP field (in users>profile fields).
And of course you can duplicate the if statements for how every many fields you want to import from s2memeber -> BP.
Also note that if(get_user_field("s2member_login_counter") < 1000) mean』s that this process will run for any user that logs in with membership role s2member_level2 and has logged in less than 1000 times. I used 1000 times because I want any member at this moment who logs in to have their profiles populated. In the future I will drop it down to 1 or 2.
Alternatively we could use a for loop in order to make any later changes a bit simpler:
// Function to populate BP Profile Fields w/ S2member Fields.
add_action('wp_head','s2_profile_field_update',10,2);
function s2_profile_field_update() {
global $current_user;

//Array of xprofile field names
$xprofile_fields = array('Nationality','Age','School');

//Array of s2member field slugs
$s2member_fields = array('nationality','age','school');

get_currentuserinfo();
if( current_user_is("s2member_level2") ) {
if(get_user_field("s2member_login_counter") < 1000)
{
for($i = 0; $i id) == '' && get_user_field($s2member_fields[i]) != '' )
{
xprofile_set_field_data($xprofile_fields[i], $current_user->id, get_user_field($s2member_fields[i]) );
}
}
}
}
}

Option 2: Suggested by @shanebp
Instead of checking for login count, and binding the function to 『wp_head』 which will run on every page load, it would be more resource efficient to bind the function to the 『wp_login』 action which will run once; when the user logs into the site. If you want to get really technical – which the computer engineer in me always does – you could argue that the process has been reduced from a time complexity of O(n) to O(n/n) = O(1) where n = the # of page loads from the user. A simple but substantial modification. Rock On @shanebp!
add_action('wp_login','s2_profile_field_update',10,2);
function s2_profile_field_update()
{
global $current_user;
get_currentuserinfo();
if( current_user_is("s2member_level2") )
{
if(xprofile_get_field_data('Nationality',$current_user->id) == '' && get_user_field('nationality') != '')
{
xprofile_set_field_data('Nationality', $current_user->id, get_user_field('nationality'));
}
}
}
I』ll post more as I gather it. But in the mean time I hope this helps some people.
M

bp_activity_set_action()

bp_activity_set_action()

Codex Home → Developer Resources → Function Examples → bp_activity_set_action()
bp_activity_set_action()

bp_activity_set_action() is used to set activity actions. bp_activity_set_action() should only be invoked through the 『bp_register_activity_actions』 action.
Usage
function custom_plugin_register_activity_actions() {
// Your plugin is creating a custom BuddyPress component
$component_id = 'plugin_component_id';
// You can also use one of the BuddyPress component
// $component_id = buddypress()->activity->id;

bp_activity_set_action(
$component_id,
'plugin_action',
__( 'Did a plugin action', 'plugin-domain' ),
'plugin_format_activity_action_plugin_action',
__( 'Plugin actions', 'plugin-domain' ),
array( 'member' )
);
}
add_action( 'bp_register_activity_actions', 'custom_plugin_register_activity_actions' );

Parameters

$component_id

The unique string ID of the component the activity action is attached to. Possible values can be one of the BuddyPress optional components or an optional component the plugin is creating :

'activity'
'blogs'
'friends'
'groups'
'members'
'xprofile'
'plugin_component'

$type

A string that describes the action type and that is used in the front-end and in the Activity Administration screens as the value of the activity dropdown filters. For instance the Activity component has two actions :

'activity_update'
'activity_comment'

$description

A string that describes the action description and that is used in the Activity Administration screens as the label of the activity dropdown filters. For instance the corresponding descriptions of the two action types of the Activity component are :

__( 'Posted a status update', 'buddypress' )
__( 'Replied to a status update', 'buddypress' )

$format_callback

A callable function for formatting the action string. For instance the corresponding callback functions of the two action types of the Activity component are :

'bp_activity_format_activity_action_activity_update'
'bp_activity_format_activity_action_activity_comment'

$label

A string that describes the action label of the activity front-end dropdown filters. For instance the corresponding labels of the two action types of the Activity component are :

__( 'Updates', 'buddypress' )
__( 'Activity Comments', 'buddypress' )

$context

An optional array that describes the Activity stream contexts where the filter should appear. Possible values are :

'activity': to display the action into the dropdown filters of the Activity directory.
'member': to display the action into the dropdown filters of the Member』s activity page (by default the home page).
'member_groups': to display the action into the dropdown filters of the Member』s groups activity page.
'group': to display the action into the dropdown filters of the group』s activity page (by default the home page).

$position

An optional integer that describes the position of the action when listed in dropdown filters. Actions are first sorted by their attached components. This argument will sort the list of actions for each component.

Return value
Boolean: true on success, false otherwise.
Source File
bp_activity_set_action() is located in bp-activity/bp-activity-functions.php
Change Log

2.2.0: It will be possible to sort the activity actions within their attached component.
2.1.0: Activity dropdown filters are dynamically generated instead of hardcoded into templates. See function bp_activity_show_filters()
2.0.0: activity action strings are generated dynamically, rather than stored statically. This means that the data is always up-to-date for a better compatibility with multilingual sites
Since 1.1.0

Notes
Since BuddyPress 2.1.0 custom templates or BuddyPress themes can use the function bp_activity_show_filters() instead of hardcoding the options into the following templates :

activityindex.php: use
groupssingleactivity.php: use
memberssingleactivity.php: use

模板中的活动下拉过滤器

模板中的活动下拉过滤器

Codex Home → BuddyPress Theme Development → Activity dropdown filters in templates
Activity dropdown filters in templates

Activity dropdown filters are used in order to let a user filter the activity stream in three main contexts: the activity directory, the single member activity page and the single group activity page.
The Activity directory dropdown filters.

Version 2.1 of BuddyPress introduced the template tag bp_activity_show_filters() to dynamically generate the options of the activity dropdown filters. While the BP Theme compatibility templates are using this function, the BP-Default templates are not since Core Team has decided that no further development on the theme template files will be made. The goal of this article is to show you how you can enjoy this new template tag within your BP-Default child theme.
Use bp_activity_show_filters() within your BP-Default child theme
The three templates that are containing an activity dropdown filters are:

Activity directory: activity/index.php
Single Member activity page: members/single/activity.php
Single Group activity page: groups/single/activity.php

Let』s look at the activity directory template, focusing on the select tag having the css id 「activity-filter-by」:

As you can see, this part is checking if the component is active before displaying its actions which are then hardcoded in the template. If you are using, at least, BuddyPress 2.1 you can edit the templates to use the template tag bp_activity_show_filters() instead of the hardcoded options (except for the first one). Once done, the activity/index.php and members/single/activity.php will have a select tag looking like this:

For the groups/single/activity.php template, the only difference is that the bp_activity_show_filters() template tag is including a context parameter set to 『group』 like this:

Why using bp_activity_show_filters() within your theme』s templates
As soon as you are using at least version 2.1 of BuddyPress, you should consider using this new template tag as it will be used by BuddyPress to create new activity actions for its current (and future) components. BuddyPress plugins might also progressively rely on this template tag as setting activity actions have been greatly improved thanks to the function bp_activity_set_action().

Related Resources

bp_activity_set_action() codex page
Posting activities from plugins, section 「Fully enjoy bp_activity_set_action()」

文章类型活动

文章类型活动

Codex Home → BuddyPress Plugin Development → Post Types Activities
Post Types Activities

Note: This guide is for use with BuddyPress 2.2+.
Any public registered post type can be tracked into the activity streams once it has been published. Here are the different options to add the 「buddypress-activity」 support to a public post type.

Activate the Blogs component ( aka Site Tracking )
If you activate the Site Tracking component from the BuddyPress component』s Administration screen, the post post type will automatically have the 「buddypress-activity」 feature enable. Comments about this post type will also generate activities or, if you chose to 「allow the activity stream commenting on blog posts」 from the BuddyPress settings Administration screen, comments will be synchronized with the activity stream.
Use add_post_type_support( 『post_type』, 『buddypress-activity』 )
From your bp-custom.php file, you can also manually set a post type to be tracked into the activity stream. For instance, for the page post type you could use this code:
add_post_type_support( 'page', 'buddypress-activity' );

In this case, BuddyPress will set an activity action using generic activity attributes : the component, the generated activities will be attached to, will be the Activity component; the action type will be the post type』s name prefixed by the mention 『new_』 (in our example 『new_page』); the label of the front-end activity dropdown filters will be the name parameter of the 『labels』 argument of the post type (in our example 『Pages』); the label of the Activity Administration screens dropdown filters will be __( 'New item published', 'buddypress' ); the action string will be __( '%1$s wrote a new item', 'buddypress' ) where %1$s will be replaced by the member』s link of the post type』s author and %2$s by the url to the post type; the context will be limited to the Activity directory; commenting on generated activities about the post type will be possible if the post type is not supporting comments.
Simply by using add_post_type_support()
Customizing generic activity attributes
You can edit the generic activity attributes of a post type from your bp-custom.php file using the function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array() ). Use the first parameter to inform about the post type you wish to edit the activity attributes of. The second parameter is an associative array containing the activity attributes to edit. For instance you could use this code:
// Don't forget to add the 'buddypress-activity' support!
add_post_type_support( 'page', 'buddypress-activity' );

function customize_page_tracking_args() {
// Check if the Activity component is active before using it.
if ( ! bp_is_active( 'activity' ) ) {
return;
}

bp_activity_set_post_type_tracking_args( 'page', array(
'component_id' => buddypress()->blogs->id,
'action_id' => 'new_blog_page',
'bp_activity_admin_filter' => __( 'Published a new page', 'custom-domain' ),
'bp_activity_front_filter' => __( 'Pages', 'custom-domain' ),
'contexts' => array( 'activity', 'member' ),
'activity_comment' => true,
'bp_activity_new_post' => __( '%1$s posted a new page', 'custom-textdomain' ),
'bp_activity_new_post_ms' => __( '%1$s posted a new page, on the site %3$s', 'custom-textdomain' ),
'position' => 100,
) );
}
add_action( 'bp_init', 'customize_page_tracking_args' );

Using add_post_type_support() and customizing activity attributes.
Below a description of the parameters used above:

$component_id
The unique string ID of the component the activity action is attached to, defaults to 『activity』
$action_id
A string that describes the action type and that is used in the front-end and in the Activity Administration screens as the value of the activity dropdown filters, defaults to 『new_{post_type_name}』
$bp_activity_admin_filter
A string that describes the action description and that is used in the Activity Administration screens as the label of the activity dropdown filters.
$bp_activity_front_filter
A string that describes the action label of the activity front-end dropdown filters.
$contexts
An array that describes the Activity stream contexts where the filter should appear. Possible values are 『activity』, 『member』, 『member_groups』, 『group』.
$activity_comment
A boolean to allow/disallow comments on the activity items. Defaults to true if the post type does not natively support comments, otherwise false.
$bp_activity_new_post
A string containing the custom action string to use for regular configs. Defaults to __( '%1$s wrote a new item', 'buddypress' )
$bp_activity_new_post_ms
A string containing the custom action string to use for multisite configs. Defaults to __( '%1$s wrote a new item, on the site %3$s', 'buddypress' )
$position
An integer to set the order of the action within the component』s actions

Adding the 「buddypress-support」 and specific labels at post type registration
When registering a post type in WordPress it』s also possible to set the 『buddypress-activity』 feature using the support parameter of the second argument of the register_post_type() function. Custom activity action strings can be defined within the labels parameter and activity attributes can be set using the parameter 『bp_activity』. See below for an example of use.
function plugin_registers_post_type() {
$args = array(
'public' => true,
'labels' => array(
'name' => __( 'Books', 'your-plugin-textdomain' ),
'singular_name' => __( 'Book', 'your-plugin-textdomain' ),
'bp_activity_admin_filter' => __( 'New book published', 'your-plugin-textdomain' ),
'bp_activity_front_filter' => __( 'Books', 'your-plugin-textdomain' ),
'bp_activity_new_post' => __( '%1$s posted a new book', 'your-plugin-textdomain' ),
'bp_activity_new_post_ms' => __( '%1$s posted a new book, on the site %3$s', 'your-plugin-textdomain' ),
),
'supports' => array( 'title', 'editor', 'buddypress-activity' ),
'bp_activity' => array(
'component_id' => buddypress()->activity->id,
'action_id' => 'new_book',
'contexts' => array( 'activity', 'member' ),
'position' => 40,
),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'plugin_registers_post_type' );

Important note: public parameter should be defined and set to true, otherwise the connection between post type and Activity component won』t be established.
Customizing Post Type Activity Content
You can customize the activity action of a Post Type via the register_post_type() example above. If you want to customize the Post Type activity content you can filter bp_before_activity_add_parse_args or bp_after_activity_add_parse_args.
function record_cpt_activity_content( $cpt ) {

if ( 'new_book' === $cpt['type'] ) {

$cpt['content'] = 'what you need';
}

return $cpt;
}
add_filter('bp_before_activity_add_parse_args', 'record_cpt_activity_content');

Tracking comments about a Post Type
Version 2.5 is bringing Post Type comments tracking into the Activity stream for the Post Types supporting the 'comments' and the 'buddypress-activity' features. You can set the comments tracking feature to an existing Post Type or during the Post Type registration by adding the 'comment_action_id' specific parameter. If you wish to customize dropdown filter labels and action strings, you simply need to define some extra parameters. Here is the list of the available parameters :

$comment_action_id
A string that describes the action type and that is used in the front-end and in the Activity Administration screens as the value of the activity dropdown filters
$bp_activity_comments_admin_filter
A string that describes the action description and that is used in the Activity Administration screens as the label of the activity dropdown filters.
$bp_activity_comments_front_filter
A string that describes the action label of the activity front-end dropdown filters.
$bp_activity_new_comment
A string containing the custom action string to use for regular configs. Defaults to __( '%1$s commented on the item', 'buddypress' )
$bp_activity_new_comment_ms
A string containing the custom action string to use for multisite configs. Defaults to __( '%1$s commented on the item, on the site %3$s', 'buddypress' )

1. Add comments tracking to an Existing Post Type
Below is an example of code to put into your bp-custom.php file to add the comments tracking feature to the 「page」 Post Type.
function customize_page_tracking_args() {
// Check if the Activity component is active before using it.
if ( ! bp_is_active( 'activity' ) ) {
return;
}

// Don't forget to add the 'buddypress-activity' support!
add_post_type_support( 'page', 'buddypress-activity' );

/**
* Also don't forget to allow comments from the WordPress Edit Page screen
* see this screencap https://cldup.com/nsl4TxBV_j.png
*/

bp_activity_set_post_type_tracking_args( 'page', array(
'action_id' => 'new_blog_page',
'bp_activity_admin_filter' => __( 'Published a new page', 'custom-textdomain' ),
'bp_activity_front_filter' => __( 'Page', 'custom-textdomain' ),
'bp_activity_new_post' => __( '%1$s posted a new page', 'custom-textdomain' ),
'bp_activity_new_post_ms' => __( '%1$s posted a new page, on the site %3$s', 'custom-textdomain' ),
'contexts' => array( 'activity', 'member' ),
'comment_action_id' => 'new_blog_page_comment',
'bp_activity_comments_admin_filter' => __( 'Commented a page', 'custom-textdomain' ),
'bp_activity_comments_front_filter' => __( 'Pages Comments', 'custom-textdomain' ),
'bp_activity_new_comment' => __( '%1$s commented on the page', 'custom-textdomain' ),
'bp_activity_new_comment_ms' => __( '%1$s commented on the page, on the site %3$s', 'custom-textdomain' ),
'position' => 100,
) );
}
add_action( 'bp_init', 'customize_page_tracking_args' );

2. Add comments tracking feature during the Post Type registration
Below is an example of code to put into your bp-custom.php file to registyer a 「foo」 Post Type and directly set the 'buddypress-activity' and 'comments' supports during this registration.
$labels = array(
'name' => 'foos',
'singular_name' => 'foo',
'bp_activity_comments_admin_filter' => __( 'Comments about foos', 'custom-textdomain' ), // label for the Admin dropdown filter
'bp_activity_comments_front_filter' => __( 'Foo Comments', 'custom-textdomain' ), // label for the Front dropdown filter
'bp_activity_new_comment' => __( '%1$s commented on the foo', 'custom-textdomain' ),
'bp_activity_new_comment_ms' => __( '%1$s commented on the foo, on the site %3$s', 'custom-textdomain' )
);

register_post_type( 'foo', array(
'labels' => $labels,
'public' => true,
'supports' => array( 'buddypress-activity', 'comments' ), // Adding the comments support
'bp_activity' => array(
'action_id' => 'new_foo', // The activity type for posts
'comment_action_id' => 'new_foo_comment', // The activity type for comments
),
) );

Notes
On multisite configurations, the post types that are registered on any sub-site will need to be registered on the root site in order to be listed in the Activity dropdown filters. That』s the case for the post and page post types
Some of you may have used the 'bp_blogs_record_post_post_types' filter to include custom post types to the site tracking having the Blogs component activated. These post types will keep on being included as long as the Blogs component is active.
About Post Type comments tracking: if the Blogs component (Site Tracking) is active and if the 「Allow activity stream commenting on blog and forum posts」 setting is checked, comments about the Post Type will be synchronized with the activity comments about the corresponding Post Type activity.

Related Resources

register_post_type() WordPress Codex page
Posting activities from plugins
Activity dropdown filters in templates
More details and explanation in this topic
More details and possible field values on bp_activity_set_action() page