群组 (Groups)

群组 (Groups)

Codex Home → Administrator Guide → Groups
Groups

Groups in BuddyPress are gatherings of members, posts, and any other user-generated content. A member can create a group in BuddyPress (if enabled by Super/Site Admin) and thus becomes the group administrator. Every group includes a Status Update form for members and the latest group news which can be kept up to date by group admins. Group admins can also approve requests to join the private group, invite friends to congregate within a hidden group, establish communications among members, extend privileges to other members, and enable new features (Group Forums if enabled by Super Admin) within the group, among others.
Sections

Groups Directory
Single Group

Group Header
Activity (group home page)
Members
Send Invites
Admin

Groups Directory
Groups Directory Page. Click on image to enlarge.
Sections
Create a Group button/link – Shown beside the Groups page title to logged in member if the Site/Super Admin has enabled group creation by members.
Search Groups search form
All Groups – with total number of registered users who have logged in at least once after BuddyPress was activated in the installation.
Selectbox – Show: Last Active (default), Most Members, Newly Created, or Alphabetical
List of Groups created in the site including time active stamp, group description, number of members and group privacy setting. Only Public and Private Groups are seen in list by regular members. Super/Site Admin sees all groups including Hidden groups.
Action buttons – for logged in members only
Join Group button – for groups listed as Public, button visible to logged in members only.
Request Membership button – for groups listed as Private, button is visible to logged in members only.
( Membership in Hidden groups is by invitation only.)

My Groups – for logged in users only. This includes a counter of the total number of groups you have created and/or joined in
Options
Selectbox – Show: Last Active (default), Most Members, Newly Created, or Alphabetical
List of Groups you are a member of – Public, Private and Hidden (only by you and Super Admin)
Leave Group button – visible to logged in members of Public, Private and Hidden Groups. You cannot leave the group if you are the only Group Admin.

Single Group Header
Single Group Header. Click on image to enlarge.
Sections
Group Avatar or Site Default Avatar
Group Name
Group Description
Group Admin/s with avatar/s
Group Mod/s (if any) with avatar/s
Join Group button (for a Public group) or Request Membership button (for a Private Group) or Leave Group button (for Public, Private or Hidden Group)

Home Page
The Group』s Activity Stream is the default Home tab for any group.
Sections
RSS feed
Selectbox: Show: Everything (default), Updates, Group Memberships
Status Update – visible to all logged in group members only
Options
Text Area box
Post In – Selectbox: Member』s Profile Page or to one of Membes』s Groups
Post Update button

List of Group activities. Following buttons/links are visible to logged in group members only
Options
Comment button
Reply to Comment link
Favorite button or Remove Favorite button
Delete button – visible only to Group Admin, Group Moderator and Super/Site Admin.

Members
List of Group Members
Sections
Member Avatar
Member Nice Name
Member Active Since
Action buttons
Options
Add Friend (friendship request) button – visible to logged in group members
Cancel Friendship Request button – visible to the group member who made the friendship request
Cancel Friendship button – visible to the group member whose friendship request was accepted
Favorite button or Remove Favorite button

Send Invites
Visibility of Send Invites link to members or Group Mod/s is dependent on what option the Group Admin chose in Admin > Settings > Group Invitations: All group Members, Group Admins and Mods only, or Group admins only.
Options
Info: Select people to invite from your friends list.
List of your friends with checkbox beside each name is shown in panel.
Select friend and the friend is automatically listed in invite list.
Remove Invite button – click to remove friend/s from list prior to sending invitation
Send Invites button – click to send invitation/notification to one or group of friend/s

Admin
Tab/link is visible only to Group Admin and Super/Site Admin
Sections
Details
Options
Group Name (required) text area
Group Description (required) text area
Notify group members of changes via email – Yes or No option
Save Changes button

Settings
Group Admin Settings Panel. Click on image to enlarge
Privacy Options – Group Admin selects from among three options (About Group Privacy Options)
Options
This is a public group
Options
Any site member can join this group.
This group will be listed in the groups directory and in search results.
Group content and activity will be visible to any site member.

This is a private group
Options
Only users who request membership and are accepted can join the group.
This group will be listed in the groups directory and in search results.
Group content and activity will only be visible to members of the group.

This is a hidden group
Options
Only users who are invited can join the group.
This group will not be listed in the groups directory or search results.
Group content and activity will only be visible to members of the group.

Group Invitations – select which members of this group are allowed to invite others?
Options
All group members
Group admins and mods only
Group admins only

Save Changes button

Avatar
Options
Upload an image to use as an avatar for this group. The image will be shown on the main group page, and in search results.- .jpg, .gif or .png format

Choose File button (no file chosen)
Upload Image button

If you』d like to remove the existing avatar but not upload a new one, please use the delete avatar button.

Delete Avatar button

Members
Group Admin > Members (group roles). Click to enlarge.

List of members according to member』s role in group – visible to Group Admin and Super/Site Admin only. (About Group Roles).

Administrator/s – If there』s only one Group Admin, there will be no button to demote or remove the user as there must always be a group admin position.
Option
Demote to Member button – Shows up only if there』s more than one Group Admin

Moderator/s
Options
Promote to Admin button
Demote to Member button

Member/s
Options
Kick & Ban button
Promote to Mod button
Promote to Admin button
Remove from Group button

Delete

WARNING: Deleting this group will completely remove ALL content associated with it. There is no way back, please be careful with this option.
Checkbox: I understand the consequences of deleting this group.
Delete Group button

Groups Management Panels
Groups Dashboard Admin. Click on image to enlarge.
BuddyPress provides admin dashboard panels to help you manage the Groups created in your site, including membership and settings(added in BuddyPress 1.7).
Sections
General Type
Options
All
Public
Private
Hidden

Bulk Actions: Delete (Apply) Groups Network-Multisite Admin Dashboard. Click on image to enlarge.
Search All Groups form
Pagination
List of All Groups
Columns
Name: Avatar and Group Name
Options
Visit: Goes to Group』s home page in the front end of the site
Edit: Opens up a new Group Management panel in dashboard to edit the Group
SectionsEdit Group panel. Click on image to enlarge.
Name and Description
Inputs
Name of Group
Text area for Description of Group

Add New Members
Input
Start typing a username to add a member

Manage Members
Types
Administrators
Columns
ID: User ID Number
Name: Avatar and Username which link to the Member』s Activity > Personal page in frontend
Group Role
Selectbox
Administrator (default)
Moderator
Member
Banned
Remove from Group (Member cannot be removed if said member is the only Group Administrator)

Moderators: Either 「No members of this type」 if there is no Group Mod or
Columns
ID: User ID Number
Name: Avatar and Username which link to the Member』s Activity > Personal page in frontend
Group Role
Selectbox
Administrator
Moderator (default)
Member
Banned
Remove from Group

Members: Either 「No members of this type」 if there are no members yet or
Columns
ID: User ID Number
Name: Avatar and Username which link to the Member』s Activity > Personal page in frontend
Group Role
Selectbox
Administrator
Moderator
Member (default)
Banned
Remove from Group

Banned Users Either 「No members of this type」 if there is no banned user or
Columns
ID: User ID Number
Name: Avatar and Username which link to the Member』s Activity > Personal page in frontend
Group Role
Selectbox
Administrator
Moderator
Member
Banned (default)
Remove from Group

Save
Options
Delete Group link
Save Changes button

Settings
Elements
Checkbox: Enable discussion forum (if bbPress plugin is activated and Group Forums are enabled in bbPress Settings page)
Privacy
Options
Public (default)
Private
Hidden

Who can invite others to this group?
Options
All group members (default)
Group admins and mods only
Group admins only

Delete: Opens up the Delete Groups panel in dashboard
Elements Delete Group/s panel in dashboard.
You are about to delete the following groups:
List of Group/s to be deleted
This action cannot be undone. (warning)
Delete Permanently button or Cancel button

Description
Status: Private, Public or Hidden
#Members: Number of members and Sorting of groups by number of members
Last Active: Date and Time

安装群组和全站点论坛

安装群组和全站点论坛

Codex Home → Getting Started → Installing Group and Sitewide Forums
Installing Group and Sitewide Forums

For New Installations:
The following is a step-by-step guide for installing the Group and/or Sitewide Forums  for the latest BuddyPress and bbPress plugins.
Forums Setup
Forums in BuddyPress make use of the bbPress software to function and we made it easy for you to install from the wp-admin backend with a few clicks. Depending on your community』s requirements, you can choose to:

Set up Sitewide Forums only
Set up Group and Sitewide Forums
Set up Group Forums only

Forums FAQ』s (Frequently Asked Questions)
What』s the difference between Forums for Groups and Sitewide Forums?
Forums for Groups
Give each individual group its own discussion forum. Choose this if you』d like to keep your members』 conversations separated into distinct areas. bbPress Forums for Groups in BuddyPress are fully integrated and attached to Groups. The Group Admin has to enable the forum feature in the Group』s admin panel first.
Features:

Group Integration
Member Profile Integration
Activity Stream Integration
Forum Plugins Available
@ Mention Integration

Site Wide Forums
Your site will have forums that are not isolated to any specific group. Choose this if you』d like to have a central forum area for your members.
Features:

Central Discussion Area
Member Profile Integration
Forum Plugins Available
Activity Stream Integration
@ Mention Integration

From hereon forward, you』ll be using the bbPress plugin to set up your Group and/or Sitewide Forums.
A. Set Up Sitewide Forums only

Install and activate bbPress.
Proceed to bbPress.org Codex to get started in creating your Sitewide Forums.
If you kept the default 「forums」 slug in Settings > Forums, you can create a new Page via Pages > Add New. Add Title 「Forums」 and insert the forums index shortcode and/or other bbPress shortcode you』ll find in the bbPress Codex then publish the new page.
Add new 「Forums」 Page in your custom menu via Appearances > Menu.

B. Set Up Group and Sitewide Forums

Install and activate bbPress.
Proceed to bbPress.org Codex to get started in creating your Sitewide Forums.
If you kept the default 「forums」 slug in Settings > Forums, you can create a new Page via Pages > Add New.
Add Title 「Forums」 and insert the forums index shortcode and/or other bbPress shortcode you』ll find in the bbPress Codex.
Publish the new page.
Add new 「Forums」 Page in your custom menu via Appearances > Menu.
Create a new Forum as the 「parent forum」 for all of your Group Forums.

Go to Forums > New Forum
Add Title, e.g. Group Forums
Change Forum Attribute Type from 「Forum」 to 「Category」

Add Page Order, e.g. 100 – positioning Group Forums near bottom of Sitewide Forums. Leave it at default 「0」 if you want it to show up above all other forums. Or adjust Page Order as necessary.
Click on Publish button.

Set up BuddyPress Group Forums in bbPress Settings

Go to Settings > Forums and scroll down to the BuddyPress section
Enable Group Forums – make sure it』s checked
Group Forums Parent – select 「Group Forums」 created in #2 above or whatever you chose to name the Forum
Save Settings

Create a Group and set up Group』s Forum

Go to your site』s Group』s Directory Page and click on create Group button.
Go through the group creation process. In Step 3, check 「Yes, I want this group to have a forum.」
Continue through and finish the group creation process.
The 「Forum」 link is now visible in the Group』s main navigation and you and your members can now create new topics for your group』s forums.

C. Set Up Group Forums Only

Install and activate bbPress.
Go to admin dashboard menu Forums > New Forum

Add Title, e.g. Group Forums
Change Forum Attribute Type from 「Forum」 to 「Category」
Click on Publish button.

Go to admin dashboard menu Settings > Forums to configure Forum Settings

BuddyPress -> Enable Group Forums: Check 「Allow BuddyPress Groups to have their own forums」
BuddyPress -> Group Forums Parent: Select 「Group Forums」 category forum created in previous step.
Click on Save button.

Create a Group and set up Group』s Forum

Go to your site』s Group』s Directory Page and click on create Group button.
Go through the group creation process. In Step 3, check 「Yes, I want this group to have a forum.」
Continue through and finish the group creation process.
The 「Forum」 link is now visible in the Group』s main navigation and you and your members can now create new topics for your group』s forums.

D. Forums: Frequently Asked Questions
How can I migrate my Group Forums to the Sitewide Forums?
Please see the main article Migrating from old forums to bbPress 2.2+.
I installed this cool bbPress add-on plugin. Will it work with the Group Forums I set up with bbPress?
Yes.

? Getting Started

主题兼容性 - 自定义

主题兼容性 - 自定义

Codex Home → BuddyPress Theme Development → Theme Compatibility → Theme Compatibility – Customizing
Theme Compatibility – Customizing

BuddyPress 1.7 has built-in theme support. All required elements such as front-end editing are included. This means that all functionality will work, even when a theme has no specific BuddyPress templates or code included with it.
To customize BuddyPress:
The directory wp-content/plugins/buddypress/bp-templates/bp-legacy/ contains the directories buddypress, css and js, and the file buddypress-functions.php.

buddypress contains template files; copy any you want to modify into a directory named buddypress in your theme』s root. eg. /wp-content/themes/mytheme/buddypress/
css contains style sheets; copy any you want to modify into a directory named css in your theme』s root. eg. /wp-content/themes/mytheme/css/

Edit the new files for complete control over BuddyPress display in your theme.
Don』t need theme compatibility?
If you are using a theme that was built for an earlier version of BuddyPress, then your theme already supports BuddyPress and you won』t need BP』s theme compatibility. Your theme can tell BuddyPress not to load the theme compat layer by putting the following line in functions.php:
add_theme_support( 'buddypress' );
For more details, see this post on the BP development blog.

注册和激活页面

注册和激活页面

Codex Home → Getting Started → Register and Activation Pages
Register and Activation Pages

BuddyPress 1.7 auto generates the component pages for you. However, if you have open registration off in the WordPress general settings these pages may not get auto created.
Enable Registration
For users to sign up to your new BuddyPress powered site you will need to enable registration.  Visit  Settings > General in the WordPress admin and make sure you have 「anyone can register」 checked.

For multisite/network installations, navigate to 「My Sites > Network Admin > Settings」 then choose either of the following registration settings available:

Registration is disabled. (default)
User accounts may be registered.
Logged in users may register new sites.
Both sites and user accounts may be registered.

Assign the Pages
After you have enabled registration, you can create the required pages and assign them to the register and activation components. Visit Settings > BuddyPress and then click the Pages tab.

⇐ Getting Started

bp_after_setup_theme()

bp_after_setup_theme()

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

bp_after_setup_theme() is where BuddyPress loads the theme functions. If you want to filter actions in functions.php or buddypress-functions.php hook to bp_after_setup_theme().
add_action( 'bp_after_setup_theme', 'bp_load_theme_functions', 1 );

Source File
bp_after_setup_theme() is located in bp-core/bp-core-dependency.php

在插件中使用 BP Theme Compat

在插件中使用 BP Theme Compat

Codex Home → BuddyPress Plugin Development → Using BP Theme Compat in Plugins
Using BP Theme Compat in Plugins

A BuddyPress plugin can need to display content in several areas of a BuddyPress powered community :

In its own directory
In the member』s profile pages
In groups

The goal of this tutorial is to show you a way to take benefit of the magic that will be introduced in the next major release of BuddyPress (version 1.7) to maximize theme compatibility for BuddyPress content and for the content generated by your plugin.
In Plugin』s main directory.
When using the BP_Component class, we can specify that our plugin will have its own directory area. Here』s a quick reminder :
class BP_Plugin_Component extends BP_Component {

function __construct() {}
function includes() {
// Files to include
$includes = array(
/* some files */
'includes/bp-plugin-screen.php',
/*some other files */
);

parent::includes( $includes );
}

function setup_globals() {
$globals = array(
'slug' => 'some-slug',
'root_slug' => 'some-root-slug',
/* has_directory is set to true in order to setup plugin's main directory */
'has_directory' => true,
'notification_callback' => 'function_to_format_notification',
/* etc... */
);

parent::setup_globals( $globals );
}

function setup_nav() {}
function setup_admin_bar() {}
}

function bp_plugin_load_core_component() {
global $bp;

$bp->bp_plugin = new BP_Plugin_Component;
}
add_action( 'bp_loaded', 'bp_plugin_load_core_component' );

In this example, i』m using the file bp-plugin-screen.php in order to hold all the functions that will allow us to set the needed template for our plugin』s main directory.
So far, in order to indicate to BuddyPress the path to my plugin』s template, i used to filter the bp_located_template hook :

function bp_plugin_load_template_filter( $found_template, $templates ) {

//Only filter the template location when we're on the bp-plugin component pages.
if ( !bp_is_current_component( 'bp-plugin' ) )
return $found_template;

foreach ( (array) $templates as $template ) {
if ( file_exists( STYLESHEETPATH . '/' . $template ) )
$filtered_templates[] = STYLESHEETPATH . '/' . $template;
elseif( file_exists( TEMPLATEPATH . '/' . $template ) )
$filtered_templates[] = TEMPLATEPATH . '/' . $template;
else
$filtered_templates[] = BP_PLUGIN_DIR . '/templates/' . $template;
}

$found_template = $filtered_templates[0];

return apply_filters( 'bp_plugin_load_template_filter', $found_template );
}

add_filter( 'bp_located_template', 'bp_plugin_load_template_filter', 10, 2 );

We first check for our template file in the active theme or in the parent theme, and if nothing was found, we add to the templates array the path to our plugin template folder. Doing so, we allow themes to 「override」 and adapt the template to their design.
This done, in order to tell to BuddyPress to load the required template for my root plugin directory i filter the hook 『bp_screens『 :
function bp_plugin_screen_index() {
// i first check i'm on my plugin directory area...
if ( !bp_displayed_user_id() && bp_is_current_component( 'bp-plugin' ) && !bp_current_action() ) {
bp_update_is_directory( true, 'bp-plugin' );

//... before using bp_core_load_template to ask BuddyPress
// to load the template bp-plugin (which is located in
// BP_PLUGIN_DIR . '/templates/bp-plugin.php)
bp_core_load_template( apply_filters( 'bp_plugin_screen_index', 'bp-plugin' ) );
}
}
add_action( 'bp_screens', 'bp_plugin_screen_index' );

As you can see, when BuddyPress will run the function bp_core_load_template, which is located at line 346 of the /bp-core/bp-core-catchuri.php file (in BuddyPress 1.7-beta1), as soon as it meets the 『bp_located_template『 filter, my function 『bp_plugin_load_template_filter』 will step in to add my plugin template path. This is made possible thanks to line 379 of this file :
// Filter the template locations so that plugins can alter where they are located
$located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates );

In BuddyPress 1.7, this method is still working fine as soon as the community administrator is using the bundled BP Default theme or a child of it. But, if he decides to enjoy the 「BP Theme Compat」 great new feature in order to use any WordPress theme, then the content generated by our plugin will not display the best way.
To maximize this, we need to use the new hook introduced in the 1.7 version : do_action(『bp_setup_theme_compat』) which is located at line 410 of the bp_core_load_template function.
Actually, if BuddyPress haven』t found the required template then this hook is finally fired. Unlike what we』ve done just above, the funny part of this tutorial is that we first won』t tell BuddyPress what template to load if the active theme is not BP Default or a child of it.
In order to check if BP Default, or a child of it, or an eventual BuddyPress theme that is not relying on BP Default is active on the blog, i use this function :
function bp_plugin_is_bp_default() {
// if active theme is BP Default or a child theme, then we return true
// If the Buddypress version is < 1.7, then return true too
if(current_theme_supports('buddypress') || in_array( 'bp-default', array( get_stylesheet(), get_template() ) )  || ( defined( 'BP_VERSION' ) && version_compare( BP_VERSION, '1.7', ' 0,
'post_title' => 'BP Plugin Directory',
'post_author' => 0,
'post_date' => 0,
'post_content' => '',
'post_type' => 'bp_plugin',
'post_status' => 'publish',
'is_archive' => true,
'comment_status' => 'closed'
) );
}
/**
* Filter the_content with bp-plugin index template part
*/
public function directory_content() {
bp_buffer_template_part( 'bp-plugin' );
}
}

new BP_Plugin_Theme_Compat ();

Thanks to this step, we just made sure that BuddyPress will look for the bp-plugin template in the WordPress Theme or in the BP Legacy templates before trying to load it.
However, unless the active theme thought about adding this template, it won』t find it as it won』t check our plugin』s templates folder. We need to reference our plugin template folder first.
To do so, we can add a filter on the 「bp_get_template_stack」 hook in order to store our plugin path into the BuddyPress template paths :
function bp_plugin_add_template_stack( $templates ) {
// if we're on a page of our plugin and the theme is not BP Default, then we
// add our path to the template path array
if ( bp_is_current_component( 'bp-plugin' ) && !bp_plugin_is_bp_default() ) {

$templates[] = BP_PLUGIN_DIR . '/templates/';
}

return $templates;
}

add_filter( 'bp_get_template_stack', 'bp_plugin_add_template_stack', 10, 1 );

Doing so we make sure that if our template is not found in the WordPress active theme or in bp-legacy, it will be found in our plugin』s template folder. Finally we just need to adapt our plugin template in BP_PLUGIN_DIR . 『/templates/』 in order to strip the get_header, get_sidebar, and get_footer calls and to simply put our output into the new container tag 『

』. Now, if our template needs to load other template parts, we can use the new function bp_get_template_part to load it. Personally, i use a function that allows me to alternatively handle BP default or any WordPress theme in order to display my plugin content the best way :

function bp_plugin_locate_template( $template = false ) {
if( empty( $template ) )
return false;

if( bp_plugin_is_bp_default() ) {
locate_template( array( $template . '.php' ), true );
} else {
bp_get_template_part( $template );
}
}

In the member』s profile pages
We have two choices to load our plugin template in this area. First, we can take benefit of the different hooks bundled in the members/single/plugins.php BuddyPress template to inject our plugin』s content in its member area. Three hooks can be used :
do_action( 'bp_template_content_header' );
do_action( 'bp_template_title' );
do_action( 'bp_template_content' );

Back on our component class, when setting our plugin user navigation, we specify the screen function to play :
class BP_Plugin_Component extends BP_Component {

function __construct() {}
function includes() {}
function setup_globals() {}

function setup_nav() {

$main_nav = array(
'name' => __( 'BP Plugin' ),
'slug' => BP_PLUGIN_SLUG,
'position' => 80,
/* main nav screen function callback */
'screen_function' => 'bp_plugin_main_screen_function',
'default_subnav_slug' => 'bp-plugin-subnav'
);

// Add a few subnav items under the main tab
$sub_nav[] = array(
'name' => __( 'BP Plugin' ),
'slug' => 'bp-plugin-subnav',
'parent_url' => 'link to the parent url',
'parent_slug' => 'parent slug',
/* sub nav screen function callback */
'screen_function' => 'bp_plugin_main_screen_function',
'position' => 10,
);

parent::setup_nav( $main_nav, $sub_nav );
}
function setup_admin_bar() {}
}

Now in our bp-plugin-screen.php file, we need to write some code for our screen function in order to add actions when the three different hooks will be fired to display our content, for example :
function bp_plugin_main_screen_function {
add_action( 'bp_template_content_header', 'bp_plugin_menu_header' );
add_action( 'bp_template_title', 'bp_plugin_title' );
add_action( 'bp_template_content', 'bp_plugin_content' );

bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

function bp_plugin_menu_header() {
_e( 'Menu Header' );
}

function bp_plugin_title() {
_e( 'Plugin title' );
}

function bp_plugin_content() {
_e( 'Plugin content');
}

We can use another approach by using a new template from our plugin』s template directory. However, unlike what we』ve accomplished earlier when we hooked 『bp_setup_theme_compat『 to display our root plugin directory content, we』ll use another method to modify the template to load as whatever happens, BP_Members_Theme_Compat will buffer the members/single/plugins template. So in our screen function, we first use the bp_core_load_template as it will be used in the BP Default case and as it will finally fire the bp_setup_theme_compat hook for any WordPress theme. Then we use our BP Default check in order to add a filter (if it returns false) to the bp_get_template_part function.
function bp_plugin_main_screen_function(){

bp_core_load_template( apply_filters( 'bp_plugin_main_screen_function', 'bp-plugin-main-user-template' ) );

//if BP Default is not used, we filter bp_get_template_part
if( !bp_plugin_is_bp_default() )
add_filter('bp_get_template_part','bp_plugin_user_template_part', 10, 3 );
}

function bp_plugin_user_template_part( $templates, $slug, $name ) {
if( $slug != 'members/single/plugins' )
return $templates;

return array( 'bp-plugin-main-user-template.php' );
}

Our bp_plugin_user_template_part will override the members/single/plugins.php BuddyPress template by our bp-plugin-main-user-template.php plugin template.
Finally, don』t forget to create the template BP_PLUGIN_DIR . 『/templates/bp-plugin-main-user-template.php』
In Group pages
here we just need to rely on the display function of the BuddyPress Group Api. In order to make sure our content will load the best way in BP Default or a child of it and any WordPress theme we can use our custom bp_plugin_locate_template function.
class BP_Plugin_Group extends BP_Group_Extension {

/** other function of group API **/

function display() {
bp_plugin_locate_template( 'bp-plugin-group-template' );
}
/** other function of group API **/

}

Finally, don』t forget to create the template BP_PLUGIN_DIR . 『/templates/bp-plugin-group-template.php』

将 BuddyPress 样式添加到主题

将 BuddyPress 样式添加到主题

Codex Home → BuddyPress Theme Development → Theme Compatibility → Add BuddyPress Styles to a Theme
Add BuddyPress Styles to a Theme

BuddyPress 1.7 adds the ability to use any WordPress theme. The theme compatibility has a base style sheet that helps format the BuddyPress content. The styles may not be perfectly suited to your theme.
It』s very easy to add your own styles. If your theme folder has a sub folder called css you only need to add a stylesheet buddypress.css to this folder and BuddyPress will use this file overriding the BuddyPress styles. If the css folder is missing just create one and include the file inside. You can copy the buddypress.css file from the BuddyPress plugin folder and edit or create your own.
Theme Developer:
If you  want to ship your theme with extra styles to support BuddyPress add the BuddyPress styles to the buddypress.css file and include it in your theme. Do not add the BuddyPress styles to your style.css file. This will ensure the styles are only loaded when BuddyPress is activated and will override the default styles supplied by the plugin.
Prefix your styles with #buddypress to target the areas of BuddyPress content.
#buddypress .activity-content {

}
*NOTE As of 1.8 you can place the file in /my-theme/community/css/ or /my-theme/buddypress/css/

检查插件或主题中的活动组件

检查插件或主题中的活动组件

Codex Home → Developer Resources → Checking for Active Components in Plugins or Themes
Checking for Active Components in Plugins or Themes

BuddyPress plugins (and sometimes themes), in order to extend (or display the content of) BuddyPress components generally use their hooks, their functions, template tags or even template parts. In order to avoid errors, it』s even more important to check for active components in BuddyPress 1.7.
On a fresh install, version 1.7 only activates the Activity Streams and the Extended Profiles components. I think it』s a very interesting move because it shows the site administrator that BuddyPress is a set of components he can activate or not in order to build his very own BuddyPress powered community.
It』s also requiring plugin or theme authors to be more vigilant than before as when running the installation wizard most site administrators used to simply hit the button 「Save & Next」 leaving all the components activated.
So to prevent errors, i think it』s important we (it』s also a note to myself) check that the component is active when we』re planning to extend its behavior or when we just need to use one of its functions.
bp_is_active
To do so, since version 1.5, we can use the bp_is_active() function. It』s located in the /bp-core/bp-core-template.php file at line 1072 (in 1.7-beta1) and needs one parameter : the component identifier. This function uses the global $bp in order to return true or false depending on whether the component is active or not.
Here』s the list of the different identifiers :

Extended Profiles = 『xprofile』
Account Settings = 『settings』
Friend Connections = 『friends』
Private Messaging = 『messages』
Activity Streams = 『activity』
User Groups = 『groups』
Group Forums = 『forums』
Site Tracking = 『blogs』

Examples of use
If for some reason we want to display a particular member』s profile field, let』s check the Extended Profiles component is active.
if ( bp_is_active( 'xprofile' ) )
$fullname = xprofile_get_field_data( 1, $user_id );

If our plugin needs to deal with user settings to allow members to customize its options, it can add a new sub navigation item to the user settings navigation. If it doesn』t check if the User Settings component is enabled, it will cause a white screen of death on the front end and on the back end!!
if( bp_is_active( 'settings' ) {
bp_core_new_subnav_item( array( 'name' => __( 'BP Plugin User Settings', 'bp-checkins' ),
'slug' => 'bp-plugin-user-settings',
'parent_slug' => bp_get_settings_slug(),
'parent_url' => trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ),
'screen_function' => 'bp_plugin_screen_settings_menu',
'position' => 40,
'user_has_access' => bp_is_my_profile()
) );
}

If we plan to build a widget to display the friends of the logged in or the displayed user, let』s not forget to check the site administrator activated the Friends component.
function bp_show_friends_register_widgets() {
if( bp_is_active( 'friends' ) )
add_action('widgets_init', create_function('', 'return register_widget("BP_Show_Friends_Widget");') );
}
add_action( 'bp_register_widgets', 'bp_show_friends_register_widgets' );

A theme can choose to display the number of unread private messages of the logged in member in its header. Again, it needs to check if the component is active, or else, after its header, no more content will be displayed.

<a href="">

Our plugin may need to take benefit of the Activity Streams component, so before recording a new activity, we should check it』s available.
if( bp_is_active('activity') )
bp_activity_add( $args );

If our plugin needs to use the Group Extension API, we should first check the User Groups component is active.
class BP_Plugin_Component extends BP_Component {

function __construct() {}
function includes() {
// Files to include
$includes = array(
'includes/bp-plugin-functions.php',
'includes/bp-plugin-templatetags.php'
);

/* includes the Group API only if...
...the User Groups component is available */

if( bp_is_active( 'groups' ) )
$includes[] = 'includes/bp-plugin-group-class.php';
}
function setup_globals() {}
function setup_nav() {}
function setup_admin_bar() {}
}

function bp_plugin_load_core_component() {
global $bp;
$bp->bp_plugin = new BP_Plugin_Component;
}
add_action( 'bp_loaded', 'bp_plugin_load_core_component' );

A theme can include a template to customize the functionality of the blog home page by adding an area to display the latest group forum topics. Here, we definitely need to check for the BuddyPress forum component as it will be soon possible to use bbPress 2.3 to power group forums. The error can confuse the site administrator as he won』t understand why he gets an error as the forum of his groups are working great.

If our plugin requires a component or more to be active to run, we can catch the admin_notices hook to invite the site administrator to activate the needed component(s) that his config is missing, i』ve found these interesting lines in BuddyPress Courseware.
function bpsp_check() {
/* beginning of extract */

foreach( array( 'groups', 'activity', 'xprofile', 'forums', 'messages' ) as $c )
if( !bp_is_active( $c ) )
$messages[] = sprintf(
__( 'BuddyPress Courseware dependency error: %2$s has to be activated!', 'bpsp' ),
admin_url( 'admin.php?page=bp-general-settings' ),
$c
);

/* end of extract */
}

add_action('admin_notices', 'bpsp_check' );

bp_get_template_part 过滤器

bp_get_template_part 过滤器

Codex Home → Developer Resources → Filters & Constants Reference → bp_get_template_part Filter
bp_get_template_part Filter

Use the bp_get_template_part filter when you want to filter the template returned by BuddyPress』s bp_get_template_part() function. Your filter should accept three arguments ( $templates, $slug, $name ).
The example below illustrates how you can use the bp_get_template_part filter to change the template that』s used to display the activity tab of a member』s profile.
function my_template_part_filter( $templates, $slug, $name ) {

// check whether the current template being fetched is the activity template. If not, just return the current template
if ( 'members/single/activity' != $slug )
return $templates;

// current template being fetched is the activity template. Replace it with the generic plugins.php template
return bp_get_template_part( 'members/single/plugins' );
}

add_filter( 'bp_get_template_part', 'my_template_part_filter', 10, 3 );

Note: For an actual example of overloading an existing template part from a plugin, see Template Overload from a Plugin
If you want to programmatically supply the content without using a template file  load plugins.php and utilize its display functions. The example below will override the activity template part.
function my_template_filter_init() {

add_action( 'bp_template_title', 'my_filter_template_title' );
add_action( 'bp_template_content', 'my_filter_template_content' );
add_filter( 'bp_get_template_part', 'my_template_part_filter', 10, 3 );

}
add_action('bp_init', 'my_template_filter_init');

function my_template_part_filter( $templates, $slug, $name ) {

if ( 'members/single/activity' != $slug )
return $templates;

return bp_get_template_part( 'members/single/plugins' );
}

function my_filter_template_title() {
echo 'Title';
}

function my_filter_template_content() {
echo 'Content';
}

从插件发布活动

从插件发布活动

Codex Home → BuddyPress Plugin Development → Posting Activity from Plugins
Posting Activity from Plugins

bp_activity_add()
This function was introduced in BuddyPress 1.1, it』s located in /bp-activity/bp-activity-functions.php at line 997 (version 1.7-beta1). It needs an array of arguments and returns the activity id once created by the method BP_Activity_Activity::save()
BuddyPress uses some aliases to call this function from its different components as detailed in this chart :

Functions
Components
Types
@uses

bp_activity_post_update()
activity
activity_update
bp_activity_add()

bp_activity_new_comment()
activity
activity_comment

bp_xprofile_new_avatar_activity()
xprofile
new_avatar

bp_core_new_user_activity
xprofile
new_member

friends_record_activity()
friends
friendship_accepted
friendship_created

groups_record_activity()
groups
created_group
joined_group
new_forum_topic
new_forum_post

bp_blogs_record_activity()
blogs
new_blog
new_blog_post
new_blog_comment

In the following chart, the array of arguments the function bp_activity_add() needs is detailled :

Arguments
Default value
Explanation

id
false
If an id is passed, then the activity will be updated with the value of other arguments

action

The activity action – e.g. 「Jon Doe posted an update」

content

The content of the activity item e.g. 「BuddyPress is awesome guys!」

component
false
The identifier of the component (groups, activity, blogs, xprofile)

type
false
The activity type e.g. activity_update, joined_group, new_member…

primary_link

The primary URL for this item

user_id
bp_loggedin_user_id()
The user to record the activity for.

item_id
false
The id of the specific item being recorded, e.g. a group_id

secondary_item_id
false
A second id used to further filter e.g. a topic_id

recorded_time
bp_core_current_time()
The GMT time that this activity was recorded

hide_sitewide
false
If true, the activity will be hidden from the sitewide activity

is_spam
false
Is this activity item to be marked as spam?

The hide_sitewide argument is responsible for the visibility of the activity. If set to true, the activity won』t show in the sitewide activities (Activity Directory).
It means the activity will be 「private」 and only visible for the logged in user when viewing his profile activities (if the argument user_id is the logged in user id) and for the displayed hidden or private group when viewing its activity page (if the component argument is 『groups』 and the argument 『item_id』 is the one of the group displayed.
Hooking Activities in plugins.
If the Activity component is active ( bp_is_active( 『activity』 ) ), it can be interesting to hook the bp_activity_add function to fire some actions just after the activity has been recorded. It informs us about what just happened. For instance, we could automate a mail to inform the community admin of the creation of new groups :
function bp_plugin_hook_activity_add( $args ) {

// sends an email to admin to inform him of a group creation
if( $args['type'] == 'created_group' )
wp_mail( get_option( 'admin_email' ), 'New group!', $args['action'], 'Content-Type: text/html' );

}

add_action( 'bp_activity_add', 'bp_plugin_hook_activity_add', 10, 1 );

The advantage in this case is that we take benefit of the action argument to get some useful information such as the group creator and the permalink to the group. Of course, if the Activity component is not active, then we need to hook 『groups_group_create_complete』 and build a mail thanks to the group_id that this hook comes with.
In the Activity component, the 2 aliases ( bp_activity_post_update & bp_activity_new_comment ) have their own hooks, so we can rely on them to be sure, for instance in the first case, an activity update has just been recorded.
function bp_plugin_hook_activity_posted_update( $content, $user_id, $activity_id ) {
// this is a silly example : just to illustrate !!
$activity_count = get_user_meta( $user_id, 'silly_activity_counter' );

$activity_count = empty( $activity_count ) ? 1 : intval( $activity_count ) + 1 ;

update_user_meta( $user_id, 'silly_activity_counter', $activity_count );

}

add_action( 'bp_activity_posted_update', 'bp_plugin_hook_activity_posted_update', 10, 3 );

Of course we could use an equivalent function to count the activity comments of a user by relying on the 『bp_activity_comment_posted』 hook.
Concerning, the other aliases, we need to hook bp_activity_add(). So we』ll have to check for the component argument or the type argument in order to, for instance, add some actions in case of a new topic update or more globally of a group update.
function bp_plugin_hook_group_activity( $args ) {

if( $args['type'] == 'new_forum_topic' )
// a new topic has been posted !!

if( $args['component'] == 'groups' )
// a new group update has been posted !!

}

add_action( 'bp_activity_add', 'bp_plugin_hook_group_activity', 11, 1 );

Once again, as explained earlier, if the activity component is not active, and if you need to fire some actions, for the different types (in other words events) listed in the first chart, you』ll need to rely on other hooks (e.g. : 『groups_group_create_complete』, 『bp_core_activated_user』…). But It』s an article about playing with activities, so i』ll focus on it
Finally we can hook an activity before it has been saved. Although i discourage its use to modify the value of the activity arguments, community admins can use a particular hook to neutralize some mini activities if they wish to. Mini activities don』t have content and are used to log simple events such as the creation of a group, the fact that a member became a member of a group, etc. Lately, i was asked how to avoid recording activities when members are becoming friends or when a member joins a group. This can be achieve by hooking 『bp_activity_before_save』.
function bp_plugin_dont_save_minis( $activity_object ) {
// friendship_created is fired when a member accepts a friend request
// joined_group is fired when a member joins a group.
$exclude = array( 'friendship_created', 'joined_group');

// if the activity type is empty, it stops BuddyPress BP_Activity_Activity::save() function
if( in_array( $activity_object->type, $exclude ) )
$activity_object->type = false;

}

add_action('bp_activity_before_save', 'bp_plugin_dont_save_minis', 10, 1 );

Recording activities for a custom component.
Well it』s quite easy, we just need to use the function bp_activity_add() and to customize its arguments regarding our component need.
function bp_plugin_record_activity() {

$activity_id = bp_activity_add( array(
'action' => 'bp plugin action',
'content' => 'bp plugin content',
/* the component argument will be set to our component's identifier */
'component' => 'bp_plugin',
/* the type argument will be set to our component's type */
'type' => 'bp_plugin_update',
) );

return $activity_id;
}

Now to take a full benefit of our custom activities, we also need to customize the available options of the activity filters that are located in the sitewide Activity directory, in the user』s profile activity page and in the group』s activity page :
function bp_plugin_activity_filter() {
?>

component->id
!important you have to use the BP_Component class to do so
See : https://codex.buddypress.org/bp_component/
***************************************************************************/
$bp->bp_plugin = new stdClass();
$bp->bp_plugin->id = 'bp_plugin';

// Bail if activity is not active
if ( ! bp_is_active( 'activity' ) )
return false;

bp_activity_set_action( $bp->bp_plugin->id, 'bp_plugin_update', __( 'BP plugin update' ) );

}

add_action( 'bp_register_activity_actions', 'bp_plugin_activity_actions' );

Finally if your component』s plugin deals with a custom post type, you can also take benefit of the Site Tracking component to automatically record an activity. Personaly, in this case, i prefer to build my own function to control the activity arguments. But you could filter the hooks 『bp_blogs_record_post_post_types』 and 『bp_blogs_record_comment_post_types』 in order to generate an activity with a type argument of 「new_blog_post」 when a custom post type is published and of 「new_blog_comment」 when a comment is posted on your custom post type.
function bp_plugin_custom_post_type( $post_type ) {
$post_type[] = 'bp_plugin_post_type';

return $post_type;
}

add_filter( 'bp_blogs_record_post_post_types', 'bp_plugin_custom_post_type', 10, 1);
add_filter( 'bp_blogs_record_comment_post_types', 'bp_plugin_custom_post_type', 10, 1);

Fully enjoy bp_activity_set_action()
In the previous section, you』ve seen how to use this function to add the custom plugin activity action to the dropdown filters of the Activity Administration screens.
Since BuddyPress 2.0 and 2.1, this function has evolved and has now 3 more parameters to help plugin developers to have more control on :

the activity action strings (2.0): for a better compatibility with multilingual sites
the dropdown filters on front-end (2.1): if BP Theme Compat is in use or if the custom template is using the function bp_activity_show_filters() to generate the options instead of directly hardcoding them in the templates.

function bp_plugin_activity_actions() {
$bp = buddypress();

/**************************************************************************
for the purpose of this tutorial we arbitrary set the $bp->component->id
!important you have to use the BP_Component class to do so
See : https://codex.buddypress.org/bp_component/
***************************************************************************/
$bp->bp_plugin = new stdClass();
$bp->bp_plugin->id = 'bp_plugin';

bp_activity_set_action(
$bp->bp_plugin->id, // The unique string ID of the component the activity action is attached to
'bp_plugin_update', // the action type
__( 'BP plugin update', 'plugin-domain' ), // the action description used in Activity Administration screens dropdown filters
'bp_plugin_format_bp_plugin_update', // A callable function for formatting the action string
__( 'BP plugin update', 'plugin-domain' ), // the action label of the activity front-end dropdown filters
array( 'activity', 'member' ) // Activity stream contexts where the filter should appear
);
}
add_action( 'bp_register_activity_actions', 'bp_plugin_activity_actions' );

/**
* Callable function for formatting the action string
* Since 2.0 activity action strings are generated dynamically, for a better compatibility with multilingual sites
*/
function bp_plugin_format_bp_plugin_update( $action = '', $activity = null ) {
$action = sprintf( __( '%s shared a new BP plugin update', 'plugin-domain' ), bp_core_get_userlink( $activity->user_id ) );

return $action;
}

As you can see in the above code, you can set the callable function for formatting the action string using the 4th argument of bp_activity_set_action()
You can also set the 5th and 6th argument instead of using the 'bp_activity_filter_options' hook to set the label and the contexts where your option will appear in the available dropdowns :

'': will not display your option in front-end
array( 'activity' ): will display your option only in the activity directory
array( 'activity', 'member' ): will display your option in the activity directory and in the member』s activity page
array( 'activity', 'member', 'member_groups' ): will display your option in the activity directory, in the member』s activity page and member』s groups activity page
array( 'activity', 'groups' ): will display your option in the activity directory and in the single group』s activity page.

Please note that this possibility was introduced in BuddyPress 2.1. It will work for the configs using the templates included in BuddyPress (BP Theme Compat). Some BuddyPress Themes might not have updated their activity templates (activity/index.php, groupssingleactivity.php, memberssingleactivity.php).