在不同的上下文中使用用户的 ID

在不同的上下文中使用用户的 ID

Codex Home → Developer Resources → Playing with the user』s ID in different contexts
Playing with the user』s ID in different contexts

BuddyPress Core is first taking care of the members. As a result, when you write a BuddyPress plugin, there is a very good chance that you』ve got to play with the finest element identifying the users : their ID.
There are two scenarios: the logged in user and the user whose profile is displayed. Thankfully, BuddyPress provides you with two interesting functions to get the user ID for these scenarios. Then there are other specific cases in which you must handle these two main functions with caution. Fortunately again, BuddyPress provides other functions to avoid some 「unwanted」 behaviors.
Steps

Explore the two main functions to get the user』s ID
Discover other useful functions when playing inside some BuddyPress loops
Additionnal resources

Explore the two main functions to get the user』s ID
The function bp_loggedin_user_id() will return you the current logged in user ID that has been set thanks to the BP_Core class using the WordPress function wp_get_current_user().
The function bp_displayed_user_id() will return the ID of the displayed user that has been set thanks to the bp_core_set_uri_globals() function when a profile page is requested. This also means that you can simply know if you are on a profile page by checking if the bp_displayed_user_id() function is not empty. The function bp_is_user(), informing you that you』ve reached a profile page is actually using this check.
When the two are equal, it means that the logged in user is visiting one of his profile pages, the BuddyPress function bp_is_my_profile() is using this equality to inform you if that』s the case.
Let』s begin an example to illustrate the use of the two functions. In the member』s header there』s a template tag BuddyPress is using to display the latest activity the displayed user posted : bp_activity_latest_update(). Like most of BuddyPress template tags, you can filter the returned value to eventually extend it in your plugin. Here, you will simply print user IDs. In the functions.php of your active theme (or in your plugin), you can write :
function bp_plugin_filter_latest_update( $update = '' ) {

$update .= ' logged_in: ' . bp_loggedin_user_id() .' | displayed: ' . bp_displayed_user_id() . '';

return $update;
}

add_filter( 'bp_get_activity_latest_update', 'bp_plugin_filter_latest_update', 10, 1 );

Here』s a screen capture of the result of this 「great extension」
bp_loggedin_user_id() Vs bp_displayed_user_id()
 
As you can see, if your goal is to display information about the user displayed, as shown in this case, you should definitively use bp_displayed_user_id() to avoid having the information of the logged in user on each profile ;). You can also see that 「imath」 is the logged in user as the two functions return the same result. In a user』s profile the bp_loggedin_user_id() will be useful to add some interaction with the user displayed. For instance, the 「Add Friend」 functionality is using the logged in user ID to check if the current user is friend with the displayed user.
Discover other great functions when extending some BuddyPress loops
To go straight to the point, let』s edit our previous code by adding a filter to the bp_member_latest_update() template tag. This function is doing the same thing than the one you saw in first step, except that it runs inside the members loop.
function bp_plugin_filter_latest_update( $update = '' ) {
// In step 1, you saw that bp_displayed_user_id() was the best function to use
// when displaying information about the user in his profile page
$update .= ' displayed: ' . bp_displayed_user_id() . '';

return $update;
}

add_filter( 'bp_get_activity_latest_update', 'bp_plugin_filter_latest_update', 10, 1 );
add_filter( 'bp_get_member_latest_update', 'bp_plugin_filter_latest_update', 10, 1 );

Take a few seconds to check the result of this code in the three parts of this screen capture.
bp_displayed_user_id() and the members loop
 
As you can see, while bp_displayed_user_id() works fine in the member』s header, it is empty in the members loop. So we need to call two functions to the rescue! The first one is a template tag specific to the member component: bp_get_member_user_id() and the second one is the function, you discovered earlier, to check you are on a user』s profile page: bp_is_user(). So, you need to edit the filter this way:
function bp_plugin_filter_latest_update( $update = '' ) {
if( bp_is_user() ) {
$user_id = 'displayed: '. bp_displayed_user_id();
} else {
$user_id = 'get_member_user: '. bp_get_member_user_id();
}
$update .= ' ' . $user_id . '';

return $update;
}

add_filter( 'bp_get_activity_latest_update', 'bp_plugin_filter_latest_update', 10, 1 );
add_filter( 'bp_get_member_latest_update', 'bp_plugin_filter_latest_update', 10, 1 );

If you check the result of this code, you will surely wonder why i』ve changed the color of the ID to red as it seems to solve the issue in the members loop and in the member』s header. To understand why, you simply need to activate the friends navigation of the user』s profile, and here』s what you』ll see:
Members loop in member』s profile : friends
 
「mathieu」, 「imath」 and 「Moi」 have the same ID! Actually, only 「mathieu」 has the good ID as you are visiting his profile. In the friends tab, although you are on a user』s profile, you also are in a members loop displaying user』s friends. So you need to adapt your code to this particular case by also checking the bp_get_member_user_id() before using bp_displayed_user_id().
function bp_plugin_filter_latest_update( $update = '' ) {
if( bp_is_user() && ! bp_get_member_user_id() ) {
$user_id = 'displayed: '. bp_displayed_user_id();
} else {
$user_id = 'get_member_user: '. bp_get_member_user_id();
}
$update .= ' ' . $user_id . '';

return $update;
}

add_filter( 'bp_get_activity_latest_update', 'bp_plugin_filter_latest_update', 10, 1 );
add_filter( 'bp_get_member_latest_update', 'bp_plugin_filter_latest_update', 10, 1 );

Now you can check again: the logged in user』s profile, another profile, the friends tab of a user』s profile and the main members loop, each user has the good ID in the different areas! Bravo
The Activity and the Group members loop also offer their specific functions to get the good user ID in their context :

Activity loop : bp_get_activity_user_id()
Group members loop : bp_get_group_member_id()

Additional resources

wp_get_current_user() in WordPress Codex
the Members loop
the Group Members loop
the Activity loop

主题兼容性

主题兼容性

Codex Home → BuddyPress Theme Development → Theme Compatibility
Theme Compatibility

The pages under this section provide an overview of the BuddyPress theme compatibility layer first introduced in version 1.7.
An overview of theme compatibility is provided as a primer followed by a detailed explanation of the template hierarchy provided and expanded on in BP 1.8 finally we provide a guide page for those of you wanting to upgrade your installs from the now redundant Template Pack Plugin approach to this far more flexible theme compatibility approach.
Theme Compatibility – an introduction.
Theme Compatibility – the template Hierarchy in detail.

群组元查询:使用示例

群组元查询:使用示例

Codex Home → BuddyPress Plugin Development → Group Meta Queries: Usage Example
Group Meta Queries: Usage Example

Since version 1.8, it is possible to filter groups by Metadata. For instance you can add a meta_query parameter to the bp_has_groups() function. To make this possible, BuddyPress uses a built-in WordPress class : WP_Meta_Query (you will find a link to its WordPress codex page at the bottom of this article).
This feature can help plugin developers to extend the way groups are filtered, or query groups to search for a particular group meta your plugin is using. For example, if a plugin is adding a groupmeta to groups when its group component is activated, it can use a group meta query to list all the groups that activated their component.
To illustrate an usage example, you can test the following tutorial. Its goal is to add a new option to the select boxes (Order by filters) that are available on the Groups directory page and on the member』s profile group page. This option will list the groups that the community Administrator featured. This is your roadmap:
Steps

Create a new meta box in the Edit Group Administration screen
Filter bp_ajax_querystring to eventually extend the groups query
Pause: the meta_query parameter in details
Add your new option to select boxes
Additional resources

Create a new meta box in the Edit Group Administration screen
For the purpose of this example, you will need to first create the Administration part to let the community Administrator feature the groups of his choice from the Group Administration screen. To do so, from the functions.php of your active theme, you can add these first lines.
//it's important to check if the Groups component is active
if( bp_is_active( 'groups' ) ) :
/**
* This is a quick and dirty class to illustrate "bpgmq"
* bpgmq stands for BuddyPress Group Meta Query...
* The goal is to store a groupmeta in order to let the community administrator
* feature a group.
* Featured groups will be filterable from the groups directory thanks to a new option
* and to a filter applied on bp_ajax_query_string()
*
* This class is an example, it would be much better to use the group extension API
*/
class bpgmq_feature_group {

public function __construct() {
$this->setup_hooks();
}

private function setup_hooks() {
// in Group Administration screen, you add a new metabox to display a checkbox to featured the displayed group
add_action( 'bp_groups_admin_meta_boxes', array( $this, 'admin_ui_edit_featured' ) );
// Once the group is saved you store a groupmeta in db, the one you will search for in your group meta query
add_action( 'bp_group_admin_edit_after', array( $this, 'admin_ui_save_featured'), 10, 1 );
}

/**
* registers a new metabox in Edit Group Administration screen, edit group panel
*/
public function admin_ui_edit_featured() {
add_meta_box(
'bpgmq_feature_group_mb',
__( 'Featured Group' ),
array( &$this, 'admin_ui_metabox_featured'),
get_current_screen()->id,
'side',
'core'
);
}

/**
* Displays the meta box
*/
public function admin_ui_metabox_featured( $item = false ) {
if( empty( $item ) )
return;

// Using groups_get_groupmeta to check if the group is featured
$is_featured = groups_get_groupmeta( $item->id, '_bpgmq_featured_group' );
?>

<input type="checkbox" id="bpgmq-featured-cb" name="bpgmq-featured-cb" value="1" >

id, 'bpgmq_featured_admin' );
}

function admin_ui_save_featured( $group_id = 0 ) {
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) || empty( $group_id ) )
return false;

check_admin_referer( 'bpgmq_featured_save_' . $group_id, 'bpgmq_featured_admin' );

// You need to check if the group was featured so that you can eventually delete the group meta
$was_featured = groups_get_groupmeta( $group_id, '_bpgmq_featured_group' );
$to_feature = !empty( $_POST['bpgmq-featured-cb'] ) ? true : false;

if( !empty( $to_feature ) && empty( $was_featured ) )
groups_update_groupmeta( $group_id, '_bpgmq_featured_group', 1 );
if( empty( $to_feature ) && !empty( $was_featured ) )
groups_delete_groupmeta( $group_id, '_bpgmq_featured_group' );
}

}

/**
* Let's launch !
*
* Using bp_is_active() in this case is not needed
* But i think it's a good practice to use this kind of check
* just in case 🙂
*/
function bpgmq_feature_group() {
if( bp_is_active( 'groups') )
return new BPGMQ_Feature_Group();
}

add_action( 'bp_init', 'bpgmq_feature_group' );

Once done, if you go in the Groups Administration screen and choose to edit a particular group, you should see a new meta box on the right as shown on this screen capture :
The featured box on the right.
What have you just achieved ?
You』ve created a class that will add a groupmeta named 「_bpgmq_featured_group」 (line 67 of the above code) if the community Administrator activated the checkbox. Now you can use this groupmeta in order to only display/get the featured groups.
Filter bp_ajax_querystring to eventually extend the groups query
In order to do this, you need to add a new hook in your setup_hooks() function (line 18 of the above code). Add this code under line 22:
/* The groups loop uses bp_ajax_querystring( 'groups' ) to filter the groups
depending on the selected option */
add_filter( 'bp_ajax_querystring', array( $this, 'filter_ajax_querystring' ), 20, 2 );

As explained in the comments, this will filter the bp_ajax_querystring() function so that you can extend it to include your meta_query. Note that 「20」 tells WordPress to run this filter at a greater priority than the default one (10). Doing so, you make sure BuddyPress first applies the needed filters before yours. 「2」 tells WordPress your filter waits for 2 arguments. Now, you need to actually create the filter_ajax_querystring() function in your class without forgetting to return a value as a WordPress filter requires one. So after the admin_ui_save_featured() function, but before the end of your class, add these lines:
public function filter_ajax_querystring( $querystring = '', $object = '' ) {

/* bp_ajax_querystring is also used by other components, so you need
to check the object is groups, else simply return the querystring and stop the process */
if( $object != 'groups' )
return $querystring;

// Let's rebuild the querystring as an array to ease the job
$defaults = array(
'type' => 'active',
'action' => 'active',
'scope' => 'all',
'page' => 1,
'user_id' => 0,
'search_terms' => '',
'exclude' => false,
);

$bpgmq_querystring = wp_parse_args( $querystring, $defaults );

/* if your featured option has not been requested
simply return the querystring to stop the process
*/
if( $bpgmq_querystring['type'] != 'featured' )
return $querystring;

/* this is your meta_query */
$bpgmq_querystring['meta_query'] = array(
array(
'key' => '_bpgmq_featured_group',
'value' => 1,
'type' => 'numeric',
'compare' => '='
)
);

// using a filter will help other plugins to eventually extend this feature
return apply_filters( 'bpgmq_filter_ajax_querystring', $bpgmq_querystring, $querystring );
}

What have you just achieved ?
Each time BuddyPress uses the function bp_ajax_querystring() to filter its components, your filter_ajax_querystring() function will be run. As you are targeting the groups loop, the first thing you need to do is to stop the process and return the original ajax query string if the you are not in a groups loop. Hopefully, line 5 of the above code is doing so! If you actually are in a groups loop, then you need to parse the query string in order to build an array that will be easier to manipulate (see line 8 to 19). You will be able to check for the 「type」 argument to make sure the selected option is 「featured」. If not, you need to stop the process and return the original query string (see line 24 to 25). The user requested the 「featured」 groups, it is time you build the object of this tutorial : the Group meta query (see line 27 to 35). Finally, it is a good practice to eventually let other plugins extend your code, that』s why i encourage you to use the apply_filters() function and to include your value and the original one in arguments (line 38).
Pause: the meta_query parameter in details
Your meta_query is a multidimensional array. Each array has a goal. In your case you only need one array as you want to query the group by one Metadata (groupmeta). But if you need to do so on more than one Metadata, then you need a first array to tell BuddyPress what will be the relation to apply. Should the query be filtered by first AND second groupmeta or by first OR second groupmeta. Then as you have a second groupmeta, you need to build a third array to configure the second one. And so on, if you have more than 2 Metadatas to filter the groups with. Your meta_query parameter could have looked this way :
$bpgmq_querystring['meta_query'] = array(
array(
'relation' => 'OR', // Optional, defaults to "AND"
),
array(
'key' => '_bpgmq_featured_group',
'value' => 1,
'type' => 'numeric',
'compare' => '='
),
array(
'key' => '_second_groupmeta',
'value' => 'group',
'compare' => 'LIKE'
)
);

Add your new option to select boxes
Back to your 「featured」 functionality. Your last touch will be to add a featured option to the select box (Order by) of the Groups directory page and the one of the member』s profile group page. If you omit the second one, then you would create a confusion for the user. As BuddyPress is using cookies to remember the way the group was last filtered, if the filter was 「featured」 in Groups directory, then in member』s profile group page the groups will be filtered this way too, but the wrong value would be set in the select box as no correspondence would have been found. So it』s important, you add your option in the two areas. First you need to add these lines in the setup_hooks() function of your class:
/* finally you create your options in the different select boxes */
// you need to do it for the Groups directory
add_action( 'bp_groups_directory_order_options', array( $this, 'featured_option' ) );
// and for the groups tab of the user's profile
add_action( 'bp_member_group_order_options', array( $this, 'featured_option' ) );

Finally, do not forget to add the featured_option() function to your class. So before the end of it insert these lines:
public function featured_option() {
?>

<?php
}

Once done, if you go in the Groups directory or in the member』s profile groups page, you should see a new option in the 「Order by」 select boxes as shown on this screen capture :
The Order By select boxes
What have you just achieved ?
I think you almost built a plugin It might be a good idea to improve this code by using the BP_Group_Extension API.

Additional resources

You can learn more about WP_Meta_Query and its arguments from the WordPress Codex
You can learn more about BP_Group_Extension from its Codex page
You can find the complete class in this gist

更改默认成员个人资料登陆选项卡

更改默认成员个人资料登陆选项卡

Codex Home → Getting Started → User Submitted Guides → Change Default Members Profile Landing Tab
Change Default Members Profile Landing Tab

By default, BuddyPress will load the Activity tab when clicking on a member』s profile link. If you would like to change this default landing tab to something else than the Activity tab you can do so.
Constants such as this are best placed in files that load before BP is fully loaded. Add the code below to either wp-config.php or bp-custom.php (which you would create in your plugin folder as this file does not exist by default). file. When adding the code to wp-config.php, place it after define(『DB_COLLATE』, 」); and before the authentication keys. If you add this line to the bottom of wp-config.php, it will not work.
/**
* Change BuddyPress default Members landing tab.
*/
define('BP_DEFAULT_COMPONENT', 'profile' );

This example will load the 『profile』 tab instead of the 『activity』 screen it』s fairly easy and you can take any other option from the tabs-menu.

bp_activity_add()

bp_activity_add()

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

bp_activity_add() is used to insert new activity items into the database.
Usage
$activity_id = bp_activity_add( $args );

Parameters

$args
An array that describes the activity item that you』re creating. Possible values:

'id'
(optional) Pass a numerical id to update an existing activity item
'action'
An HTML string summarizing the activity item, which is used by the template when displaying the activity item. Usually contains links to related users, groups, etc. E.g., 'Bill created the group TMNT'
'content'
(optional) The string content of the activity item. In the case of a blog post, for example, you might use an excerpt from the post content. In some cases, it』s appropriate for activity items not to have any content for this field – e.g., when a user creates a new group.
'component'
A string denoting the unique 「component」 that this activity item is associated with. BuddyPress components are 『groups』, 『members』, etc. If you are writing a BuddyPress plugin, you might consider having a single component name for all activity in your plugin.
'type'
A string denoting the specific kind of activity being created. This should be more specific than 'component'. For example, when creating a group, BuddyPress posts an activity item with the component 『groups』 and the type 『created_group』. 'type' is used for filtering, as in the 「New Groups」, 「New Blog Posts」, etc dropdown on Activity directories.
'primary_link'
(optional) The primary URL associated with the activity item. BuddyPress uses this value when creating activity RSS feeds, to tell the feed reader where to find the original item. If you omit this value, the fallback value is the permalink page for the single activity item.
'user_id'
(optional) The unique numeric id of the user associated with the activity item. In BuddyPress, the primary use of this value is to filter which items appear on the Activity tab of an individual member』s profile. If the value is omitted, it will default to the id of the currently logged-in user. Note that you can pass 0 for items that may be associated with no user at all.
'item_id'
(optional) The numeric ID of the primary item associated with this activity item. For example, when recording the creation of a group, BuddyPress sets the 'item_id' to the numeric id of the newly created group. This value can be used for filtering.
'secondary_item_id'
(optional) A second numeric ID for further filtering. For example, when recording a new blog comment, BuddyPress sets the 'item_id' to the ID of the blog, and the 'secondary_item_id' to the ID of the comment.
'recorded_time'
(optional) The time the activity is recorded. Should be in GMT, MySQL format. (In PHP, date( 'Y-m-d H:i:s', $time ).) Defaults to the current time.
'hide_sitewide'
(optional) 'hide_sitewide' is used in a few different ways:

To prevent duplicate entries when viewing the sitewide activity stream. For instance, when a new friendship is established, two activity items are created: one with 'user_id' set to the user who sent the request and 'item_id' set to recipient, and the other one vice versa. We need both items so that both users see the item on their own profiles, but it』s not desirable to see both of them on the sitewide stream, so the second one is marked 'hide_sitewide' => true.
To prevent activity items from hidden or private groups from appearing in sitewide activity streams. That is, when an activity item is posted to a non-public group, 'hide_sitewide' is set to false. Then, when viewing the group』s activity stream (which is accessible only to members), BP includes 'hide_sitewide' items; in contrast, the sitewide stream excludes these items.

Thus, 'hide_sitewide' is used simultaneously for preventing duplicates and for privacy. Please be sure you understand the way that 'hide_sitewide' works before attempting to use it for the purposes of privacy in your own plugins.
'is_spam'
(optional) Set to true to mark an item as spam.

Return value
New database row activity ID
Source File
bp_activity_add() is located in bp-activity/bp-activity-functions.php

WordPress 博客

WordPress 博客

Codex Home → BuddyPress Components and Features → WordPress Blogs
WordPress Blogs

Some of the most powerful features of BuddyPress relate to how it enhances your multisite network. Creating a network allows your members to start their own full-powered public or private WordPress blogs. Members can track new posts and comments from public blogs across the network of sites as they are posted in the sitewide activity stream, in the blog owner』s activity stream, and in the blogs directory page. These features help facilitate content discovery and social interaction on your network.
Note: When you are using multisite and blog creation is enabled for users, there』ll be an option for 「I want to create a blog」 when a user registers in your site.
Configuring Site Tracking
In order to use all of the network features of BuddyPress you must first enable the 『Site Tracking』 component under the Components tab in the BuddyPress section of your Network Admin Settings.
Also make sure to check that your 『Site Tracking』 page has been correctly associated under the Pages tab in the BuddyPress section of your Network Admin Settings.
Using Site Tracking
By default the blogs directory page lists the public blogs in your network in the order of the most recently updated to the least recently updated. You can re-order the list by either newest to oldest or alphabetically by selecting either option from the 『Sort Order』 drop down menu. Use the 『Visit Site』 button to visit the homepage of any site from the list. In addition to the site title and 『Visit Site』 button each site shows the time of the last update and a direct link to the site』s latest post.
With 『Site Tracking』 enabled, the Activity Streams of your primary site will also include activities completed on any site on your network which has not enabled privacy for their blog.
Blog Privacy
When a blog selects 「discourage search engines…」 as a privacy setting, the blog won』t show up in activity directories, etc.

将您的插件链接添加到 BuddyPress 会员工具栏菜单

将您的插件链接添加到 BuddyPress 会员工具栏菜单

Codex Home → BuddyPress Plugin Development → Adding Your Plugin』s Link to the BuddyPress Member Toolbar Menu
Adding Your Plugin』s Link to the BuddyPress Member Toolbar Menu

If you』ve added a new navigation item to the single Member page, you may want to add the same link to the Toolbar Menu.
Let』s say you added a tab called 『Dogs』 – this will add the same link to the Toolbar Menu.
Put it in the same file that adds your tab on the Member page.
Or put it in your theme』s functions.php or bp-custom.php or your plugin file.
function your_bp_admin_bar_add() {
global $wp_admin_bar, $bp;

if ( !bp_use_wp_admin_bar() || defined( 'DOING_AJAX' ) )
return;

$user_domain = bp_loggedin_user_domain();
$item_link = trailingslashit( $user_domain . 'dogs' );

$wp_admin_bar->add_menu( array(
'parent' => $bp->my_account_menu_id,
'id' => 'my-account-dogs',
'title' => __( 'Dogs', 'your-plugin-domain' ),
'href' => trailingslashit( $item_link ),
'meta' => array( 'class' => 'menupop' )
) );

// add submenu item
$wp_admin_bar->add_menu( array(
'parent' => 'my-account-dogs',
'id' => 'my-account-dogs-poodles',
'title' => __( 'Poodles', 'your-plugin-domain' ),
'href' => trailingslashit( $item_link ) . 'poodles'
) );
}
add_action( 'bp_setup_admin_bar', 'your_bp_admin_bar_add', 300 );

To remove an item from the Toolbar Menu, for example: activity, place this code in one of the locations mentioned above:
function your_bp_admin_bar_remove() {
global $wp_admin_bar;

$wp_admin_bar->remove_menu( 'my-account-activity' );

}
add_action( 'bp_setup_admin_bar', 'your_bp_admin_bar_remove', 301 );

To find out what should go in the remove_menu argument, look at the browser code generated for the Toolbar. For 『Activity』, it looks like this:

将插件选项添加到 BuddyPress 设置页面

将插件选项添加到 BuddyPress 设置页面

Codex Home → BuddyPress Plugin Development → Adding Plugin』s Options to BuddyPress Settings Page
Adding Plugin』s Options to BuddyPress Settings Page

When writing your plugin you may need to give the community administrator the ability to set some options about it to eventually let him customize some behaviors. When you have a lot options, you would use the WordPress built in add_options_page() or add_submenu_page() functions to create your plugin』s settings page.
But, If your plugin only needs a very few options to be set by the community administrator, it can be interesting to use BuddyPress settings administration screen to add your own fields.
Sections

Choosing the best BuddyPress settings section
Adding your field to bp_main settings section
Adding a new settings section
Additionnal resources

Choosing the best BuddyPress settings section
BuddyPress settings are divided into sections. Depending on your plugins features you can choose to include your setting in the best one. For instance, if your plugin is extending the Groups component, you can choose the 『bp_groups』 section.
Available BuddyPress settings sections
Adding your field to bp_main settings section
The following code illustrates how you could add your setting field to the 『bp_main』 BuddyPress settings section.
/**
* Your settings main function
*/
function bp_plugin_admin_settings() {

add_settings_field(
/* the option name you want to use for your plugin */
'bp-plugin-option-name',

/* The title for your setting */
__( 'BP Plugin Setting', 'bp-plugin-domain' ),

/* Display function */
'bp_plugin_setting_field_callback',

/* BuddyPress settings */
'buddypress',

/* BuddyPress setting section
Here you are adding a field to 'bp_main' section.
As shown on the image, other available sections are :
- if xprofile component is active : 'bp_xprofile',
- if groups component is active : 'bp_groups',
- if legacy forums component is active : 'bp_forums',
- if activity component is active : 'bp_activity'
*/
'bp_main'
);

/* This is where you add your setting to BuddyPress ones */
register_setting(
/* BuddyPress settings */
'buddypress',

/* the option name you want to use for your plugin */
'bp-plugin-option-name',

/* the validatation function you use before saving your option to the database */
'bp_plugin_setting_field_validate'
);

}

add_action( 'bp_register_admin_settings', 'bp_plugin_admin_settings' );

/**
* This is the display function for your field
*/
function bp_plugin_setting_field_callback() {
/* if you use bp_get_option(), then you are sure to get the option for the blog BuddyPress is activated on */
$bp_plugin_option_value = bp_get_option( 'bp-plugin-option-name' );

// you can use the checked() function to easily add a checked attribute to the checkbox if needed
?>
<input id="bp-plugin-option-name" name="bp-plugin-option-name" type="checkbox" value="1" />

<input id="bp-plugin-option-name" name="bp-plugin-option-name" type="checkbox" value="1" />

<?php
}

Here is a screenhot of your custom section in BuddyPress settings.
A custom section for your plugin』s option

Additional resources

add_options_page()
add_submenu_page()
add_settings_section()
add_settings_field()
add_settings_section()