新增電子郵件令牌

新增電子郵件令牌

Codex Home → Emails → Add Email Token
Add Email Token

Adding a token to an existing email can be done by using the bp_email_set_tokens filter.

For example, an email is sent when a member requests membership in a private group. Let』s add the requesting member』s email address to the body of that email.

function maybe_add_tokens_bp_email( $formatted_tokens, $tokens, $obj ) {

if ( isset( $formatted_tokens['requesting-user.name'] ) && isset( $formatted_tokens['requesting-user.id'] ) ) {

$user_info = get_userdata( $formatted_tokens['requesting-user.id'] );

$formatted_tokens['memberemail'] = $user_info->user_email;

}

return $formatted_tokens;

}
add_filter( 'bp_email_set_tokens', 'maybe_add_tokens_bp_email', 11, 3 );

This page lists the default tokens.

We can use that information to set the conditional so that the token is only added when a group membership request email is generated:

if ( isset( $formatted_tokens['requesting-user.name'] ) && isset( $formatted_tokens['requesting-user.id'] ) ) {
// etc

Now that we have added the memberemail token, we need to use the token in the body of the email.

Go to wp-admin > Emails and find the Membership request for group email. Roll over the name and click Edit. 

Then add the new token to the body of the email.

For example: Member Email: {{memberemail}}

Click Update and the token will be used every time that type of email is generated.

發表回覆

您的電子郵箱地址不會被公開。 必填項已用 * 標註