/** * Add default email tokens. * * @since 2.5.0 * * @param array $tokens Email tokens. * @param string $property_name Unused. * @param string $transform Unused. * @param BP_Email $email Email being sent. * @return array */ function bp_email_set_default_tokens($tokens, $property_name, $transform, $email) { $tokens['site.admin-email'] = bp_get_option('admin_email'); $tokens['site.url'] = home_url(); // These options are escaped with esc_html on the way into the database in sanitize_option(). $tokens['site.description'] = wp_specialchars_decode(bp_get_option('blogdescription'), ENT_QUOTES); $tokens['site.name'] = wp_specialchars_decode(bp_get_option('blogname'), ENT_QUOTES); // Default values for tokens set conditionally below. $tokens['email.preheader'] = ''; $tokens['recipient.email'] = ''; $tokens['recipient.name'] = ''; $tokens['recipient.username'] = ''; $tokens['unsubscribe'] = site_url('wp-login.php'); // Who is the email going to? $recipient = $email->get('to'); if ($recipient) { $recipient = array_shift($recipient); $user_obj = $recipient->get_user('search-email'); $tokens['recipient.email'] = $recipient->get_address(); $tokens['recipient.name'] = $recipient->get_name(); if (!$user_obj && $tokens['recipient.email']) { $user_obj = get_user_by('email', $tokens['recipient.email']); } if ($user_obj) { // Unsubscribe link. $tokens['unsubscribe'] = esc_url(sprintf('%s%s/notifications/', bp_core_get_user_domain($user_obj->ID), function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings')); $tokens['recipient.username'] = $user_obj->user_login; } } // Email preheader. $post = $email->get_post_object(); if ($post) { $tokens['email.preheader'] = sanitize_text_field(get_post_meta($post->ID, 'bp_email_preheader', true)); } return $tokens; }