Remove Email Verification breaks Buddypress activation email after uninstall

Hi,

I have been having a long term issue with my buddypress activation email being filled with incorrect information, after a user creates a blog on my multisite install.

After you activate, you can visit your blog here:

http://1/

This is similar to the issue here (not fixed):
https://premium.wpmudev.org/forums/topic/pro-sites-and-buddypress

and here:
https://premium.wpmudev.org/forums/topic/bp-social-theme-registration-messagge

or here:
http://stackoverflow.com/questions/15016305/how-to-edit-the-registration-email-sent-by-buddypress-for-activating-users

This filter does not seem to change the activation email content:

function custom_buddypress_site_activation_message( $message, $domain, $path, $title, $user, $user_email, $key, $meta ) {
    return __("Thanks for registering! “, ‘buddypress’);
}
add_filter( 'bp_core_activation_signup_blog_notification_message', 'custom_buddypress_site_activation_message', 10, 5 );

I have spent several hours trying to fix it. Feel free to create a site on my multisite to test.

I even tried PHP trimming the $message to exclude the URL and bottom sentence, but could figure out why it would PHP error out.

If possible, on a multisite test install Buddypress, password set, and remove email verification. Then uninstall password set and remove email verification. These are the plugins I have installed in the past, that has seems to have got me in this mess. They are not on my server any more.

Thanks for any help on this matter.

Cheers,

Johnny

  • johnnymestizo
    function change_site_activation_email_body($message) {
    //  Get some globals
    global $bp, $wpdb;
    
      //  Get username from the signup form just posted
      $username = $bp->signup->username;
    
      //  SQL query to get activation key for that username
      $sql = 'select meta_value from wp_usermeta where meta_key="activation_key" and user_id in ( select ID from wp_users where user_login="' . $username . '" and user_status=2 )';
    
      //  Getting the activation key from the database
      $activation_key = $wpdb->get_var($sql);
    
      $activate_url = bp_get_activation_page() ."?key=$activation_key";
      //$activate_url = esc_url( $activate_url );
    
     //  Custom message with activation key
      $message = "Thanks for registering! To complete the activation of your new website, please click the following link:\n\n$activate_url";
        return "Thanks for registering! To complete the activation of your website, please click the following link:\n\n$activate_url\n\n";
    
            return $message;
        }
        add_filter('bp_core_activation_signup_blog_notification_message', 'change_site_activation_email_body', 10, 5 );

    The above filter doesn't return the activation key url, which makes site creation impossible.

  • Ash

    Hello @Johnny

    I hope you are well today and thanks for asking the question.

    Password set and remove email verification - both plugins are not compatible with BuddyPress. But after uninstalling that should not affect your current setup.

    For activation URL, would you please try the following:

    add_filter('bp_core_signup_send_validation_email_message', 'custom_bp_change_activation_email_message');
    function custom_bp_change_activation_email_message($message) {
    	//	Get some globals
    	global $bp, $wpdb;
    
    	//	Get the slug of the activation page
    	$slug = $bp->pages->{"activate"}->slug;
    
    	//	Get username from the signup form just posted
    	$username = $bp->signup->username;
    
    	//	SQL query to get activation key for that username
    	$sql = 'select meta_value from wp_usermeta where meta_key="activation_key" and user_id in (select ID from wp_users where user_login="' . $username . '" and user_status=2)';
    
    	//	Getting the activation key from the database
    	$activation_key = $wpdb->get_var($sql);
    
    	//	Make activation URL
    	$url = sprintf("%s/%s/?key=%s", WP_HOME, $slug, $activation_key);
    
    	//	Custom message with activation key
    	$message = "Yayy! Thanks for signing up! Please confirm your account!\n\n$url";
    
    	return $message;
    }

    Let me know if it works.

    - remove the http://1/ link

    I am not sure, how this comes in the email. You have to remove all added custom code and run a plugin conflict test. Would you please run a plugin conflict test? Please deactivate all plugins except this one and check if you still face the problem. If not, then enable one by one and check which one is causing the problem. You can see the flowchart here: https://premium.wpmudev.org/manuals/using-wpmu-dev/getting-support/

    Please let me know what you get.

    Cheers
    Ash

    • Vinod Dalvi

      Hi @Johnny,

      The above shared code might have not worked because the filter function takes three arguments but in the shared code it was only one so could you please try using the following modified code?

      add_filter('bp_core_signup_send_validation_email_message', 'custom_bp_change_activation_email_message', 10, 3);
      function custom_bp_change_activation_email_message($message,$user_id, $activate_url) {
      	//	Get some globals
      	global $bp, $wpdb;
      
      	//	Get the slug of the activation page
      	$slug = $bp->pages->{"activate"}->slug;
      
      	//	Get username from the signup form just posted
      	$username = $bp->signup->username;
      
      	//	SQL query to get activation key for that username
      	$sql = 'select meta_value from wp_usermeta where meta_key="activation_key" and user_id in (select ID from wp_users where user_login="' . $username . '" and user_status=2)';
      
      	//	Getting the activation key from the database
      	$activation_key = $wpdb->get_var($sql);
      
      	//	Make activation URL
      	$url = sprintf("%s/%s/?key=%s", WP_HOME, $slug, $activation_key);
      
      	//	Custom message with activation key
      	$message = "Yayy! Thanks for signing up! Please confirm your account!\n\n$url";
      
      	return $message;
      }

      Also i can see in your following shared message that the activation link is getting displayed fine so you don't need to display activation link now, Right?

      Thanks for registering! To complete the activation of your account and blog, please click the following link:
      http://tradr.com/activate-2/?key=0c7ad6250170335d

      Regards,
      Vinod Dalvi

  • Vinod Dalvi

    Hi @Johnny,

    Try using the following CSS code in the functions.php file of your child theme.

    add_filter('bp_core_activation_signup_blog_notification_message', 'custom_bp_change_activation_email_message', 10, 8);
    function custom_bp_change_activation_email_message($message, $domain, $path, $title, $user, $user_email, $key, $meta) {
    	//	Get some globals
    	global $bp;
    
    	//	Get the slug of the activation page
    	$slug = $bp->pages->{"activate"}->slug;
    
    	//	Make activation URL
    	$url = sprintf("%s/%s/?key=%s", get_bloginfo('url'), $slug, $key);
    
    	//	Custom message with activation key
    	$message = "Yayy! Thanks for signing up! Please confirm your account!\n\n$url";
    
    	return $message;
    }
    
    add_filter('bp_core_activation_signup_blog_notification_subject', 'custom_bp_change_activation_email_subject', 10, 8);
    function custom_bp_change_activation_email_subject($subject, $domain, $path, $title, $user, $user_email, $key, $meta) {
    	return 'Activate http://'.$_SERVER"HTTP_HOST".'/'.$path;
    }

    Best Regards,
    Vinod Dalvi

  • johnnymestizo

    90% there. The following added to the bp-custom.php file obtains the desired results.

    For some reason, on the new blog success email subject, the path was not being carried through.

    It was saying, "Activate http://COMPANY.COM//".

    Any ideas on why the variable is being passed?

    Cheers,

    Johnny

    /* ===== Change the user activation email on signup =================================== */
    function custom_buddypress_activation_message( $message, $user, $user_email, $key, $meta ) {
    	$from_name = "COMPANY";
    	$admin_email = "support@company.com";
        $activate_url = bp_get_activation_page() . "?key=$key";
        $activate_url = esc_url( $activate_url );
        return "Yayy! Thanks for joining COMPANY! Please confirm your account:\n\n$activate_url\n\n";
    }
    add_filter( 'bp_core_activation_signup_user_notification_message', 'custom_buddypress_activation_message', 10, 5 );
    function custom_buddypress_activation_subject(){
    return "Please activate your new COMPANY account";
    }
    add_filter( 'bp_core_activation_signup_user_notification_subject', 'custom_buddypress_activation_subject', 10, 5 );
    
    /* ===== Change the user activation email on signup =================================== */
    function custom_bp_change_activation_email_message($message, $domain, $path, $title, $user, $user_email, $key, $meta) {
    	//	Get some globals
    	global $bp;
    
    	//	Get the slug of the activation page
    	$slug = $bp->pages->{"activate"}->slug;
    
    	//	Make activation URL
    	$url = sprintf("%s/%s/?key=%s", get_bloginfo('url'), $slug, $key);
    
    	//	Custom message with activation key
    	$message = "Yayy! Your new website is nearly ready. Please activate it here:\n\n$url";
    
    	return $message;
    }
    add_filter('bp_core_activation_signup_blog_notification_message', 'custom_bp_change_activation_email_message', 10, 8);
    
    function custom_bp_change_activation_email_subject($subject, $domain, $path, $title, $user, $user_email, $key, $meta) {
    	return 'Please activate your new COMPANY website!';
    }
    add_filter('bp_core_activation_signup_blog_notification_subject', 'custom_bp_change_activation_email_subject', 10, 8);