在成员和群组循环中使用 BuddyPress 封面图像

在成员和群组循环中使用 BuddyPress 封面图像

Codex Home → Using BuddyPress Cover Images inside the Member and Group Loops
Using BuddyPress Cover Images inside the Member and Group Loops

Since BuddyPress 2.4 Groups and Member are able to upload Cover Images to be used on the single Group and Member pages. If you would like to use Cover Images when building custom loops you can use the following code to retrieve the cover images whilst inside your loop.
Inside Groups Loops

'groups',
'item_id' => bp_get_group_id(),
));
?>

<img src="">

Inside Members Loops

'members',
'item_id' => bp_get_member_id(),
));
?>

<img src="">

将 「活动」 组件的名称和 slug 更改为其他内容。

将 「活动」 组件的名称和 slug 更改为其他内容。

Codex Home → Developer Resources → User Submitted Guides → Change 「Activity」 component』s name and slug to something else.
Change 「Activity」 component』s name and slug to something else.

Want to change the default BuddyPress 「Activity」 (activity stream) to 「Dashboard」, or 「The Activity Center」, or anything other than 「Activity」?
Here is how:

Create wp-content/plugins/bp-custom.php, and put the following:
?12345678910// change BP /activity/ slug to /dashboard/define( 'BP_ACTIVITY_SLUG', 'dashboard' ); // Change the name for the "Activity" tab to "Dashboard", // and reference the newly defined slug /dashboard/function bpcodex_rename_profile_tabs() {    // Change "Activity" to "Dashboard"    buddypress()->members->nav->edit_nav( array( 'name' => __( 'Dashboard', 'textdomain' ) ), 'dashboard' );}add_action( 'bp_actions', 'bpcodex_rename_profile_tabs' );

You may also want to change all labels associated by following these instructions: 「Customizing Labels, Messages, and URLs「.

注册 (Registration)

注册 (Registration)

Codex Home → Member Guide → Registration
Registration

1. Click on the 「Register」 link. Some sites use 「Join Us」, 「Sign Up」, or other terminology.

2. Fill in the forms. Some sites allow you to create your own blog. You can fill up the form to create one now, or choose to create a new blog later.
3. Click on the 「Complete Sign Up」 button.
4. Check Your Email To Activate Your Account! You have successfully created your account. To begin using this site you will need to activate your account via the email we have just sent to your address.
5. Wait for a minute or so if you don』t see the email to activate your account. If the activation email doesn』t show up in your inbox, check your 「Spam」 folder just in case it was redirected by your email client.
6. Click on the activation link in the email. This will bring you to the homepage of the site.
7. Fill up the rest of your profile information if you only completed the 「required」 fields during registration. Or, begin exploring the Sitewide Activity, Groups you can join, or other Members you can befriend, and many more.

⇐ Back to Member Guide

电子邮件 (Emails)

电子邮件 (Emails)

Codex Home → Emails
Emails

BuddyPress 2.5 introduces a customizable email API. After updating or installing BuddyPress 2.5 you will find a new top level admin menu item 「Emails」. Under this menu item is where you can customize, edit or add new emails.
Previous versions of BuddyPress would send emails but there was no UI exposed to edit the content of the email or no user friendly way to create new emails. Let』s take a look at the admin UI for creating, editing and customizing Emails.
 
Admin Email List
Emails are a CPT. They are edited and created very much like posts and pages.

 
Edit Email
Editing an Email is very much like editing a post or page. The main difference here is the use of  tokens. Tokens are variable strings that will get replaced with dynamic content when the email gets sent. Read this page for more info on the core tokens provided.
The 「Situations」 meta box is for selecting the action that triggers the sending of an email. Note that not all tokens are available for every situation trigger. Read the tokens documentation page to learn which tokens will work for your selected situation.

 
Email Design
Emails uses the WordPress customizer to edit the look and feel of your emails. The default colors are BuddyPress Orange but you can easily change them to suit your sites branding. Access the email customizer from the 「Email」 admin menu. Click the 「Customize」 link and it will open the email customizer.

 
There are three sections that can be  edited; header, body and footer. Clicking on a section on the left will open the sub panel to change settings that will customize the email.

 
Customize Header
Options to edit the email header also includes the email background.

 
Customize Body

 
Customize Footer

 
Customize Email Template
BuddyPress ships with a default email template:
/wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/assets/emails/single-bp-email.php
If the customization options above are not enough, you can override this template by copying the above file to your theme:
/wp-content/themes/YOUR-THEME/buddypress/assets/emails/single-bp-email.php
If you do not want to override the template, the default email template does have a few hooks that can be used:
https://buddypress.trac.wordpress.org/browser/tags/2.5.0-rc1/src/bp-templates/bp-legacy/buddypress/assets/emails/single-bp-email.php?marks=143-148,152-157,192-197,205-210#L121
 
Filter From Address and Name
If you have been using the wp_mail_from or wp_mail_from_name WP filter, then you need to switch to this:
add_action( 'bp_email', function( $email_type, $email_obj ) {
$email_obj->set_from( "[email protected]", "Custom Website Name" );
}, 10, 2 );
 
Disable BP Email
If you already have an existing HTML email template solution in place and want to completely disable BuddyPress』 email template system, add the following to wp-content/plugins/bp-custom.php:
add_filter( 'bp_email_use_wp_mail', '__return_true' );

BP_Attachment

BP_Attachment

Codex Home → BuddyPress Plugin Development → BP_Attachment
BP_Attachment

Note: This guide is for use with BuddyPress 2.3+.
Version 2.3.0 introduced the BuddyPress Attachments API. In the first place, we use it to manage particular user submitted files: their profile photo or the profile photo of the group the user is an admin/creator of.
A BuddyPress attachment is a file you 「attach」 to a BuddyPress object. For instance, the group』s profile photo is an image file 「attached」 to the ID of the group and used to represent it in BuddyPress loops.
An important piece of the API is the BP_Attachment class. You can extend it to be ready to receive user submitted files, validate these submissions and finally write the files in a /wp-content/uploads『s subdirectory you define.

A closer look to the following BP_Attachment methods.
<?php
/**
* BP Attachment class
*/
abstract class BP_Attachment {
public function __construct( $args = '' ) {}
public function set_upload_dir() {}
public function create_dir() {}
public function upload( $file, $upload_dir_filter = '' ) {}
public function upload_dir_filter() {}
public function validate_upload( $file = array() ) {}
}

The __construct() method
This is the method you will use to define all the needed parameters to manage the user uploads for your plugin. To do so, you can directly set these parameters inside the __construct() method of your class.
'custom_upload',
'file_input' => 'custom_file',
'original_max_filesize' => 512000,
'allowed_mime_types' => array( 'png', 'jpg' ),
'upload_error_strings' => array(
9 => __( 'Your file name must contain the term 「custom」', 'custom-domain' ),
),
'base_dir' => 'custom',
) );
}
}

endif;

Or you can pass an array containing these specific parameters when you instantiate your class.
'custom_upload',
'file_input' => 'custom_file',
'original_max_filesize' => 512000,
'allowed_mime_types' => array( 'png', 'jpg' ),
'upload_error_strings' => array(
9 => __( 'Your file name must contain the term 「custom」', 'custom-domain' ),
),
'base_dir' => 'custom',
)
);

Setting the parameters for your class

$action
This parameter is required. It』s a string carrying the upload action used when uploading a file, the $_POST['action'] must be set to this parameter.
$file_input
This parameter is required. It』s a string to inform about the name attribute used in the file input of your upload form.
$original_max_filesize
This parameter is optional. It』s an integer informing about the max upload filesize allowed in bytes, it defaults to wp_max_upload_size()
$allowed_mime_types
This parameter is optional. It』s an array informing about the list of allowed extensions, it defaults to WordPress allowed ones get_allowed_mime_types(). NB: in multisite configurations, allowed mime types are restricted to the upload_filetypes site option (See check_upload_mimes() in related resources).
$upload_error_strings
This parameter is optional. It』s an array containing the feedback messages for your custom validation rules. The index of the array is starting at nine because BuddyPress is already taking care of some feedback messages (index 0 to 8) in case an error occured during the upload process.
$base_dir
This parameter is optional. It』s a string to inform about the /wp-content/uploads『s subdirectory to write the uploaded files to.

Depending on your needs, you can simply use the __construct() method and its required parameters or override some other BP_Attachment methods to match more advanced needs. We advise you to define a $base_dir to separate your attachments from WordPress ones. Below is a very basic example of use.

<input type="hidden" name="action" id="action" value="" />

<input type="file" name="" id="custom-file-id" />
<input type="submit" name="upload" id="upload" value="" />

__construct()
*
* eg:
* - $action 'custom_upload',
* - $file_input 'custom_file'
* - $base_dir '/wp-content/uploads/custom'
*/
$result = $custom_attachment->upload( $_FILES );

// Define a custom redirect inside a BuddyPress page
$redirect = trailingslashit( bp_loggedin_user_domain() );

/**
* If there's an error during the upload process
* $result will be an array containing the error message
*/
if ( ! empty( $result['error'] ) ) {

// Add a feedback message containing the upload error
bp_core_add_message( $result['error'], 'error' );

// Safely redirect the user
bp_core_redirect( $redirect );

/**
* If the file was successfully uploaded
* $result will be an array containing the path to the file,
* its url and its mime type.
*
* array {
* $file Absolute path to the file
* $url Absolute url to the file
* $type the file mime type
* }
*/
} else {
// Add a feedback containing the success message
bp_core_add_message( __( 'Bingo! file successfully uploaded., 'custom-domain' ) );

/**
* In our example, the result could be:
* array {
* 'file' => ABSPATH . 'wp-content/uploads/custom/custom_image.png',
* 'url' => 'http://site.url/wp-content/uploads/custom/custom_image.png',
* 'type' = 'image/png',
* }
*/

// Safely redirect the user
bp_core_redirect( $redirect );
}
}

The set_upload_dir() method
This method will set the $upload_path (path to your upload dir) and $url (url of your upload dir) properties of your class. You shouldn』t need to override it from your extending class. If you defined a $base_dir in your __construct() method, then it will also create this specific dir using the create_dir() method.
The create_dir() method
This method will create the $base_dir in /wp-content/uploads to write the uploaded files to, if you defined this particular parameter in your __construct() method. If you need to do some specific actions when creating your base dir, you can override this method. For instance, you could add an .htaccess file to protect your files in Apache servers. Below is a way to achieve this:
'custom_upload',
'file_input' => 'custom_file',
'base_dir' => 'custom',
) );
}

public function create_dir() {
// Create the dir using the BP_Attachment->create_dir() method
$created = parent::create_dir();

// if directory was created, create the .htaccess file
if ( $created && ! file_exists( $this->upload_path .'/.htaccess' ) ) {
// Define the rule to protect uploads dir in Apache servers.
$rules = array( 'Order Allow,Deny','Deny from all' );

// make sure to load the file where the insert_with_markers() function is located
require_once( ABSPATH . '/wp-admin/includes/misc.php' );

// create the .htaccess file
insert_with_markers( $this->upload_path .'/.htaccess', 'Custom Attachments', $rules );
}
}
}

endif;

The upload() method
This method will upload the file into the $upload_path directory defined within your class. You shouldn』t need to override it from your extending class. Just before using the WordPress function wp_handle_upload(), The method is including a filter 'bp_attachment_upload_overrides' to edit/add some upload $overrides if you need to.

$file
This parameter is required. It』s an array, the $_FILES superglobal.
$upload_dir_filter
This parameter is optional. It contains the callback function name to override the BP_Attachment included filter that is setting the specified $base_dir (see your __construct() method) as the destination folder for the uploaded files (see the upload_dir_filter() method). If you define this parameter, you』ll need to create a specific function to filter 'upload_dir' (see wp_upload_dir() in related resources).

upload_dir_filter() method
If you haven』t specified the $upload_dir_filter parameter when uploading your file and if you set a $base_dir parameter from your __construct() method, this function will take care of filtering the WordPress upload dir to use your specific $upload_path. If you need to add some specific organisation into your upload dir, you can override this method like this.
'custom_upload',
'file_input' => 'custom_file',
'base_dir' => 'custom',
) );
}

/**
* Optional, use it if you need to do some custom actions in the upload directory
* eg: add a subdirectory for each user ids
*/
public function upload_dir_filter() {
/**
* You can use the BP_Attachment->upload_dir_filter() function to get
* your custom upload dir data
*
* if you defined the $base_dir parameter in the construct method
*
* you will get: array(
* 'path' => 'site_path/wp-content/uploads/custom',
* 'url' => 'site_url/wp-content/uploads/custom',
* 'subdir' => false,
* 'basedir' => 'site_path/wp-content/uploads/custom',
* 'baseurl' => 'site_url/wp-content/uploads/custom',
* 'error' => false
* );
*/
$upload_dir_data = parent::upload_dir_filter();

if ( ! is_user_logged_in() ) {
return $upload_dir_data;
}

/**
* Or you can dynamically set your custom upload dir data
* eg: /wp-content/uploads/custom/1
*/
return array(
'path' => $this->upload_path . '/' . bp_loggedin_user_id(),
'url' => $this->url . '/' . bp_loggedin_user_id(),
'subdir' => '/' . bp_loggedin_user_id(),
'basedir' => $this->upload_path . '/' . bp_loggedin_user_id(),
'baseurl' => $this->url . '/' . bp_loggedin_user_id(),
'error' => false
);
}
}

endif;

The validate_upload() method
If the $original_max_filesize parameter was set in your __construct() method, the file size will be checked using the BP_Attachment->validate_upload() method. This method can be overriden within your custom class if you need to add some custom file validation rules. NB: If you plan on using custom validation rules, don』t forget to create the corresponding custom error messages using the $upload_error_strings parameter from your __construct() method.

$file
This parameter is required. It』s an array containing the temporary file attributes (before it has been moved).

The following example checks the name of the uploaded file contains 「custom」.
'custom_upload',
'file_input' => 'custom_file',
'base_dir' => 'custom',
'upload_error_strings' => array(
9 => __( 'Your file name must contain the term 「custom」', 'custom-domain' ),
),
) );
}

/**
* Optional, use it if you need to add some custom validation rules
* in our example: the file must contain "custom" in its name
*/
public function validate_upload( $file = array() ) {
/**
* You can use the BP_Attachment->validate() function to check
* for your max upload size
*/
$file = parent::validate_upload( $file );

// Bail if already an error
if ( ! empty( $file['error'] ) ) {
return $file;
}

/**
* The file name is not containing 'custom', add a reference
* to the index of your $upload_error_strings array containing the
* feedback message
*/
if ( false === strpos( $file['name'], 'custom' ) ) {
$file['error'] = 9;
}

return $file;
}
}

endif;

A sample plugin to add Attachments to private messages
To illustrate how to extend the BP_Attachment class, this sample plugin (Do not use it on a production server!) is using what we』ve learnt in the previous section to allow users to 「attach」 a file to their private messages.

This is the Custom_Attachment class for the sample plugin
This is the function to handle uploads for the sample plugin

The file input in the messages compose screen
The plugin will add a new file input in the Compose view of private messages component and run some custom validation rules before 「attaching」 the file to the ID of a private message.
The link to download the file in the messages view screen

Related Resources

wp_max_upload_size() WordPress Code Reference page
get_allowed_mime_types() WordPress Codex page
check_upload_mimes() WordPress Codex page
wp_handle_upload() WordPress Codex page
wp_upload_dir() WordPress Codex page
The sample plugin

电子邮件令牌

电子邮件令牌

Codex Home → Emails → Email Tokens
Email Tokens

With the release of BuddyPress 2.5.0, site administrators can easily edit the contents of email notifications. These notifications use 「tokens,」 which are generic placeholders that are replaced with specific data when a single message is generated and sent.
We』ve created some general-purpose tokens that are available for use in any message, like the display name of the recipient (tokenized as {{recipient.username}}). Because messages sent in different contexts need different information to be meaningful, each message also has access to more specific tokens. Take the message sent when a member is invited to a group, for instance. It includes tokens that allow you to include the group』s name, the display name and member profile of the member who extended the invitation, and a link to the recipient』s 「manage invitations」 screen. The tokens available in each specific message are listed below.
Finally, some tokens are wrapped in two sets of curly braces, like {{site.description}}, while other are wrapped in three sets, like {{{site.url}}}. Tokens wrapped in three braces are treated differently (they are not escaped on merging) which is critical for including working links, for instance. So, keep track of how many braces the token you』re including needs to work properly.
 
Global tokens available in all messages

{{site.admin-email}}
Email address of the site administrator.

{{{site.url}}}
Value of home_url().

{{site.description}}
Value of 『blog description』.

{{site.name}}
Value of 『blog name』.

{{recipient.email}}
Email address of recipient.

{{recipient.name}}
Display name of recipient.

{{recipient.username}}
Username (login) of recipient.

{{{unsubscribe}}}
Link to the recipient』s email notifications settings screen in his or her user profile.

{{email.subject}}
The subject line of the email.

 
Activity
[{{{site.name}}}] {{poster.name}} mentioned you in a status update
Situation: Recipient was mentioned in an activity update.

{{usermessage}}
The content of the activity update.

{{{mentioned.url}}}
Permalink to the activity item.

{{poster.name}}
Display name of activity item author.

{{receiver-user.id}}
The ID of the user who is receiving the update.

 
[{{{site.name}}}] {{poster.name}} mentioned you in an update
Situation: Recipient was mentioned in a group activity update.

{{usermessage}}
The content of the activity update.

{{{mentioned.url}}}
Permalink to the activity item.

{{poster.name}}
Display name of activity item author.

{{group.name}}
Name of the group housing the activity update. Empty if not in a group.

{{receiver-user.id}}
The ID of the user who is receiving the update.

 
[{{{site.name}}}] {{poster.name}} replied to one of your updates
Situation: A member has replied to an activity update that the recipient posted.

{{usermessage}}
The content of the comment.

{{poster.name}}
Display name of comment author.

{{{thread.url}}}
Permalink to the original activity item thread.

{{comment.id}}
The comment ID.

{{commenter.id}}
The ID of the user who posted the comment.

{{original_activity.user_id}}
The ID of the user who wrote the original activity update.

 
[{{{site.name}}}] {{poster.name}} replied to one of your comments
Situation: A member has replied to a comment on an activity update that the recipient posted.

{{usermessage}}
The content of the comment.

{{poster.name}}
Display name of comment author.

{{{thread.url}}}
Permalink to the original activity item thread.

{{comment.id}}
The comment ID.

{{parent-comment-user.id}}
The ID of the user who wrote the immediate parent comment.

{{commenter.id}}
The ID of the user who posted the comment.

 
Members
[{{{site.name}}}] Activate {{{user-site.url}}}
Situation: Recipient has registered for an account and site.

{{{activate-site.url}}}
Link to the site』s membership and new blog activation page.

{{{user-site.url}}}
The link to the new blog created by the user.

{{title}}
The new blog』s title.

{{domain}}
The new blog』s domain.

{{path}}
The new blog』s path.

{{key_blog}}
The activation key created in wpmu_signup_blog().

{{user.email}}
The new user』s email address. (Dupes recipient.email?)

 
[{{{site.name}}}] Activate your account
Situation: Recipient has registered for an account.

{{{activate.url}}}
Link to the site』s membership activation page, including the user』s activation key.

{{key}}
Activation key.

{{user.email}}
The new user』s email address. (Dupes recipient.email?)

{{user.id}}
The new user』s ID.

 
[{{{site.name}}}] New friendship request from {{initiator.name}}
Situation: A member has sent a friend request to the recipient.

{{{friend-requests.url}}}
Link to the user』s friendship request management screen.

{{{initiator.url}}}
The initiator』s user profile.

{{initiator.name}}
Display name of the initiator.

{{friendship.id}}
ID of the friendship object.

{{friend.id}}
ID of the request recipient.

{{initiator.id}}
ID of the user who initiated the request.

 
[{{{site.name}}}] {{friend.name}} accepted your friendship request
Situation: Recipient has had a friend request accepted by a member.

{{{friendship.url}}}
Link to the request recipient』s user profile.

{{friend.name}}
Display name of the request recipient.

{{friendship.id}}
ID of the friendship object.

{{friend.id}}
ID of the request recipient.

{{initiator.id}}
ID of the user who initiated the request.

 
[{{{site.name}}}] Verify your new email address
Situation: Recipient has changed their email address.

{{{verify.url}}}
Link used to verify the new email address.

{{displayname}}
Display name of recipient (Dupes recipient.name?)

{{old-user.email}}
The user』s previous email address.

{{user.email}}
The user』s new email address.

 
Private Messages
{{{site.name}}}] New message from {{sender.name}}
Situation: Recipient has received a private message.

{{usersubject}}
The subject of the message.

{{usermessage}}
The content of the message.

{{{message.url}}}
Link to the message thread.

{{sender.name}}
Display name of the message sender.

 
Groups
[{{{site.name}}}] Group details updated
Situation: A group』s details were updated.

{{changed_text}}
Text describing the details of the change.

{{{group.url}}}
Link to the group.

{{group.name}}
Name of the group.

{{group.id}}
ID of the group.

 
[{{{site.name}}}] Membership request for group: {{group.name}}
Situation: A member has requested permission to join a group.

{{group.name}}
Name of the group.

{{{group-requests.url}}}
Link to the group』s membership requests management screen.

{{requesting-user.name}}
Display name of the user who is requesting membership.

{{{profile.url}}
User profile of the user who is requesting membership.

{{admin.id}}
ID of the group admin who is receiving this email.

{{group.id}}
ID of the group.

{{membership.id}}
ID of the membership object.

{{requesting-user.id}}
ID of the user who is requesting membership.

 
Title: [{{{site.name}}}] Membership request for group 「{{group.name}}」 accepted
Situation: Recipient had requested to join a group, which was accepted.

{{group.name}}
Name of the group.

{{{group.url}}}
Link to the group.

{{group.id}}
ID of the group.

{{requesting-user.id}}
ID of the user who is requesting membership.

 
Title: [{{{site.name}}}] Membership request for group 「{{group.name}}」 rejected
Situation: Recipient had requested to join a group, which was rejected.

{{group.name}}
Name of the group.

{{{group.url}}}
Link to the group.

{{group.id}}
ID of the group.

{{requesting-user.id}}
ID of the user who is requesting membership.

 
[{{{site.name}}}] You have been promoted in the group: 「{{group.name}}」
Situation: Recipient』s status within a group has changed.

{{group.name}}
Name of the group.

{{{group.url}}}
Link to the group.

{{promoted_to}}
String describing new group responsibilitied. Possible values: 『an administrator』 or 『a moderator』.

{{group.id}}
ID of the group.

{{user.id}}
ID of the promoted user.

 
[{{{site.name}}}] You have an invitation to the group: 「{{group.name}}」
Situation: A member has sent a group invitation to the recipient.

{{group.name}}
Name of the group.

{{{group.url}}}
Link to the group.

{{inviter.name}}
Inviter』s display name wrapped in a link to that user』s profile.

{{{inviter.url}}}
Link to the profile of the user who extended the invitation.

{{{invites.url}}}
Link to the recipient』s invitation management screen.

BuddyPress 配套样式表

BuddyPress 配套样式表

Codex Home → BuddyPress Theme Development → BuddyPress Companion Stylesheets
BuddyPress Companion Stylesheets

What are Companion styles and why?
As of BuddyPress 2.3 we have introduced a process to enqueue stylesheets that support specific WordPress bundled default themes. BuddyPress stylesheets are now available for the following:

Twenty Sixteen Theme
Twenty Fifteen Theme
Twenty Fourteen Theme
Twenty Thirteen Theme
Twenty Twelve Theme (for BP 2.5.0)

The motivation for doing this was to ensure that we presented BuddyPress in the best possible light when activated out of the box running under one of the WordPress twenty-something themes, as it afforded us the ability to style specific BP elements to work within those themes and deal with any possible conflicting styles.
These stylesheets are referred to as 『Companion』 ones as they run in addition to the default BP stylesheet rather than as a replacement, they compliment our existing stylesheet, providing theme specific enhancements and minor correction where the themes styles affect the BP elements. as these sheets are targetting a specific theme we are also then able to look with more detail at such aspects as breakpoints, providing a better responsive experience.
Released with BP 2.3
For the initial task we are releasing two stylesheets to support WP TwentyFifteen and TwentyFourteen themes, with the intention that in subsequent BP releases we』ll tackle the older themes working backwards, twentythirteen being already underway but slightly too late to make the cut for BP 2.3 inclusion. In future we will release a supporting companion stylesheet for new WP themes as they are released e.g Twentysixteen.
The Process
The process for including these styles, although new, follows the tried and tested principles BP already uses for it』s 『Theme Compatibility』 implementation.
We introduced for the first time pre-processor support in the creation of our .css/rtl.css files writing the initial stylesheet rules as twentyfiften.scss as it was felt that it was time we updated our approaches to better fit with current practises.
In buddypress-functions.php in the bp-template/bp-legacy/ directory where we currently run our enqueue_styles() function for stylesheets we now have a blocks that enqueue a stylesheet based on the theme name.
Running twentyfifteen as the site theme would now enqueue a file with the handle 『bp-twentyfifteen-css』
For child themes it was decided that they should inherit the styles too so we enqueue the companion stylesheet using get_template() to create a path that always points to the parent theme.
Overloading & customizing the styles
As we have followed the established principles for theme compatibility and hierarchical support modifying or customizing these sheets is extremely simple:
If you are running for example twentyfifteen but have created a child theme for custom styles and templates then the same process for theme compatibility applies, creating a directory named buddypress/ or community/ in your child theme root directory and then adding a directory for css/ and either copying the existing twentyfifteen.css over or creating a new file named the same would be loaded and used in preference to the existing core file.
Existing styled Themes
If you are already using a WP twenty-* child theme and don』t require these new styles applied automatically to the BuddyPress pages &emdash; maybe they clash with your existing customizations &emdash; then you can simply dequeue the stylesheet in your child theme』s functions file.
function my_dequeue_bp_companion_stylesheet() {
// Change 'twentyfifteen' to the WordPress theme you are using
wp_dequeue_style( 'bp-twentysixteen' );
}
add_action( 'bp_enqueue_scripts', 'my_dequeue_bp_companion_stylesheet', 20 );

Alternatively, `bp-twentyfifteen`, `bp-twentyfourteen`, `bp-twentythirteen`, etc.

自定义电子邮件

自定义电子邮件

Codex Home → Emails → Custom Emails
Custom Emails

BuddyPress only includes emails for BuddyPress core functionality. Blog posting is not part of BuddyPress, but it could be an integral part of your community. Let』s look at an example to send an email to a blog post author when a user comments on their post.
Note: This requires the BP Email API which is only available in BP 2.5.0+.
Email Post Type
BuddyPress emails are a Custom Post Type so adding emails is similar to creating posts and pages. The function below will programmatically add a post and add the correct taxonomy. Taxonomies are used to connect the email with the correct Situation or action that will trigger the sending of the email. Hook your email creation to bp_core_install_emails – this insures that it will be created if you need to reset emails using the 「Re-install emails」 tool in the admin tools. You can call the function directly as part of activating your plugin via register_activation_hook.
function codex15766_custom_email_message() {

// Do not create if it already exists and is not in the trash
$post_exists = post_exists( '[{{{site.name}}}] New post comment.' );

if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' )
return;

// Create post object
$my_post = array(
'post_title' => __( '[{{{site.name}}}] New post comment.', 'buddypress' ),
'post_content' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // HTML email content.
'post_excerpt' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // Plain text email content.
'post_status' => 'publish',
'post_type' => bp_get_email_post_type() // this is the post type for emails
);

// Insert the email post into the database
$post_id = wp_insert_post( $my_post );

if ( $post_id ) {
// add our email to the taxonomy term 'post_received_comment'
// Email is a custom post type, therefore use wp_set_object_terms

$tt_ids = wp_set_object_terms( $post_id, 'post_received_comment', bp_get_email_tax_type() );
foreach ( $tt_ids as $tt_id ) {
$term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
'description' => 'A member comments on a posts',
) );
}
}

}
add_action( 'bp_core_install_emails', 'codex15766_custom_email_message' );

Send Email
For the next step, hook an action to wp_insert_comment to get the comment data and then send the post author an email. In this function, you create the tokens to parse out in the email before sending. The tokens array can be anything but you usually want to keep it personal to the recipient.
bp_send_email() takes three arguments:

the taxonomy term you set up in the the CPT above
the recipients user ID
the array of tokens to parse in the title, body and excerpt of the email

function codex15766_comment_inserted( $comment_id, $comment_object ) {

if ( $comment_object ) {
// get the post data
$post = get_post( $comment_object->comment_post_ID );
// add tokens to parse in email
$args = array(
'tokens' => array(
'site.name' => get_bloginfo( 'name' ),
'commenter.name' => $comment_object->comment_author,
),
);
// send args and user ID to receive email
bp_send_email( 'post_received_comment', (int) $post->post_author, $args );
}
}
add_action( 'wp_insert_comment','codex15766_comment_inserted', 99, 2 );

将自定义选项卡添加到群组目录

将自定义选项卡添加到群组目录

Codex Home → Add Custom Tab to Groups Directory
Add Custom Tab to Groups Directory

This is an example of how to add a custom tab to the Groups Directory.
And call a custom template when that tab is clicked.
The same approach can be used to add a custom tab to the Members Directory.
The tab will be called Custom and it will load a template called groups-custom.php.
?12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// add Custom tab on Groups Pagefunction asdf_groups_custom_tab() {     if ( bp_is_current_action( 'custom' ) )         return;     $button_args = array(        'id'         => 'groups-custom',        'component'  => 'groups',        'link_text'  => __( 'Custom', 'buddypress' ),        'link_title' => __( 'Custom', 'buddypress' ),        'link_class' => 'group-custom no-ajax',        'link_href'  => trailingslashit( bp_get_groups_directory_permalink() . 'custom' ),        'wrapper'    => false,        'block_self' => false,    );           ?>    

  •      0,            'post_title'     => 'Groups Custom',            'post_author'    => 0,            'post_date'      => 0,            'post_content'   => '',            'post_type'      => 'page',            'post_status'    => 'publish',            'is_page'        => true,            'comment_status' => 'closed'        ) );    }     public function create_content() {        return bp_buffer_template_part( 'groups/groups-custom', null, false );    } }
    This example assumes that the groups-custom.php template is in your theme at this location:
    .../wp-content/themes/your-theme/buddypress/groups/groups-custom.php
    If you want to load the template from a plugin, you need to register the location of the template:
    ?12345678910111213// add path to plugin templatesfunction asdf_register_template_location() {    return dirname( __FILE__ ) . '/templates/';}  function asdf_template_start() {     if( function_exists( 'bp_register_template_stack' ) )        bp_register_template_stack( 'asdf_register_template_location' ); }add_action( 'bp_init', 'asdf_template_start' );
    More info about using BP Theme Compat in plugins.