Page 1 of 1

Outstanding Issues & Code Share

PostPosted: September 16th, 2011, 8:40 am
by seofeed
We've about got S2Member where we need it but I have a couple of outstanding issues I can't get fixed. It's the same two issues for both scenarios.

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

}




Re: Outstanding Issues & Code Share

PostPosted: September 20th, 2011, 12:01 pm
by seofeed
Bumping this thread. Really need an answer to these two questions.

Re: Outstanding Issues & Code Share

PostPosted: September 20th, 2011, 9:39 pm
by Cristián Lávaque
Thanks for pointing out these problems with the hack. I'll ask Jason to help me because I'm not sure myself.

Re: Outstanding Issues & Code Share

PostPosted: September 23rd, 2011, 9:09 am
by seofeed
Following up here again. Sorry to be such a hassle but I really need to get these two issues fixed.

Re: Outstanding Issues & Code Share

PostPosted: September 24th, 2011, 10:37 pm
by Cristián Lávaque
Sorry for the wait. I really haven't had the time to look into this, and Jason is busy with the new release. We'll get to improving the hack eventually.

Maybe you can have your site work without the auto-login after registration for now?

Re: Outstanding Issues & Code Share

PostPosted: September 27th, 2011, 1:33 pm
by Jason Caldwell
You might also take a look at s2Member's Remote Operations API, which provides you with an easy-to-use API call, that creates Users/Members, and also provides options for the email notification.

There is further detail and a code sample available in your Dashboard, under:
s2Member -> API Scripting -> Remote Operations API.
remote-ops-api.png

As another alternative, you could try the Hook user_register, which is what lies beneath these other Hooks/Filters, as part of the WordPress core. See: http://codex.wordpress.org/Plugin_API/A ... r_register Setting a Hook priority to a high number would ensure that your custom routine runs last, after all other processing has taken place.
Code: Select all
<?php add_action("user_register", "my_function", 1000); ?>