Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • Google+
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
PHP ›
How to customize the BuddyPress activation email

How to customize the BuddyPress activation email

April 24, 2014 PHP Jesin A 30 Comments

BuddyPress the social networking plugin for WordPress sends an activation email when a new user registers. This email is very plain so why not add some spice to it by having your custom email. There are many forum threads out there for this topic but 99% of them don’t mention if their method is for single site or multi site. So I spent a lot of time trying customize this activation mailer without any success. Finally I sank into the code of BuddyPress and found the right set of hooks for the each environment – single or multi site.

WordPress Single site

These are the filters that contain the necessary data.

  • bp_core_signup_send_validation_email_subject
  • bp_core_signup_send_validation_email_message

Changing the subject is pretty simple.

add_filter( 'bp_core_signup_send_validation_email_subject', 'custom_buddypress_activation_subject', 10, 2 );

function custom_buddypress_activation_subject( $subject, $user_id ) {
	$user = get_userdata( $user_id );
	return $user->user_login . ' – Activate your ' . get_bloginfo( 'name' ) . ' account';
}

To change the activation message –

add_filter( 'bp_core_signup_send_validation_email_message', 'custom_buddypress_activation_message', 10, 3 );

function custom_buddypress_activation_message( $message, $user_id, $activate_url ) {
	$user = get_userdata( $user_id );
	return "Hi $user->user_login,
Thanks for registering! To complete the activation of your account please click the following link:
$activate_url
Thanks,
Jesin";
}

This is a plaintext email, you can also send a HTML email. To do this the content type of the email has to be changed to “text/html”

function set_bp_message_content_type() {
	return 'text/html';
}

add_filter( 'bp_core_signup_send_validation_email_message', 'custom_buddypress_activation_message', 10, 3 );

function custom_buddypress_activation_message( $message, $user_id, $activate_url ) {
	add_filter( 'wp_mail_content_type', 'set_bp_message_content_type' );
	$user = get_userdata( $user_id );
	return 'Hi <strong>' . $user->user_login . '</strong>,
<br><br>
Thanks for registering! To complete the activation of your account please <a href="' . $activate_url . '">click here</a>.
<br></br>
Thanks,
Jesin';
}

The email’s Content-Type is to be modified only for the BuddyPress activation message, so we act on the wp_mail_content_type hook only inside this function.

You can also use full fledged email templates to give a branded feel.

WordPress Multisite

These are the hooks which contain the activation email and its subject on a Multisite setup.

Registration without blog.

  • bp_core_activation_signup_user_notification_subject
  • bp_core_activation_signup_user_notification_message

Registration with blog.

  • bp_core_activation_signup_blog_notification_subject
  • bp_core_activation_signup_blog_notification_message

The arguments passed by the filters are different here.

add_filter( 'bp_core_activation_signup_user_notification_subject', 'custom_buddypress_activation_subject', 10, 5 );

function custom_buddypress_activation_subject( $subject, $user, $user_email, $key, $meta ) {
	return $user . ' – Activate your ' . get_bloginfo( 'name' ) . ' account';
}

Just choose the right pair of hooks depending on whether a blog is being created or not when a user registers.

add_filter( 'bp_core_activation_signup_user_notification_message', 'custom_buddypress_activation_message', 10, 5 );

function custom_buddypress_activation_message( $message, $user, $user_email, $key, $meta ) {
	$activate_url = bp_get_activation_page() . "?key=$key";
	$activate_url = esc_url( $activate_url );
	return "Hi $user,
Thanks for registering! To complete the activation of your account please click the following link:
$activate_url
Thanks,
Jesin";
}

Adding this code

So where do you add this code? There are three options

bp-custom.php

This file resides in wp-content/plugins/bp-custom.php, if it not there create it and paste the required code. This is the method I recommend because it works in sync with the BuddyPress plugin and is not affected by change of themes. Also disabling BuddyPress will cause this file NOT to be loaded thus reducing the number of loaded files.

Create a plugin

You can create a file inside wp-content/plugins/ with the following plugin header and place the code after it.

<?php
/*
Plugin Name: BuddyPress custom activation email
Plugin URI: https://websistent.com/custom-buddypress-activation-email/
Description: Checks the health of your WordPress install
Author: Jesin A
Author URI: https://websistent.com
*/

This gives the advantage of being able to disable this functionality if not needed.

Child Theme’s functions.php file

This is the least recommended location because changing the theme will result in lost of this functionality.

Related posts:

wordpress custom 403 error pageCustom 403 and 401 error pages in WordPress Default ThumbnailCreate your own email with Windows Live Custom Domains php category thumbnailPHP auto_prepend_file and auto_append_file

Tags: php, wordpress

Comments

  1. Rich says

    August 20, 2014 at 10:22 pm

    The filter for the message should be:

    add_filter( 'bp_core_signup_send_validation_email_message', 'custom_buddypress_activation_message', 10, 5 );
    Reply
    • Jesin A says

      August 20, 2014 at 11:25 pm

      Why should the $accepted_args parameter be 5? This filter only passes 3 variables.

      Reply
      • Rich says

        August 20, 2014 at 11:35 pm

        Sorry was using a heavily modified version. However the naming convention is correct, the tutorial above works great for the subject line but not for the message.

        Reply
        • Jesin A says

          August 20, 2014 at 11:39 pm

          So setting the fourth argument of add_filter() to 5 made it work for you?

  2. Rich says

    August 21, 2014 at 1:28 pm

    No its the the change to the 1st argument which made it work.

    You are hooking into:
    bp_core_activation_signup_user_notification_message

    It should be:
    bp_core_signup_send_validation_email_message

    Reply
    • Jesin A says

      August 21, 2014 at 3:24 pm

      This article explains both the filters, check under the single site and multisite headings. “bp_core_activation_ …” is for Multisite blogs and the one that worked for you is for single site.

      Reply
      • Rich says

        August 21, 2014 at 4:27 pm

        Lol! Sorry Jesin, great post!!

        Reply
  3. Allécto says

    December 21, 2014 at 4:29 am

    Hey Jesin,

    Ty for the post, it is very enlightening.
    I was wondering if you could help me with something else. I would like the BP activation email to also send the new user his/hers username and password. Is that possible?

    Ty very much.

    Reply
    • Jesin A says

      December 21, 2014 at 5:43 pm

      Hi Allécto,

      This post already uses the username in the example code snippets, $user->user_login prints the username.

      I can’t find a way for sending the password without editing the core files which I don’t recommend.

      Reply
      • Allécto says

        December 26, 2014 at 9:11 pm

        Hello, Jesin,

        Thanks a bunch for your reply. Now the emails send the username, which was actually more important that the password.

        Regards!

        Reply
  4. Mizagorn says

    January 27, 2015 at 9:41 am

    Hi Jesin,

    Thanks very much for this article! I was trying to find out how to do this, ran across some very messed up articles, then found this one by simply Googling the text that BuddyPress sends out for an activation email! lol

    Awesome, you have made my life much better. I can’t stand plain and jane. 🙂 This is perfect for my remodel of WinkPress.

    Cheers!

    Reply
  5. Elmister says

    April 1, 2015 at 4:38 am

    hi, great post.

    It was VERY helpful post, for me.
    Especially:

    function set_bp_message_content_type() {return 'text/html';}
        add_filter( 'wp_mail_content_type', 'set_bp_message_content_type' );
    }
    

    Thank You.

    Cheers.

    Reply
  6. Rajo says

    April 27, 2015 at 2:16 pm

    Hi,
    How to sync buddypress activation with Aweber activation (opt-in email) ?
    I would like to send information enter since buddypress registration form to my contacts aweber when a user account is activated
    What are the functions that allows to have the email, username, and the profile information for buddupress? and where is that I can put a function that sending this information?

    Thanks,

    Reply
  7. Paddy says

    May 31, 2015 at 9:28 pm

    Strange,
    My website does send that email when somebody creates a new site :

    “Thanks for registering! To complete the activation of your account and blog, please click the following link:…”

    but I can’t find the file bp-custom.php.

    I just want to locate and modify that email.
    When can i find it?

    Thanks for helping.

    Reply
    • Jesin A says

      May 31, 2015 at 9:36 pm

      Editing the file is not the right way to do it, updating BuddyPress will overwrite the changes. Use the bp_core_activation_signup_blog_notification filter as shown in this article to modify the mail text.

      Reply
  8. Paddy says

    May 31, 2015 at 10:33 pm

    Yes but I just want to edit the file for now. I think it is easy for me now.
    Which file i have to edit?
    Thanks.

    Reply
    • Jesin A says

      June 1, 2015 at 12:10 am

      Inside wp-content/plugins, create a file “bp-custom.php” with the following contents:

      add_filter( 'bp_core_activation_signup_blog_notification_message', 'custom_buddypress_activation_message', 10, 8 );
       
      function custom_buddypress_activation_message( $message, $domain, $path, $title, $user, $user_email, $key, $meta ) {
          $activate_url = bp_get_activation_page() . "?key=$key";
          $activate_url = esc_url( $activate_url );
          return "Hi $user,
      Thanks for registering! To complete the activation of your account and blog, please click the following link:
      $activate_url
      
      After you activate, you can visit your blog here:
      " . esc_url( "http://{$domain}{$path}" );
      }
      Reply
  9. Diego says

    June 7, 2015 at 10:45 pm

    Many Thks man! You saved my life 🙂

    Reply
  10. Mel says

    July 16, 2015 at 9:22 pm

    Great article. Thanks for this.

    What about customising the title?
    The default is [domain.com] Activate Your Account

    Reply
    • Jesin A says

      July 16, 2015 at 9:38 pm

      Hi Mel,

      Use the bp_core_signup_send_validation_email_subject filter on single sites and bp_core_activation_signup_user_notification_subject or bp_core_activation_signup_blog_notification_subject on multisites. The article above covers these filters too.

      Reply
  11. Mel says

    July 16, 2015 at 9:50 pm

    Thanks Jesin.
    This is unfortunately beyond my current skills.
    Would you have a snippet that works out of the box?
    Greatly appreciated!

    Reply
    • Jesin A says

      July 16, 2015 at 11:19 pm

      The snippet too is available in this article. This is for single site:

      add_filter( 'bp_core_signup_send_validation_email_subject', 'custom_buddypress_activation_subject', 10, 2 );
       
      function custom_buddypress_activation_subject( $subject, $user_id ) {
          return 'Your own subject line';
      }
      Reply
      • Mel says

        July 17, 2015 at 9:28 am

        Fantastic! Thanks

        Reply
  12. Daniel says

    July 29, 2015 at 9:34 pm

    Hi Jesin

    Thanks for this. I’m getting a weird issue though.

    I created a plugin using the code. Locally it works fine. I can see in my mailoutput in XAMPP that the email has been created.

    I am also testing a version of this on a subdomain on the live server, but here the reigstration email doesn’t sent. If I switch off the plugin the default activation email gets correctly sent. For some reason the exact same code isn’t working on the subdomain. Do you have any idea why?

    Thanks

    Reply
    • Jesin A says

      July 30, 2015 at 1:11 am

      Hi Daniel,

      It could be that the customized email is being marked as spam, did you check the junk folder of the recipient?

      Reply
      • Daniel says

        July 30, 2015 at 1:24 am

        Hey! Yeah I did check the junk folder. When I switched off the plugin, the default Buddypress activation emails were coming through. Not sure why it isn’t working as it’s fine locally. I’m wondering if it is to do with it being on a subdomain.

        Reply
  13. Trigger says

    November 18, 2015 at 4:14 am

    Hi Jesin, this is a great snippet.

    However I have a problem. The function works great when the user registers for the first time, the email is sent automatically and is displayed as it should; but if I try (as admin) to RESEND the activation mail to the new registered user, the $user->user_login variable is empty, it doesn’t show any value in the email message.
    Do you have a solution for this?

    Also, do you know how to show the user first_name instead of user_login? This doesn’t seem to work either.

    Thank you!

    Reply
  14. Marc-Antoine says

    February 28, 2016 at 1:09 am

    Hi Jesin, thank you for your snippet .

    I use the it on a single site in html version :

    function set_bp_message_content_type() {
        return 'text/html';
    }
     
    add_filter( 'bp_core_signup_send_validation_email_message', 'custom_buddypress_activation_message', 10, 3 );
     
    function custom_buddypress_activation_message( $message, $user_id, $activate_url ) {
        add_filter( 'wp_mail_content_type', 'set_bp_message_content_type' );
        $user = get_userdata( $user_id );
        return 'Hi <strong>' . $user-&gt;user_login . '</strong>,
    
    Thanks for registering! To complete the activation of your account please <a href="' . $activate_url . '" rel="nofollow">click here</a>.
    
    Thanks,
    Jesin';
    }

    Do you know a way to use it in to language english and french. I run for the moment a site in french but we plan to translate it in the next year.

    Best regard,
    Marc-Antoine

    Reply
  15. anand says

    May 6, 2016 at 11:55 am

    Sir Great tutorial
    but i want to include username and password in email sent by buddypress after registering

    Reply
  16. skynet says

    February 9, 2017 at 5:09 pm

    Hi,
    I would like to deactivate the activation of an account by email, when a user registers on my site, he is waiting, I would like the member to be automatically activated after his registration, do you know a php code or a plugin For it to work ?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.