电子邮件(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’ );

上次修改 2021.12.31