I am trying to get the user_id for the recipient from within a BuddyPress email template without much success. I have tried the following email tokens from the Codex, none of which appear to be available in the context I'm using: {{user.id}}
{{original_activity.user_id}}
There doesn't seem to be a global token available, like: {{recipient.userid}}
Does anyone know how to add the user_id as a global token, or is there an alternative way to get the user_id of the recipient user from within a BuddyPress email template?
I created a solution that works as follows:
function add_user_id_to_email_tokens($tokens,$property_name,$transform,$email)
{
$user = get_user_by( 'email', $tokens['recipient.email'] );
$user_id=$user->ID;
$tokens['recipient.userid'] = $user_id;
return $tokens;
}
add_filter('bp_email_get_tokens','add_user_id_to_email_tokens',10,4);
I am now able to use the token {{recipient.userid}}
in all BP email templates as a global token.