註冊 (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

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

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 → Member Guide → Settings → Delete Account
Settings → Delete Account

This is where you can delete your account in the site, if account deletion was enabled by the Site Admin. Note that deleting your account will delete all the content you have created in the site. Those will be completely irrecoverable.

⇐ Previous: Settings → Profile Visibility
⇐ Back to Member Guide

WordPress 版本相容性

WordPress 版本相容性

Codex Home → Getting Started → WordPress version compatibility
WordPress version compatibility

BuddyPress shines brightest when run on the newest available version of WordPress – we optimize for the latest and greatest. For this reason, the BuddyPress team strongly recommends that all WordPress installations be kept up to date. However, we strive to maintain support for a number of legacy WordPress versions – generally, four or five major versions.
Near the beginning of each development cycle, we reassess BuddyPress』s minimum required WP version. Our rough guidelines are as follows:

If a WordPress version became obsolete over a year ago, it』s a candidate for removal. See https://wordpress.org/news/category/releases/ for a list of WP release dates.
If a WordPress version』s use slips below 5% of all WP installations, it』s a strong candidate for removal. See https://wordpress.org/about/stats/ for information about WordPress version usage.

What do we mean when we say that BP 「supports」 a given version of WordPress? Roughly:

BuddyPress should run error-free (ie, without fatal errors or PHP notices) on the WP version.
If a new version of BP includes a feature that requires a very recent version of WordPress, the feature should be gracefully disabled on earlier WP versions.
The WP version will be included in our automated testing builds.

By extension: When we 「drop support」 for a version of WordPress, it means we stop including it in our builds, stop answering support questions related to that specific WP version, and stop putting function_exists() checks (and the like) targeting that version when building new BP features. Dropping support does not mean that we will actively try to break older versions of WP

⇐ Getting Started

BuddyPress 封面影象

BuddyPress 封面影象

Codex Home → BuddyPress Theme Development → BuddyPress Cover Images
BuddyPress Cover Images

Note: This guide is for use with BuddyPress 2.4+. 
The Cover Images feature uses the BP Theme Compat API to maximize its compatibility with most WordPress themes. It allows members of your community, and groups administrators to upload an image to prettify their headers.

Themes using the BP Theme Compat API
A Group』s Cover Image in the TwentySixteen theme.
 
This is the most common case. The BP Theme Compat API is dynamically registering Cover Images for your members (if the the xProfile component is active) and/or your groups (if the Groups component is active) by:

Adding the feature to the features property of the component (buddypress()->profile->features and/or buddypress()->groups->features)
Adding the feature settings to the features property of the Theme Compat theme in use (BP Legacy in most cases: buddypress()->theme_compat->theme->features).

Although the BP Theme Compat API should make sure Cover Images are looking awesome within your theme, you may need to edit some of the feature』s settings to refine its appearance in your theme. To do so, you can use the following filters :

bp_before_members_cover_image_settings_parse_args for the members Cover Images
bp_before_groups_cover_image_settings_parse_args for the groups Cover Images

Here is an example to change the width and the height of the Cover Image for the members component:
function your_theme_xprofile_cover_image( $settings = array() ) {
$settings['width'] = 1170;
$settings['height'] = 250;

return $settings;
}
add_filter( 'bp_before_members_cover_image_settings_parse_args', 'your_theme_xprofile_cover_image', 10, 1 );

Here is an example to add a default image to use for Groups Cover Images:
function your_theme_xprofile_cover_image( $settings = array() ) {
$settings['default_cover'] = 'http://site.url/to/your/default_cover_image.jpg';

return $settings;
}
add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'your_theme_xprofile_cover_image', 10, 1 );

You may also want to completely replace the default css styles BuddyPress is using for the Cover Image positioning. In this case using one (or both) of the above filters, you will define a new callback parameter and actually build this callback function so that it』s returning your css rules.
/**
* Your theme callback function
*
* @see bp_legacy_theme_cover_image() to discover the one used by BP Legacy
*/
function your_theme_cover_image_callback( $params = array() ) {
if ( empty( $params ) ) {
return;
}

return '
/* Cover image - Do not forget this part */
#buddypress #header-cover-image {
height: ' . $params["height"] . 'px;
background-image: url(' . $params['cover_image'] . ');
}
';
}

function your_theme_cover_image_css( $settings = array() ) {
$settings['callback'] = 'your_theme_cover_image_callback';

return $settings;
}
add_filter( 'bp_before_members_cover_image_settings_parse_args', 'your_theme_cover_image_css', 10, 1 );
add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'your_theme_cover_image_css', 10, 1 );

About Template Part Overrides
The BP Theme Compat API allowes your theme to override the template parts BuddyPress is using to display its content as soon as you put your custom templates inside a subdirectory named 『buddypress』 or 『community』 in your theme』s directory.
If your theme is overridding the following templates:

buddypress/members/single/home.php
buddypress/members/single/profile.php
buddypress/groups/create.php
buddypress/groups/single/admin.php
buddypress/groups/single/home.php

Then you will need to upgrade these template parts according to the changes we have introduced about them since version 2.4.0. In this case, observe the corresponding template parts of the BuddyPress plugin (in the bp-templates/bp-legacy/buddypress directory) and apply the changes to your custom template parts.
About buddypress.css Overrides
The BP Theme Compat API also allowes your theme to override the BuddyPress stylesheet by putting a buddypress.css file into the css directory of your theme. If you』re doing so, you』ll need to edit your css file according to the css rules we』ve added in the 2.4.0 version. You』ll also need to filter the cover image settings so that the theme handle of your BuddyPress stylesheet is used instead of the BP Legacy one. There is also a great probability you』ll need to use a custom callback function. Here』s an example of the code you could use.
function your_theme_cover_image_css( $settings = array() ) {
/**
* If you are using a child theme, use bp-child-css
* as the theme handel
*/
$theme_handle = 'bp-parent-css';

$settings['theme_handle'] = $theme_handle;

/**
* Then you'll probably also need to use your own callback function
* @see the previous snippet
*/
$settings['callback'] = 'your_theme_cover_image_callback';

return $settings;
}
add_filter( 'bp_before_members_cover_image_settings_parse_args', 'your_theme_cover_image_css', 10, 1 );
add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'your_theme_cover_image_css', 10, 1 );

 
Standalone BuddyPress Themes
A Member』s Cover Image in the BP Default theme
 
These themes are using their very own templates and are generally adding BuddyPress support (add_theme_support( 'buddypress' )) into their functions.php file. In this case, the BP Theme Compat API won』t register dynamically the BuddyPress Cover Images feature. These themes will need to register the feature in order to enjoy it. To show you how this can be achieved, let』s take the case of a well known Standalone BuddyPress theme: 「BP Default」.
First, you』ll need to make sure your Standalone BuddyPress Theme is following the recommendation of the WordPress Themes Handbook about how to include stylesheets for your theme using the wp_enqueue_style() function. BP Default is following this recommendation and uses 『bp-default-main』 as the stylesheet handle.
Then, you』ll need to register the Cover Images feature. You can choose to register it for Members and / or Groups by including (or not) the corresponding components in your feature』s settings.
// Register the Cover Image feature for Users profiles
function bp_default_register_feature() {
/**
* You can choose to register it for Members and / or Groups by including (or not)
* the corresponding components in your feature's settings. In this example, we
* chose to register it for both components.
*/
$components = array( 'groups', 'xprofile');

// Define the feature's settings
$cover_image_settings = array(
'name' => 'cover_image', // feature name
'settings' => array(
'components' => $components,
'width' => 940,
'height' => 225,
'callback' => 'bp_default_cover_image',
'theme_handle' => 'bp-default-main',
),
);

// Register the feature for your theme according to the defined settings.
bp_set_theme_compat_feature( bp_get_theme_compat_id(), $cover_image_settings );
}
add_action( 'bp_after_setup_theme', 'bp_default_register_feature' );

The different parameters of the Cover Image settings explained:

$components
An array to inform about the BuddyPress Components IDs you wish to activate the feature for.
eg: array( 'profile', 'groups' )
$width
An integer to set the width of the cover image.
$height
An integer to set the height of the cover image.
$callback
A string to define the callback function that will return your css rules for the cover image.
$theme_handle
The string used inside the wp_enqueue_style() function to identify the theme』s stylesheet.

Now the feature is registered, you will need to create the callback function used to include the css rules specific to the Cover Image feature. In this example, we called it bp_default_cover_image().
// Example of function to customize the display of the cover image
function bp_default_cover_image( $params = array() ) {
if ( empty( $params ) ) {
return;
}

// The complete css rules are available here: https://gist.github.com/imath/7e936507857db56fa8da#file-bp-default-patch-L34
return '
/* Cover image */
#header-cover-image {
display: block;
height: ' . $params["height"] . 'px;
background-image: url(' . $params['cover_image'] . ');
}
';
}

Finally, you』ll need to edit the following template parts according to the changes we have introduced in version 2.4.0:

members/single/home.php
members/single/profile.php
groups/create.php
groups/single/admin.php
groups/single/home.php

Additionally you can use your own templates for the Cover Image headers ones by creating the following into your theme:

members/single/cover-image-header.php
members/single/profile/change-cover-image.php
groups/single/cover-image-header.php

NB: if you are enqueueing your stylesheet by hooking 『wp_enqueue_scripts』 like it is recommended here and if the Cover Images specific css rules are not loaded, you may need to edit the priority of your hook to an earlier one like 9.
Neutralizing the Cover Images feature
As we have just seen, the feature is not automatically registered for Standalone BuddyPress themes, so this part should only concern themes using the BP Theme Compat API. If you need some time to 「fine-tune」 Cover Images for your theme, you can decide to completely deactivate the feature. In this case you can either use filters or stop the BP Theme Compat API from dynamically registering the feature.
Using Filters :
// For members :
add_filter( 'bp_is_members_cover_image_active', '__return_false' );

// For groups :
add_filter( 'bp_is_groups_cover_image_active', '__return_false' );

Stopping the BP Theme Compat API from dynamically registering the feature
function cover_images_no_support() {
remove_action( 'bp_after_setup_theme', 'bp_register_theme_compat_default_features', 10 );
}
add_action( 'after_setup_theme', 'cover_images_no_support' );

Finally, if the feature is registered, the community Administrators will always have the choice to deactivate the feature from the Settings > BuddyPress > Settings screen of their WordPress Administration.
BuddyPress Cover Images options

Related Resources

Using BuddyPress Cover Images inside the Member and Group Loops
Theme Compatibility
Overloading Template Compatibility theme files
WordPress Theme Handbook – Stylesheets

在成員和群組迴圈中使用 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="">

電子郵件 (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' );

電子郵件令牌

電子郵件令牌

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.