latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Different new user email based on member leve

Home Forums Community Forum Different new user email based on member leve

Tagged: 

This topic contains 6 replies, has 2 voices. Last updated by  Raam Dev 4 years, 10 months ago.

Topic Author Topic
Posted: Thursday Mar 8th, 2012 at 7:20 am #7616
Roger
Username: 21inspired

We want to send different new user emails based on the member level of the new member.

We have three levels of member (0, 1, 2), and use s2memberPro forms to make them all free levels (so no actual interaction with PayPal)
e.g.


$attr = array('register' => "1", 'level' => "0",  'ccaps' => "", 'desc' => "", 'custom' => $custom, 'tp' => "0", 'tt' => "D",  'success' => "/" 	);

echo c_ws_plugin__s2member_pro_paypal_form::sc_paypal_form($attr);

Do we have any options to set up different welcome emails for each level?

e.g. Can we filter / hook into the ‘customise new user emails with s2Member’ code and provide alternative text based on a conditional check on member level?

If so, can you point to the appropriate hook?

Thanks, Roger

  • This topic was modified 4 years, 10 months ago by  Roger.
  • This topic was modified 4 years, 10 months ago by  Roger.

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Thursday Mar 8th, 2012 at 7:50 pm #7669
Raam Dev
Username: Raam
Staff Member

Hi Roger,

You can do that by redefining the function that sends the new user email.

First, you’ll need to disable the existing function, wp_new_user_notification() by creating the following file and adding the code below: /wp-content/mu-plugins/disable-new-user-notify.php

<?php
// Disable wp_new_user_notification() so we can 
// create our own custom function in functions.php
if( !function_exists('wp_new_user_notification') ) {
	function wp_new_user_notification(){}
}
?>

Now inside your theme’s functions.php file (e.g., /wp-content/themes/theme_name/functions.php), you can add a function like the following:

add_action ("ws_plugin__s2member_during_configure_user_registration", "my_email_function");
function my_email_function ($vars = array ())
{
	$email = $vars["email"];
	$first_name = $vars["fname"];
	$last_name = $vars["lname"];
	$full_name = $vars["name"];
	$username = $vars["login"];
	$password = $vars["pass"];
	$level = $vars["level"];

	$from = "admin@example.com";
	$subject = "Your username and password";

	if($level == "0") {
		$message = "Username: " . $username . "\nPassword: " . $password . "\nName: " . $full_name. "\nEmail: " . $email;
	}
	elseif($level == "1") {
		$message = "Username: " . $username . "\nPassword: " . $password . "\nName: " . $full_name. "\nEmail: " . $email;	
	}
	elseif($level == "2") {
		$message = "Username: " . $username . "\nPassword: " . $password . "\nName: " . $full_name. "\nEmail: " . $email;	
	}	
	else { // default message if none of the above levels match
		$message = "Username: " . $username . "\nPassword: " . $password . "\nName: " . $full_name. "\nEmail: " . $email;		
	}


   mail ($email, $subject, $message, "From: $from\r\nContent-Type: text/plain; charset=utf-8", "-f $from");
}
  • This reply was modified 4 years, 10 months ago by  Raam Dev. Reason: Revised code
  • This reply was modified 4 years, 10 months ago by  Raam Dev.
  • This reply was modified 4 years, 10 months ago by  Raam Dev.
  • This reply was modified 4 years, 10 months ago by  Raam Dev.
Posted: Friday Mar 9th, 2012 at 5:35 am #7708
Roger
Username: 21inspired

thanks for the quick response.

The disable function in mu-plugins is causing some problems with ‘headers already sent’ –

Warning: Cannot modify header information – headers already sent by (output started at /home/endev/public_html/wp-content/mu-plugins/disable-new-user-notify.php:11) in /home/endev/public_html/wp-login.php on line 349

So, need to find alternative way to disable the wp_new_user_notification()

Have also removed ‘breaks’ from the if clause in new mail function – suspect they might have been left in from earlier revision with switch statement.

Posted: Friday Mar 9th, 2012 at 5:37 am #7709
Roger
Username: 21inspired

ok… moving the disable function to plugins (rather than mu-plugins) and activating from there gets past the problem with headers already sent.

However, the hook to send mail is not working.

Will investigate further.

— EDIT —-

Just realised we are already hooking on ws_plugin__s2member_during_configure_user_registration to provide auto-login. Suspect that is interfering with the send mail, so will rework the code appropriately in there, and update.

  • This reply was modified 4 years, 10 months ago by  Roger.
Posted: Monday Mar 12th, 2012 at 8:28 am #7889
Raam Dev
Username: Raam
Staff Member

Thank you for the update, Roger. Let us know if you get it working.

Posted: Monday Mar 12th, 2012 at 8:33 am #7890
Roger
Username: 21inspired

Yes… running nicely.

We’ve written a little plugin to go with it – that gives an admin screen to setup the welcome emails (with html editor using the WP3.3 function: wp_editor).

Thanks again for your help on this.

Posted: Monday Mar 12th, 2012 at 8:36 am #7891
Raam Dev
Username: Raam
Staff Member

Fantastic. Thank you for the update. :)

Awarded Experienced User badge.
Viewing 6 replies - 1 through 6 (of 6 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.