从插件发布活动

从插件发布活动

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).

BP 1.7 – 升级 「模板打包」 主题

BP 1.7 – 升级 「模板打包」 主题

Codex Home → Legacy Docs → Archived Section: Theme Development → BP 1.7 – Upgrading 「Template Packed」 Themes
BP 1.7 – Upgrading 「Template Packed」 Themes

Archived file. Good up to BP 1.8.

From BuddyPress 1.2 through 1.6.5, most WordPress themes went through the BP Compatibility process via the BuddyPress Template Pack plugin to align the HTML structure of the BP template files with that of the respective WP theme.
BuddyPress 1.7 is now compatible with nearly all WordPress themes available in the market. To make your BP component pages future-proof, it』s time to take advantage of the theme compatibility BP 1.7 brings to the table. Activated BP components will automagically be inserted into your theme』s default page structure.
Upgrading to BP 1.7 – Changing from BP Template Pack to default BP 1.7 Theme Compatibility

Back up or download a copy of your WP theme folder in server which contains the template-packed files or folders.
Deactivate the BP Template Pack plugin in Plugins > Installed.
Delete the six (6) BP folders transferred to your theme』s folder in server when you went through the BP Compatibility Process: /activity, /blogs, /forums, /groups, /members, and /registration. If you have a header-buddypress.php, sidebar-buddypress.php and/or a footer-buddypress.php files, delete those files as well via s/FTP or control panel.
Upgrade to BuddyPress 1.7.
Check out your site』s BP pages – activity, members, etc. – which should contain the respective BP components activated in Settings > BuddyPress.

Frequently Asked Questions
BP 1.7 Theme Compatibility is not working on my theme.
That could be due to a variety of reasons including the WordPress theme』s customized templating, erroneous coding, missing page titles in pages and so forth, all of which are beyond our control. Please create a topic at the BuddyPress Forums and report the problem.
To facilitate troubleshooting, open up your theme』s page.php file, copy all code, paste into pastebin.com and post the generated URL in your support topic. While troubleshooting is going on, re-upload the theme folder you backed up in #1 above which contains the template-packed files/folders to wp-content/themes/ and activate BP Template Pack plugin.
I want to remove the sidebar and have full-width layout for all BuddyPress pages.
1. Open the full-width template in your theme with a text editor and copy all source code.
2. Create a file named buddypress.php and paste the copied source code into the file and save.
3. Upload buddypress.php to your theme』s folder in server i.e., wp-content/themes/yourtheme/
reference: A Brief overview of BuddyPress Theme Compatibility in 1.7
Note: Customize the layouts of BuddyPress pages within the WordPress Default Themes
Why do my sitewide and group forums still have a sidebar even when I uploaded a full-width layout with buddypress.php file?
That』s because since BP version 1.7, sitewide and group forums are rendered by the bbPress plugin. You』d need to copy the full-width template source code into a new file named bbpress.php

用户扩展个人资料

用户扩展个人资料

Codex Home → Administrator Guide → User Extended Profiles
User Extended Profiles

Highlight the best of your community members by creating an unlimited number of Extended Profile (xProfile) Fields and/or groups of Extended Profile Fields custom-made for your social network.
To start creating xProfile fields, go to administration menu Users > Profile Fields. If you have a multisite installation with BuddyPress activated network-wide via Network Admin > Plugins, you』ll find the Profile Fields admin screen via Network Admin > Users > Profile Fields
Sections

Add New xProfile Field
Add New xProfile Field Group
Rearranging xProfile Fields or Field Groups

Add New xProfile Field

Fields marked * are required.
Fields in the 「Base」 (Primary) group will appear on the signup/register page.
Input
Field Title*
Field Description
Is this field required?
Select
Not Required
Required

Field Type:
Select
Single Line Text Box
Multi-line Text Box
Date Selector
Radio Buttons
Dropdown Select Box
Multiple Select Box
Checkboxes

Default Visibility
Options
Anyone (default)
Logged In Users
Admins Only
My Friends

Per-Member Visibility
Options
Let members change this field』s visibility {default)
Enforce the default visibility for all members

Save button, Cancel link

Edit Group button – allows you add, remove, move or change any xProfile field in the specific xProfile Group
Name (Primary)(Required) Field – Nice Name
Edit Field button – opens up a new screen
Input
Field Name (Required)
Field Description

Add New xProfile Field Group

The Add New Field Group button is located beside the Profile Fields component title. Click on the button to create a new Profile Group where you can later add more xProfile Fields

Title of xProfile Field Group
(Field) Group Description
Create Field Group button or Cancel link

Rearranging xProfile Fields or xProfile Field Groups
A. Change order of xProfile Fields within a Profile Field Group:
You can change the order by which xProfile Field/s show up in the Registration Form or in the Member』s Profile area by dragging the field up or down within the field group to the preferred location.

B. Change order of xProfile Field Groups:
You can change the order by which your xProfile Field Groups show up in Member』s Profile area by dragging the Group Tab to the left or right in Users > Profile Fields screen. Remember that only the Base (Primary) Field Group shows up in the Registration Form.

C. Move an xProfile Field from one xProfile Field Group to Another:
1. Click on the xProfile Field Group tab to open the panel where the xProfile Field you want to move is located.
2. Drag that xProfile Field to the xProfile Field Group tab where you want to move the xProfile Field.
3. You can then rearrange the position of the xProfile Field in new field group by dragging up or down to where you want to position the xProfile Field within the new group.

群组扩展 API

群组扩展 API

Codex Home → Developer Resources → Group Extension API
Group Extension API

Note: This guide is for use with BuddyPress 1.8+. A guide for using the Group Extension API with earlier versions of BP can be found at https://codex.buddypress.org/developer/plugin-development/group-extension-api-prior-to-bp-1-8/.
The group extension API 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. You might also want to check & ensure that the Group component is active using the bp_is-active() function.
Overview
The Group Extension API consists of a base class called BP_Group_Extension, which you extend in your own plugin. BP_Group_Extension does most of the work necessary to integrate your content into BP group – creating new navigation tabs, registering a step during group creation, etc. See the Examples section for working examples.
Use
Use BP_Group_Extension as follows:

In a plugin file, create your own class that extends BP_Group_Extension.
In the __construct() method, pass an array of arguments to parent::init(). Arguments are described in the Configuration section.
Write any methods that your extension requires. See the Methods section for available options.
Register your extension with BuddyPress using bp_register_group_extension()

 
Configuration
In the __construct() method of your extension class, you should define a set of arguments and pass them to parent::init(). (Reference the examples to see how this is done.) Possible arguments:

slug
(required) A unique string identifier for your extension. Used, among other places, in the construction of URLs.
name
(required) The translatable name of your extension. Used as the default value for navigation items and page titles.
visibility
(optional) 'public' means that your extension will be visible to anyone who can access the group, 'private' means it won』t. Defaults to 'public'. Note: BuddyPress 2.1.0 added the new argument 'access', which should be used when possible.
nav_item_position
(optional) An integer describing where your extension』s tab should appear. A number between 1 and 100 is recommended. Defaults to 81.
enable_nav_item
(optional) true for the nav item to be enabled for the current user, false otherwise. Defaults to true. Note: BuddyPress 2.1.0 added the new argument 'show_tab', which should be used when possible.
nav_item_name
(optional) The string you want to appear in the navigation tab for your group extension. Defaults to the of the 『name』 parameter, described above.
display_hook
(optional) The WordPress action that the widget display method is hooked to. Defaults to 'groups_custom_group_boxes'.
template_file
(optional) The template file that BuddyPress will use as a wrapper for your display content. Defaults to 'groups/single/plugins.php'
screens
(optional) A multi-dimensional array of options related to the three secondary 「screens」 available to group extensions: 『create』 (the step dedicated to the extension during the group creation process), 『edit』 (the subtab dedicated to the extension under the Admin tab of the group), and 『admin』 (the extension』s metabox that appears on the group page when editing via the Groups Administration Dashboard panels). Each of these screens has a set of configuration options, to be described below. Note that all config values are optional, and you only need to override those values where you want to change the default – BuddyPress will parse your 『screens』 array, using your provided values when available, otherwise falling back on the defaults.

create – Config options for the 『create』 screen

position – The position of the extension』s step in the Create a Group process. An integer between 1 and 100 is recommended. Defaults to 81.
enabled – true if you want your extension to have a Create step, otherwise false. Defaults to true.
name – The name of the creation step, as it appears in the step』s navigation tab. Defaults to the general 『name』 value described above.
slug – The string used to create the URL of the creation step. Defaults to the general 『slug』 value described above.
screen_callback – The function BP will call to display the content of your create screen. BuddyPress attempts to determine this function automatically; see Methods below. Do not change this value unless you know what you』re doing.
screen_save_callback – The function BP will call after the extension』s create step has been saved. BuddyPress attempts to determine this function automatically; see Methods below. Do not change this value unless you know what you』re doing.

edit – Config options for the 『edit』 screen

submit_text – The text of the submit button on the edit screen. Defaults to 'Edit'.
enabled – true if you want your extension to have a subtab in the Group Adimn area, otherwise false. Defaults to true.
name – The text that appears in the navigation tab for the extension』s Edit screen. Defaults to the general 『name』 value described above.
slug – The string used to create the URL of the admin tab. Defaults to the general 『slug』 value described above.
screen_callback – The function BP will call to display the content of your admin tab. BuddyPress attempts to determine this function automatically; see Methods below. Do not change this value unless you know what you』re doing.
screen_save_callback – The function BP will call after the extension』s admin tab has been saved. BuddyPress attempts to determine this function automatically; see Methods below. Do not change this value unless you know what you』re doing.

admin – Config options for the 『admin』 screen

metabox_context – The context for your extension』s metabox. Defaults to 'normal'. (See add_meta_box() for more details.)
metabox_priority – The priority for your extension』s metabox. Defaults to ''. (See add_meta_box() for more details.)
enabled – true if you want your extension to have a subtab in the Group Adimn area, otherwise false. Defaults to true.
name – The text that appears in the navigation tab for the extension』s Edit screen. Defaults to the general 『name』 value described above.
slug – The string used to create the URL of the admin tab. Defaults to the general 『slug』 value described above.
screen_callback – The function BP will call to display the content of your admin tab. BuddyPress attempts to determine this function automatically; see Methods below. Do not change this value unless you know what you』re doing.
screen_save_callback – The function BP will call after the extension』s admin tab has been saved. BuddyPress attempts to determine this function automatically; see Methods below. Do not change this value unless you know what you』re doing.

access
(optional) Which users can visit the extension』s tab. Possible values: 'anyone', 'loggedin', 'member', 'mod', 'admin' or 'noone'. ('member', 'mod', 'admin' refer to user』s role in the current group.) Defaults to 'anyone' for public groups and 'member' for private groups. Note that the 'mod' level targets only moderators, so if you want to allow access for group moderators and administrators, specify array( 'mod', 'admin' ). Added in BuddyPress 2.1.0 as a more flexible replacement for 'visibility'.
show_tab
(optional) Which users can see the extension』s navigation tab. Possible values: 'anyone', 'loggedin', 'member', 'mod', 'admin' or 'noone'. ('member', 'mod', 'admin' refer to user』s role in the current group.) Defaults to 'anyone' for public groups and 'member' for private groups. Note that the 'mod' level targets only moderators, so if you want to show the tab to group moderators and administrators, specify array( 'mod', 'admin' ). Added in BuddyPress 2.1.0 as a more flexible replacement for 'enable_nav_item'.

 
Methods
BP_Group_Extension has built-in support for a number of different customization methods, which you can override in your extension as needed.
The most prominent of these methods is display(), which BuddyPress uses to generate the output of the plugin』s main tab. Your display() method should echo markup, which BP will automatically place into the proper template.
For the three 「screen」 contexts – 『create』, 『edit』, and 『admin』 – a flexible system allows you to customize the way that your settings screens work, without unnecessary reproduction of code. Your extension should, at minimum, provide the following two methods:

settings_screen()
Outputs the fallback markup for your create/edit/admin screens
settings_screen_save()
Called after changes are submitted from the create/edit/admin screens. This methods should contain the logic necessary to catch settings form submits, validate submitted settings, and save them to the database.

If your extension requires further customization to one or more of the screens, BuddyPress provides the following methods, which are context-specific:

create_screen()
create_screen_save()
edit_screen()
edit_screen_save()
admin_screen()
admin_screen_save()

If your extension contains any of these methods, BP will use them when appropriate. Otherwise, the generic settings_screen() or settings_screen_save() will be used.
 
Examples
Two examples follow. The first is a very simple (though fully functional) implementation of BP_Group_Extension. The second demonstrates some more advanced customizations.

/**
* The bp_is_active( 'groups' ) check is recommended, to prevent problems
* during upgrade or when the Groups component is disabled
*/
if ( bp_is_active( 'groups' ) ) :

class Group_Extension_Example_1 extends BP_Group_Extension {
/**
* Your __construct() method will contain configuration options for
* your extension, and will pass them to parent::init()
*/
function __construct() {
$args = array(
'slug' => 'group-extension-example-1',
'name' => 'Group Extension Example 1',
);
parent::init( $args );
}

/**
* display() contains the markup that will be displayed on the main
* plugin tab
*/
function display( $group_id = NULL ) {
$group_id = bp_get_group_id();
echo 'What a cool plugin!';
}

/**
* settings_screen() is the catch-all method for displaying the content
* of the edit, create, and Dashboard admin panels
*/
function settings_screen( $group_id = NULL ) {
$setting = groups_get_groupmeta( $group_id, 'group_extension_example_1_setting' );

?>
Save your plugin setting here: <input type="text" name="group_extension_example_1_setting" value="" />
'group-extension-example-2',
'name' => 'Group Extension Example 2',
'nav_item_position' => 105,
'screens' => array(
'edit' => array(
'name' => 'GE Example 2',
// Changes the text of the Submit button
// on the Edit page
'submit_text' => 'Submit, suckaz',
),
'create' => array(
'position' => 100,
),
),
);
parent::init( $args );
}

function display( $group_id = NULL ) {
$group_id = bp_get_group_id();
echo 'This plugin is 2x cooler!';
}

function settings_screen( $group_id = NULL ) {
$setting = groups_get_groupmeta( $group_id, 'group_extension_example_2_setting' );

?>
Save your plugin setting here: <input type="text" name="group_extension_example_2_setting" value="" />

Welcome to your new group! You are neat.
Save your plugin setting here: <input type="text" name="group_extension_example_2_setting" value="" />
<?php
}

}
bp_register_group_extension( 'Group_Extension_Example_2' );

endif;

 
Updated Recommendations for BuddyPress 2.6
Please note: Before BuddyPress 2.6, we recommended checking that the `BP_Group_Extension` class existed before calling it. BP 2.6 introduces class autoloading, so the `BP_Group_Extension` class could be autoloaded even if the groups component isn』t active, which causes problems. For this reason, we now recommend that extensions of the `BP_Group_Extension` class be wrapped in an `if ( bp_is_active( 『groups』 ) )` conditional.

主题兼容性 - 自定义

主题兼容性 - 自定义

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.

群组的管理 UI 界面

群组的管理 UI 界面

Codex Home → BuddyPress Plugin Development → Admin UI for Groups
Admin UI for Groups

In BuddyPress 1.7, the Groups Component comes with a great Admin UI that allows Community Administrator to easily manage the created groups (members, settings…) directly from the WordPress backend.
Edit Group Admin Screen
As plugin authors, I think we should enjoy this new area and let the Community Administrator manage the settings of the group extension we might use in our custom component. To do so, I think the best way is to enrich the class we use to extend the BP Group Extension API.
Let』s consider this class as our plugin』s group component, just to refresh our memory about the BP Group Extension API  class and its functions:
class Bp_Plugin_Group extends BP_Group_Extension {
function __construct() {}
function create_screen() {}
function create_screen_save() {}
function edit_screen() {}
function edit_screen_save() {}
function admin_screen() {}
function admin_screen_save() {}
function display() {}
function widget_display() {}
function enable_nav_item() {}
}
bp_register_group_extension( 'Bp_Plugin_Group' );

Adding a meta box for our component in the 「Edit Group」 Admin screen.
When creating your component utilizing the BP Group Extension API you can include the functions below to add a meta box to the Group Admin Page. You can create anything from displaying group content or allowing an admin to update the group meta. The  admin_screen_save() function has an example of getting form parameters out of the $_POST global and saving it into the group meta.
function admin_screen( $group_id ) {
?>

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.

<?php
}
}

bp_member_user_id()

bp_member_user_id()

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

Description
Get the id of the user in a members loop.
If placed outside of a Members loop, it will be empty.
Usage
bp_member_user_id();

Parameters
None.
Example
Source File
bp_member_user_id() is located in bp-members/bp-members-template.php.

活动流 (Activity Streams)

活动流 (Activity Streams)

Codex Home → Administrator Guide → Activity Streams
Activity Streams

Activity streams aggregate all of your activities across a BuddyPress installation.
Enabled BuddyPress components make use of the activity stream component, which means any sort of activity can be recorded. Blogs posts, new friendships and blog comments are among the most popular activities recorded. Furthermore, custom components can also hook into the activity streams, meaning any sort of data can be tracked and recorded.
Following are the the pages rendered in the front end of your site when the Activity Component is activated.

Sitewide Activity Stream
Member Activity Stream
and if the Groups Component is active:
Group Activity Stream

Sitewide Activity Stream
Shows all activities throughout the site or network (if multisite)
Sitewide Activity Stream on BP Default Theme. Click on image to enlarge.
Sections
RSS feed
Selectbox: Show: Everything (default), Updates, Posts, Comments, New Groups, Group Memberships, Friendships, New Members
Status Update – visible to all logged in members only

Text Area box
Post In – Selectbox: Member』s Profile Page or to one of Membes』s Groups
Post Update button

Following buttons/links are visible to logged in members only

Comment button
Reply to Comment link
Favorite button or Remove Favorite button
Delete button – visible only to Super/Site Admin.

Member Activity Stream
Shows the Member』s activities throughout the site.
Sections Member Activity Stream on Twenty Twelve Theme. Click on image to enlarge.
Personal – Shows your activities throughout the site. The status update form and following buttons are visible for logged-in members only.

Selectbox – Show: Everything (default), Updates, Posts, Comments, Friendships, New Groups, or Group Memberships
Status Update – visible to all logged in members only

Text Area box
Post In – Selectbox: Member』s Profile Page or to one of Membes』s Groups
Post Update button

Comment button
Reply to Comment link
Favorite button or Remove Favorite button
Delete button

Mentions – Shows a list of all @mentions for you. The following buttons are visible for logged-in members only.

Selectbox – Show: Everything (default), Updates, Posts, Comments, Friendships, New Groups, or Group Memberships
Comment button
Reply to Comment link
Favorite button or Remove Favorite button

Favorites – Shows a list of all items you clicked as 「Favorite」. The following buttons are visible to the member only.

Selectbox – Show: Everything (default), Updates, Posts, Comments, Friendships, New Groups, or Group Memberships
Comment button
Reply to Comment link
Favorite button or Remove Favorite button
Delete button

Friends – Shows Activity Streams of your friends. The following buttons are visible for logged-in members only.

Selectbox – Show: Everything (default), Updates, Posts, Comments, Friendships, New Groups, or Group Memberships
Comment button
Reply to Comment link
Favorite button or Remove Favorite button

Groups – Shows the Activity Streams of the groups you』ve joined. The following buttons are visible to the member only.

Selectbox – Show: Everything (default), Updates, New Groups, or Group Memberships
Comment button
Reply to Comment link
Favorite button or Remove Favorite button

Group Activity Stream
Shows the specific Group』s Activity Stream which is the default Home tab for any group.
Group Activity Stream on the Twenty Thirteen Theme. Click on image to enlarge.
Sections
RSS feed
Selectbox: Show: Everything (default), Updates, Group Memberships
Status Update – visible to all logged in members only

Text Area box
Post In – Selectbox: Member』s Profile Page or to one of Membes』s Groups
Post Update button

Following buttons/links – visible to logged in group members only

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.

⇒ Related: Activity Stream Management Screens

从旧论坛迁移到 bbPress 2.2+

从旧论坛迁移到 bbPress 2.2+

Codex Home → Getting Started → User Submitted Guides → Migrating from old forums to bbPress 2.2+
Migrating from old forums to bbPress 2.2+

So you』ve been using BuddyPress』 built-in group forums since BuddyPress 1.5, but would like to use the new bbPress plugin to power your forums instead.
Gotcha.  You』ll need to migrate your existing group forum content over to bbPress as well.  Don』t worry!  This is what this article is all about.
Let』s get started!
(1) Backup your database
It』s always wise to backup your database, just in case you need to restore your database backup if migration fails.
(2) Install bbPress 2.3 or higher (if you』re using bbPress 2.2, upgrade to 2.3)
Install bbPress and activate it.
Also make sure you』re using at least BuddyPress 1.6.1.
(3) Remove 「Forums」 page from BuddyPress

In the the WP admin dashboard navigate to 「Settings > BuddyPress「.  Click on the 「Pages」 tab.
Under 「Discussion Forums「, select 「None」 and save.

(4) Disable BuddyPress』 Forums Component

In the WP admin dashboard, navigate to 「Settings > BuddyPress「.  Click on the 「Components」 tab.
Uncheck 「Group Forums (Legacy)」 and save.

(5) Import old forums to bbPress 2

In the WP admin dashboard, navigate to 「Tools > Forums「
(Note: if using Members plugin, you may need to assign forum capabilities to the Administrator Role. Go to Users->Roles.)
Click on the 「Import Forums」 tab.
Under 「Select Platform」, make sure 「bbPress1」 is selected.
For 「Database Name」, 「Database User」, 「Database Password」, use the values as set in wp-config.php.
Under 「Table Prefix」, type in your bbPress prefix. For most users, this will be 「wp_bb_「, however if you used a different table prefix, check your table prefix in bb-config.php and append 「bb_」 to whatever is listed there.
Click on the 「Start」 button.

(6) Repair bbPress 2 forum relationships

In the WP admin dashboard, navigate to 「Tools > Forums「
Check the first option and hit 「Repair「.
Next, check the second option and hit 「Repair「.  Keep doing this until you have completed each option on this page.

(7) Configure bbPress settings for BuddyPress

In the WP admin dashboard, navigate to 「Settings > Forums「
Make sure 「Enable Group Forums」 is checked
Under 「Group Forums Parent「, ensure 「Group Forums」 is selected.

(8) Make 「Forums」 page a sitewide index (optional)

In the WP admin dashboard, navigate to 「Pages「
Find your old BuddyPress forums page (usually named 「Forums」) and edit that page.
In the post content, type in `[bbp-topic-index]`
This will use bbPress』 topic index shortcode to display the most recent topics on our forums page.
For more on bbPress shortcodes, check out the codex article.