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

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

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 1.7 捆绑自定义模板的旧插件

升级为 BP 1.7 捆绑自定义模板的旧插件

Codex Home → BuddyPress Plugin Development → Upgrading older plugins that bundle custom templates for BP 1.7
Upgrading older plugins that bundle custom templates for BP 1.7

This article examines what you can do as a plugin developer to maintain backwards-compatibility template support, while utilizing the newer template-loading approach as featured in BuddyPress 1.7.
We will walk through a real-life case study involving the BP Follow plugin and what was done to update the plugin for BuddyPress 1.7.
Intro
If you created a BuddyPress plugin that bundles custom template files, chances are you might have followed the bp_example_load_template_filter() function approach as recommended by the BP Skeleton Component:
https://github.com/r-a-y/buddypress-skeleton-component/blob/master/includes/bp-example-functions.php#L10
If you didn』t follow this approach, you are lucky! You get to stop reading the rest of this article!
For the rest of you, this approach was fine for versions of BuddyPress previous to 1.7 as BP was only specific to the bp-default theme.
However, if we don』t alter the bp_example_load_template_filter() function, what it actually does is bypass the universal theme compatibility code, which is the main feature in BuddyPress 1.7.
Obviously, we do not want to do that!
Words can only explain so much, so here are some screenshots of the BP Follow plugin before we dive into the tutorial:
Screenshot of the BP Follow plugin running on BP 1.7 before updating the code on the TwentyTen theme:

Screenshot of the BP Follow plugin running on BP 1.7 after updating the code on the TwentyTen theme:

What we』re going to do is make the BP Follow plugin look like the second screenshot so it will be ready for BuddyPress 1.7.
Let』s get started!
(1) Include some 1.7 template-compatibility code with your plugin
BuddyPress 1.7 comes with some awesome new template-loading functions like bp_get_template_part().
However, not everyone will be upgrading to BuddyPress 1.7 immediately, so we need to include some 1.7-compatible code with our plugin to ensure that this new code will work on older BP installs.
A version of this code can be found here:
https://gist.github.com/r-a-y/5119066
Make sure to add it to your plugin』s includes section like so:
if ( ! class_exists( 'BP_Theme_Compat' ) ) {
require( 'THE FILE FROM THE LINK ABOVE AND WHATEVER YOU NAMED IT TO' );
}

For reference, BP Follow does this here:
https://github.com/r-a-y/buddypress-followers/blob/1.2.x/bp-follow-core.php#L54
We will utilize some of these functions a little bit later, but let』s get back to that first screenshot from the Intro section.
(2) A closer look at the 『bp_located_template』 filter
So what is happening in the first screenshot?
If we analyze the bp_follow_load_template_filter() function, we can see that it is similar to the BP Skeleton Component as referenced in the Intro.
What』s happening is BP Follow will always serve its own template:
https://github.com/r-a-y/buddypress-followers/blob/1.1.x/_inc/templates/members/single/following.php
Which is a full page template (using get_header() and get_footer()) and not a template part.
The bp_follow_load_template_filter() function runs on the 'bp_located_template' filter, so let』s examine that for a second:
https://buddypress.trac.wordpress.org/browser/tags/1.7-rc1/bp-core/bp-core-catchuri.php#L378
Since our function always returns a template location, we will bypass the universal theme compatibility code that runs on lines 397-411 and our full page template will be loaded.
We don』t want to do this.
So the first thing we do is alter the function to this:
function bp_follow_load_template_filter( $found_template, $templates ) {
global $bp;

// Only filter the template location when we're on the follow component pages.
if ( ! bp_is_current_component( $bp->follow->followers->slug ) && !bp_is_current_component( $bp->follow->following->slug ) )
return $found_template;

// $found_template is not empty when the older template files are found in the
// parent and child theme
//
// When the older template files are not found, we use our new template method,
// which will act more like a template part.
if ( empty( $found_template ) ) {

// we will add some code here to add our new templates in the next step
}

return apply_filters( 'bp_follow_load_template_filter', $found_template );
}
add_filter( 'bp_located_template', 'bp_follow_load_template_filter', 10, 2 );

What we』re doing here is checking if $found_template is empty.
The passed $found_template variable already tries to find if our full templates:

/members/single/following.php
/members/single/followers.php

exist in the parent or child themes because locate_template() is used.
This is great for themes that might have overriden the old templates that came with BP Follow and handles our backwards-compatibility requirement.
If $found_template is empty, we can start to add some code to add our new template parts!
(3) Get acquainted with the BP Template Stack
The BP Template Stack is a new approach in BP 1.7 to locate templates residing in different directories.
BP handles template stack registration here:
https://buddypress.trac.wordpress.org/browser/tags/1.7-rc1/bp-loader.php#L536
Let』s look at the following lines specifically:
bp_register_template_stack( 'get_stylesheet_directory', 10 );
bp_register_template_stack( 'get_template_directory', 12 );

bp_register_template_stack() is a function that allows us to register a template directory where BP will attempt to find templates in.
The first parameter is a function callback returning a directory that houses templates; the second parameter tells BuddyPress when to look at this directory.
If we look at the above example, what this means is BuddyPress will look in the stylesheet directory (or child theme』s directory) for templates first since it has a priority of 10. Next, BuddyPress will look for templates in the template directory (or parent theme』s directory) if it could not find it in the child theme since it has a priority of 12.
We can also register our own directory to the stack; this is especially beneficial for 3rd-party components and is exactly what we』re doing in BP Follow:
function bp_follow_load_template_filter( $found_template, $templates ) {
global $bp;

// Only filter the template location when we're on the follow component pages.
if ( ! bp_is_current_component( $bp->follow->followers->slug ) && !bp_is_current_component( $bp->follow->following->slug ) )
return $found_template;

// $found_template is not empty when the older template files are found in the
// parent and child theme
//
// When the older template files are not found, we use our new template method,
// which will act more like a template part.
if ( empty( $found_template ) ) {

// register our theme compat directory
//
// this tells BP to look for templates in our plugin directory last
// when the template isn't found in the parent / child theme
bp_register_template_stack( 'bp_follow_get_template_directory', 14 );

// we're not done yet! read on to the next step!
}

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

Note that 'bp_follow_get_template_directory' is a real function returning the location where our custom templates are housed:
https://github.com/r-a-y/buddypress-followers/blob/1.2.x/_inc/bp-follow-screens.php#L138
We』re giving it a priority of 14 so it is checked after the stylesheet and template directories.
(4) Setup bp-default compatibility
Now, we have to make sure that we still support the bp-default theme, since a lot of people will still be using that theme.
Don』t forget that bp-default has its own page template for plugins where we can inject our plugin content into:

/members/single/plugins.php – members component
/groups/single/plugins.php – groups component

In the BP Follow plugin, since we add new pages to member profiles, we will alter the bp_follow_load_template_filter() function to look for the 'members/single/plugins.php' template:
function bp_follow_load_template_filter( $found_template, $templates ) {
global $bp;

// Only filter the template location when we're on the follow component pages.
if ( ! bp_is_current_component( $bp->follow->followers->slug ) && !bp_is_current_component( $bp->follow->following->slug ) )
return $found_template;

// $found_template is not empty when the older template files are found in the
// parent and child theme
//
// When the older template files are not found, we use our new template method,
// which will act more like a template part.
if ( empty( $found_template ) ) {

// register our theme compat directory
//
// this tells BP to look for templates in our plugin directory last
// when the template isn't found in the parent / child theme
bp_register_template_stack( 'bp_follow_get_template_directory', 14 );

// plugins.php is the preferred template to use, since all we'd need to do is
// inject our content into BP
//
// note: this is only really relevant for bp-default themes as theme compat
// will kick in on its own when this template isn't found
$found_template = locate_template( 'members/single/plugins.php', false, false );

// we're almost there! let's move on to the next step!
}

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

So what did we just do?
We are redeclaring the passed $found_template variable to look for 'members/single/plugins.php'. locate_template() will attempt to find this template in the child and parent theme and will return the location of this template if found.
Since we』re thinking of bp-default users, this template will always be found since that template is bundled with bp-default. Therefore, this template will be loaded by BuddyPress.
If we』re using any other WordPress theme, BuddyPress』 theme compatibility will kick in later since this template will not be found.
Lastly, we need to setup our new template parts so they will be loaded by BuddyPress.
(5) Setup the new template parts
We』re going to inject our new template parts using the "bp_template_content" hook, which is located in both the bp-default theme and the theme compatibility templates:

https://buddypress.trac.wordpress.org/browser/tags/1.7-rc1/bp-themes/bp-default/members/single/plugins.php#L57
https://buddypress.trac.wordpress.org/browser/tags/1.7-rc1/bp-templates/bp-legacy/buddypress/members/single/plugins.php#L29

Our updated bp_follow_load_template_filter() function looks like this:
https://github.com/r-a-y/buddypress-followers/blob/1.2.x/_inc/bp-follow-screens.php#L60
function bp_follow_load_template_filter( $found_template, $templates ) {
global $bp;

// Only filter the template location when we're on the follow component pages.
if ( ! bp_is_current_component( $bp->follow->followers->slug ) && !bp_is_current_component( $bp->follow->following->slug ) )
return $found_template;

// $found_template is not empty when the older template files are found in the
// parent and child theme
//
// When the older template files are not found, we use our new template method,
// which will act more like a template part.
if ( empty( $found_template ) ) {

// register our theme compat directory
//
// this tells BP to look for templates in our plugin directory last
// when the template isn't found in the parent / child theme
bp_register_template_stack( 'bp_follow_get_template_directory', 14 );

// plugins.php is the preferred template to use, since all we'd need to do is
// inject our content into BP
//
// note: this is only really relevant for bp-default themes as theme compat
// will kick in on its own when this template isn't found
$found_template = locate_template( 'members/single/plugins.php', false, false );

// add our hook to inject content into BP
//
// note the new template name for our template part
add_action( 'bp_template_content', create_function( '', "
bp_get_template_part( 'members/single/follow' );
" ) );
}

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

So what is happening here?
// add our hook to inject content into BP
//
// note the new template name for our template part
add_action( 'bp_template_content', create_function( '', "
bp_get_template_part( 'members/single/follow' );
" ) );

We are adding a hook to the "bp_template_content" action to load our new template part with the bp_get_template_part() function that we added from our 1.7 compatibility code in step (1).

If you』re wondering what create_function() is for, it』s just a way to create an anonymous function without having to create a real function. You can still create a real function if you wanted to.
For example, you could do this instead:
add_action( 'bp_template_content', 'my_new_template_part_function' );

And somewhere else, you could have my_new_template_part_function() defined like:
function my_new_template_part_function() {
bp_get_template_part( 'members/single/follow' );
);

And the same result would occur. Anyway, back to our regular, scheduled programming!

The new template part resides at:
/members/single/follow.php
If you recall, the old templates in BP Follow reside here:

members/single/following
members/single/followers

For the new template parts, we cannot use the same location and filename due to backwards-compatibility issues.
Hence, for BP Follow, we simply went with /members/single/follow since the 「Following」 and 「Followers」 screens use the same information.
Notice that /members/single/follow is a template part and that the templates reside in a subfolder called 『buddypress』.
The 'buddypress' subfolder is just another one of those cool BP 1.7 features to help separate custom templates in your theme directory just a little bit better.
For example, if you wanted to override the new template part in your Twenty Twelve theme, you could copy 'buddypress/members/single/follow.php' to your theme:
/wp-content/themes/twentytwelve/buddypress/members/single/follow.php
Make a few changes and they would override the bundled template part from BP Follow. To find out a little more about this feature, read this codex article.
If your own BuddyPress plugin uses more than one template, you will have to introduce a bit more logic.
Check out the changes to BP-Album, a plugin that recently implemented the same approach listed above:
https://github.com/BP-Media/bp-album/pull/4
Pay special attention to lines 404-417:
https://github.com/BP-Album/bp-album/blob/master/includes/bpa.core.php#L372
Summary
The bp_follow_load_template_filter() function is now complete! And our second screenshot from step (1) should now show up.
So to summarize, what did we just do?
We:

Added BP 1.7 theme backpat functions so we can use them in our plugin
Allow themes that are already using the older, full page templates to continue working as-is
Change our plugin to use /members/single/plugins.php as the template so we can inject template parts into BP without changing the surrounding markup
Re-route older template locations to use our new template parts to avoid conflicts.

The beauty of this entire approach is older versions of BuddyPress (tested down to v1.5) will inherit some of 1.7』s template-loading features as well, so we get to be both backwards-and-future-compatible with the way we utilize templates in our BuddyPress plugin.

BuddyPress 小工具

BuddyPress 小工具

Codex Home → BuddyPress Theme Development → BuddyPress Widgets
BuddyPress Widgets

BuddyPress provides widgets which you can add to any of your theme』s widget areas. To activate these, go to dashboard menu Appearance > Widgets.

(BuddyPress) Friends
(BuddyPress) Groups
(BuddyPress) Log In
(BuddyPress) Members
(BuddyPress) Recently Active Members
(BuddyPress) Sitewide Notices
(BuddyPress) Who』s Online
(BuddyPress) Recent Networkwide Posts – Multisite Installations only

(BuddyPress) Friends
A dynamic list of recently active, popular, and newest Friends of the displayed member. Widget is only shown when viewing a member profile.
Options
Link widget title to Members directory – optional
Maximum friends to show – default is 5
Default friends to show: Newest, Active, or Popular

(BuddyPress) Groups
A dynamic list of recently active, popular, and newest groups
Options
Title: Set the title to be displayed in the sidebar – optional
Link widget title to Groups directory – optional
Maximum groups to show – default is 5
Default groups to show: Newest, Active, or Popular

(BuddyPress) Log In
Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.
Option
Title: Set the title to be displayed in the sidebar – optional

(BuddyPress) Members
A dynamic list of recently active, popular, and newest members
Options
Title: Set the title to be displayed in the sidebar – optional
Link widget title to Members directory – optional
Maximum members to show
Default members to show: Newest, Active, or Popular

(BuddyPress) Recently Active Members
Profile photos of recently active members
Options
Title: Set the title to be displayed in the sidebar – optional
Maximum members to show – default is 15

(BuddyPress) Sitewide Notices
Display Sitewide Notices posted by the site administrator
Option
Title: Set the title to be displayed in the sidebar – optional

(BuddyPress) Who』s Online
Profile photos of users who are currently online
Options
Title: Set the title to be displayed in the sidebar – optional
Maximum members to show – default is 15

(BuddyPress) Recent Networkwide Posts
A list of recently published posts from across your network (multisite)
Options
Title: Set the title to be displayed in the sidebar – optional
Link widget title to Blogs directory – optional
Maximum posts to show – default is 10

bp_core_get_userlink()

bp_core_get_userlink()

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

Description
Returns a HTML formatted link for a user with the user』s full name as the link text.
Top
Usage

Top
Parameters
$user_id
(integer) User ID to check.
$no_anchor
(bool) Disable URL and HTML and just return full name. Default false.
$just_link
(bool) Disable full name and HTML and just return the URL text. Default false.
Returns
Returns false when there was no match found, and the link text (string) based on passed parameters.
Top
Example

post_author ) ); ?>

Top
Source File
bp_core_get_userlink() is located in bp-members/bp-members-functions.php

群组 (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

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';
}

开发者和设计师信息 BP 1.7

开发者和设计师信息 BP 1.7

Codex Home → Legacy Docs → Archived Section: Getting Started → Developer and Designer Information BP 1.7
Developer and Designer Information BP 1.7

Archived file. Good only for BP 1.7 version

BuddyPress 1.7 Theme Compatibility
* Theme Authors, Make Sure Your Theme Registers BuddyPress Support – @boonebgorges
* Add BuddyPress Styles To a Theme – @modemlooper
* Overview of Theme Compatibility in BP 1.7 (Customization) – @hnla
* Upgrading 「Template Packed」 Themes to BP 1.7 Theme Compatibility – @mercime
* New Members Navigation Menus – @hnla
Plugins for BuddyPress 1.7
* Using theme compatibility in plugins – @imath
* Upgrading Older Plugins That Bundle Custom Templates for BP 1.7 – @r-a-y
BP 1.7 Developers and Contributors

信息 (Messages)

信息 (Messages)

Codex Home → Administrator Guide → Messages
Messages

Sections

Public Messages
Private Messages

Private Message Screens
How to Send a Private Message

Public Messages
BuddyPress provides ways for you to send a message publicly to another member of the site or network. Members will be notified of public messages by a new message count in the Notifications circle in Admin/Toolbar as well as receive an email notifications, if enabled by said member.

Mention the member by using the 「at sign」 ( @ ) + member username, e.g. @mercime. Mentioning the user can be done anywhere within the BuddyPress site:

Status Update form in the Sitewide Activity page, Group Activity page or in your own profile page
Activity Stream Comment and/or Reply form
Forum Topic Post or Reply Post – if the bbPress forums (sitewide or group) plugin is activated in your site

Click on the Public Message button located beside the member』s avatar in his/her profile page (see image above). That brings you to your own Activity Status Update form with that member』s username already mentioned. Add your message and click on Post Update button.

Private Messages
Private Messaging works like an internal site email. Members can message people on their friends list as well as reply to received messages. Each member will have their own individual Inbox and Sent messages folders as well as a Compose message screen. Members will be notified of new messages by a new message count in own Messages tab, in notification circle in Admin toolbar, as well as receive email notifications of the private message, if enabled.
Private Message Screens

Inbox – Shows the list of Private Message/s sent to your by members of the site. Visible to the logged in member only.Options

Search Messages
Read Message
Delete Message
Bulk Delete Messages – Select Read, Unread or All Messages

Sent – Shows the list of Message/s you have sent to other members of the site. Visible to the logged in member only.Options

Search Sent Messages
Read Sent Message
Delete Sent Message
Bulk Delete Sent Messages – Select Read, Unread or All Messages

Compose – Shows a form to send messages. Visible to logged in member only.Input

Send To (Username or Friend』s Name) field
Super Admin Only: Checkbox for 「This is a notice to all users.」
Subject field
Message field
Send Message button

Super Admin Only: Notices – Shows a list of Sitewide Notices broadcasted and date sent via Compose panel. The Super Admin』s notice will show up in the sidebar for logged in members only (BP Default theme) who in turn, can click on the 「Close」 link at the end of the notice – hopefully after they』ve read the message first. The following buttons are visible to the Site/Super Admin only.

Deactivate (notice) button
Delete (notice) button

How to Send a Private Message
Via member』s Private Message button

Go to the member』s profile page
Click on the Private Message button in the member』s header area and you will be redirected to your Messages > Compose screen
Member』s username is already entered as addressee
Enter the Title of your message
Enter content of your message
Click on the Send Message button
The logged in member will be notified about the message via Notification alert in the Admin Toolbar and via email if enabled.

Via your Account navigation in Admin Toolbar

Hover over your account Messages > click on Compose and you will be redirected to your Messages > Compose screen
Enter the username or the display name of your friend
Enter the Title of your message
Enter content of your message
Click on the Send Message button
The logged in member will be notified about the message via Notification alert in the Admin Toolbar and via email if enabled.

群组扩展 API(旧版)

群组扩展 API(旧版)

Codex Home → Legacy Docs → Archived Section: Developer Resources → Group Extension API (legacy)
Group Extension API (legacy)

Archived file. Good only up to BP 1.7 version

Note: This guide is for use with versions of BuddyPress older than 1.8. In BP 1.8, the group extension API was rewritten. Plugins written as described below should continue to work, but for new projects you are highly encouraged to use the 1.8+ methods described on the main Group Extension API Codex page.
The group extension API (1.1+) makes it very easy to add custom creation steps, edit screens, navigation items and pages to a group. It essentially allows you to create fully functional extensions to BuddyPress created groups.
Note: If you are building a BuddyPress plugin, please make sure you have read how to check if BuddyPress is active. This is very important.
Note: The admin_screen() and admin_screen_save() methods are new in BuddyPress 1.7. On earlier versions of BP, they won』t do anything.
The API Syntax
A group extension could be created as a standalone plugin file, or included as code within a plugin that performs other tasks. The core API code is as follows:
if ( bp_is_active( 'groups' ) ) : // Recommended, to prevent problems during upgrade or when Groups are disabled

class My_Group_Extension extends BP_Group_Extension {

function __construct() {
$this->name = 'My Group Extension';
$this->slug = 'my-group-extension';

$this->create_step_position = 21;
$this->nav_item_position = 31;
}

/**
* The content of the My Group Extension tab of the group creation process
*
* Don't need a group creation step? In the __construct() method:
*
* $this->enable_create_step = false;
*/
function create_screen() {
if ( !bp_is_group_creation_step( $this->slug ) )
return false;

/**
* If your extension's Create step shares much of its code with
* its Edit step, you might consider putting shared markup into
* a separate method (such as edit_create_markup()), and then
* call the method here:
*
* $this->edit_create_markup();
*/
?>

The HTML for my creation step goes here.

slug );
}

/**
* The routine run after the user clicks Continue from your creation step
*
* You'll be pulling your data out of the $_POST global. Be sure to
* sanitize as necessary.
*/
function create_screen_save() {
global $bp;

check_admin_referer( 'groups_create_save_' . $this->slug );

/* Save any details submitted here */
groups_update_groupmeta( $bp->groups->new_group_id, 'my_meta_name', 'value' );
}

/**
* The content of the My Group Extension tab of the group admin
*/
function edit_screen() {
if ( !bp_is_group_admin_screen( $this->slug ) )
return false; ?>

name ) ?>

Edit steps here

slug );
}

/**
* The routine run after the user clicks Save from your admin tab
*
* You'll be pulling your data out of the $_POST global. Be sure to
* sanitize as necessary.
*/
function edit_screen_save() {
global $bp;

if ( !isset( $_POST['save'] ) )
return false;

check_admin_referer( 'groups_edit_save_' . $this->slug );

/* Insert your edit screen save code here */

/* To post an error/success message to the screen, use the following */
if ( !$success )
bp_core_add_message( __( 'There was an error saving, please try again', 'buddypress' ), 'error' );
else
bp_core_add_message( __( 'Settings saved successfully', 'buddypress' ) );

bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/admin/' . $this->slug );
}

/**
* Use this function to display the actual content of your group extension when the nav item is selected
*/
function display() {
?>

Welcome to my cool group extension!

The HTML for my admin panel.

name ) ?>

You could display a small snippet of information from your group extension here. It will show on the group
home screen.

enable_nav_item = $this->enable_nav_item();

/* Add this method the end of your extension class */
function enable_nav_item() {
global $bp;

/* You might want to check some groupmeta for this group, before determining whether to enable the nav item */
if ( groups_get_groupmeta( $bp->groups->current_group->id, 'settings_complete' ) )
return true;
else
return false;
}

安装群组和全站点论坛

安装群组和全站点论坛

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