Skip to:
Content
Pages
Categories
Search
Top
Bottom

Customizing Buddypress Activation Emails (and still get activation key)

  • Avatar of kpolkson
    kpolkson
    Participant

    @kpolkson

    Hi,

    I have the following filters set up in my theme’s functions.php file to make a custom activation email for new users. Most everything works, but the only problem is the activation url does not pull trough the activation key, it’s just blank after ‘?key=’ what am I missing here to get the activation key (and avoid having to alter bp-core files):

    /*FILTERS FOR CUSTOM BUDDYPRESS ACTIVATION EMAIL*/

    function change_bp_activation_subject($subject) {

    $from_name = ( ” == get_site_option( ‘site_name’ ) ) ? ‘WordPress’ : esc_html( get_site_option( ‘site_name’ ) );

    return __( ‘Activate Your Account With Our Forums Today’, ‘buddypress’ );

    }

    add_filter(‘bp_core_activation_signup_user_notification_subject’, ‘change_bp_activation_subject’);

     

    function change_bp_activation_message($message) {

    $activate_url = bp_get_activation_page() . “?key=$key”;

    $activate_url = esc_url($activate_url);

    $email = is_admin() ? ‘&e=1′ : ”;

    return sprintf( __( “Greetings,\n\nYou have subscribed to our new community website. \n\n To complete the activation of your account and to set up a new password, please click the following link:\n\n%1\$s\n\n \Thanks for taking the time to complete your subscription!”, ‘buddypress’ ), $activate_url . $email );

    }

    add_filter(‘bp_core_activation_signup_user_notification_message’, ‘change_bp_activation_message’);

     

    /*END – CUSTOM BUDDYPRESS ACTIVATION EMAIL*/

Viewing 7 replies - 1 through 7 (of 7 total)
  • @kpolkson,
    There are smarter people around these forums than me, but I will try to help.

    It looks like you haven’t defined the $key variable or have not passed it properly.

    Perhaps try digging into bp-members-functions.php and figuring out a way to extract the $key variable. See the line:
    `$user_id = $wpdb->get_var( $wpdb->prepare( “SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = ‘activation_key’ AND meta_value = %s”, $key ) );`

    http://buddypress.svn.wordpress.org/trunk/bp-members/bp-members-functions.php

    Avatar of kpolkson
    kpolkson
    Participant

    @kpolkson

    hmm, good point. though it seems to me that the query there is assuming a key has already been generated and is associated with a user in the db. The email goes to brand new users that haven’t activated yet, so not sure where to step into the actual $key generation process. I’ll dig around further.

     

    thanks!

    One other thing that I don’t know the answer to is how BuddyPress keys are connected to the WordPress registration process. For example, does WordPress generate the key, or is it BuddyPress that is generating the key?

    If WordPress is generating the key, then the answer might be further down the line.

    Avatar of kpolkson
    kpolkson
    Participant

    @kpolkson

    you’re probably right.

    Though I’d be curious to hear from any of the buddypress experts (or maybe just wordpress experts in general – I am not a big php or wordpress guy) how it is that the function for the activation emails is pulling in the $key where it does not appear to be defined or set up anywhere in the bp-core-filters.php file*, it just appears and is handled as such. I assumed if the filter were set up to attach to that function, it would pull in whatever that function pulls in it’s original context.

    *http://openlab.citytech.cuny.edu/redmine/projects/openlab/repository/revisions/028e8c7af06906d09b18f01fdee8951bf076c0ec/entry/wp-content/plugins/buddypress/bp-core/bp-core-filters.php

    Avatar of becskr
    becskr
    Participant

    @becskr

    I know this is old but I had the same problem and figured out how to fix it so thought I would post it.
    Instead of trying to feed the key in, I just trimmed the message to remove the original wording and then replaced it with my own wording.

    `
    function fix_bp_activation_message($message) {
    $msgTrim = “Thanks for registering! To complete the activation of your account please click the following link:”;
    $trimmed = trim($message,$msgTrim);

    return __( “Thanks for signing up to Clandestine Cake Club! In order to take part in the fun, you’ll need to activate your account by clicking the link below. \n Once you’ve done that, we’ll need to approve the account, usually within 24 hours.”.$trimmed.”Best wishes,\n Lynn Hill – CCC Founder”, ‘buddypress’ );
    }

    add_filter(‘bp_core_signup_send_validation_email_message’, ‘fix_bp_activation_message’);
    `

    Avatar of gentlemanhog
    gentlemanhog
    Participant

    @gentlemanhog

    Hi,

    I did this, after some digging into the $bp object after the registration form is posted. Not tested properly in the wild yet, so you might want to double check before using this. Done via WordPress 3.5.1 and BuddyPress 1.7.2.

    
    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;
    }
    

    I’ve got this in a theme’s functions.php file, but not sure if that’s the right place for it. Would it be better in bp_custom.php?

    Ta,
    Alan.

    Avatar of Toby Cryns (@themightymo)
    Toby Cryns (@themightymo)
    Participant

    @themightymo

    @gentlemanhog – If it works, then it doesn’t matter where it is. :)

    The conventional wisdom is to keep things out of functions.php unless they are theme-specific. In your case, I would say this function belongs someplace other than the theme’s functions.php file.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.