1. When user is created an email isn't sent to admin
2. The user isn't added to our email list
Both of these things work fine within the S2Member system but outside of it and they don't work. The two scenarios are auto login after registration and when creating a member from the outside.
For #1 above:
In other words, wp_new_user_notification only sends to the user and not the admin.
For #2 above:
I don't know the call to make the list functions work. Of course, I can tap into MailChimp's API myself if necessary but it would be a lot easier to use to use S2Members' functions.
How can I make sure the admin gets the email they usually get? How can we make sure they are added to the list?
And for the code share:
Here's my auto login code (thanks to Christian):
- Code: Select all
add_action('ws_plugin__s2member_during_configure_user_registration_front_side_free', 's2_auto_login_after_registration');
function s2_auto_login_after_registration($vars = array()) {
if (!is_admin() && $vars['processed'] === 'yes') {
wp_new_user_notification($vars['user_id'], $vars['pass']);
wp_set_auth_cookie($vars['user_id'], false, is_ssl());
wp_redirect('http://domain.com/download-' . $vars['__refs']['level']);
exit();
}
}
Here's my create/update user code from outside of S2Member. In this case, we have an XML notification posted this file and it creates a user or updates an existing one. This is useful stuff:
- Code: Select all
require('wp-blog-header.php');
$xml = simplexml_load_file("xml.xml");
$orderID = $xml->orderID;
$role = getProductID($xml->lineItems->item->product->productID);
$firstName = $xml->paymentInfos->paymentInfo->customerFirstName;
$lastName = $xml->paymentInfos->paymentInfo->customerLastName;
$email = $xml->paymentInfos->paymentInfo->customerEmail;
$fullName = $firstName . " " . $lastName;
$autoEOT = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")+1);
if(!email_exists($email)) {
$random_password = wp_generate_password(8, false);
$generatedID = wp_create_user($email, $random_password, $email);
if ($role == "s2member_level1") {
wp_update_user( array ('ID' => $generatedID,
'first_name' => $firstName,
'last_name' => $lastName,
'user_email' => $email,
'user_login' => $email,
'user_nicename' => $email,
'display_name' => $fullName,
'user_registered' => date('Y-m-d H:i:s'),
'role' => $role
) ) ;
update_user_meta($generatedID, 'wp_s2member_auto_eot_time', date("U", $autoEOT));
update_user_meta($generatedID, 'wp_s2member_custom', 'domain.com');
update_user_meta($generatedID, 'wp_s2member_subscr_id', (int)$orderID);
} else {
wp_update_user( array ('ID' => $generatedID,
'first_name' => $firstName,
'last_name' => $lastName,
'user_email' => $email,
'user_login' => $email,
'user_nicename' => $email,
'display_name' => $fullName,
'user_registered' => date('Y-m-d H:i:s'),
'role' => $role
) ) ;
update_user_meta($generatedID, 'wp_s2member_custom', 'domain.com');
update_user_meta($generatedID, 'wp_s2member_subscr_id', (int)$orderID);
}
wp_new_user_notification($generatedID, $random_password);
} else {
if ($role == "s2member_level1") {
$currentID = email_exists($email);
wp_update_user( array ('ID' => $currentID,
'first_name' => $firstName,
'last_name' => $lastName,
'user_email' => $email,
'user_login' => $email,
'user_nicename' => $email,
'display_name' => $fullName,
'role' => $role
) ) ;
update_user_meta($currentID, 'wp_s2member_auto_eot_time', date("U", $autoEOT));
update_user_meta($currentID, 'wp_s2member_subscr_id', (int)$orderID);
} else {
$currentID = email_exists($email);
wp_update_user( array ('ID' => $currentID,
'first_name' => $firstName,
'last_name' => $lastName,
'user_email' => $email,
'user_login' => $email,
'user_nicename' => $email,
'display_name' => $fullName,
'role' => $role
) ) ;
update_user_meta($currentID, 'wp_s2member_subscr_id', (int)$orderID);
delete_user_meta($currentID, 'wp_s2member_auto_eot_time');
}
}
function getProductID($id) {
if ($id == "235875900") {
return "s2member_level1";
}
if ($id == "235876000") {
return "s2member_level2";
}
if ($id == "235876100") {
return "s2member_level3";
}
if ($id == "235876200") {
return "s2member_level4";
}
if ($id == "235876300") {
return "s2member_level5";
}
}