Hook to approve/reject user registration based on submitted info (php)

Hi,

Updated thread. See latest post. Need a hook and don’t think I can use ws_plugin__s2member_before_configure_user_registration or ws_plugin__s2member_during_configure_user_registration

ORIGINAL POST

I’m working on a site for a club with many existing offline members. New members can register purely online (and pay the membership fee), but existing offline members get membership on the website for free. I have a file containing info for the current offline members, and if members enter their information during registration, they get online access for free. Also, usually both new and existing members will get level 1 access, but some existing users will get higher access levels depending on their submitted info.

How I’m currently doing it:
New or existing members click different links to get to different paypal pro forms, which have different prices ($25 or free), and different values in the “custom” attribute. I use the ws_plugin__s2member_during_configure_user_registration hook to check the submitted information for users trying to register as already-paid members (which I know from the “custom” attribute). If their info matches what’s on file, registration proceeds smoothly and they don’t have to pay. If it doesn’t match, I’m canceling the registration by calling wp_delete_user on their newly-made account and then using exit().

It feels like there should be a better way of doing things.

  1. I’d prefer to use the ws_plugin__s2member_before_configure_user_registration hook to check their info before the account gets created, but I can’t find any variables there to indicate whether they’re trying to make a $25 account or an already-paid account. (should I even be using the “custom” attribute for that?)
  2. How do I make the registration process fail nicely?
  3. What’s the best way to change the fields shown on each pro-form? Right now they’re the same, but I’d like to customize it. Should I use the “ws_plugin__s2member_custom_field_gen” hook? Or should I use Pro Form templates(http://s2member.com/kb-article/s2member-pro-forms/#toc-40ec91be)?

Any pointers would be appreciated.

To your questions:

  1. You can use whatever info is “secure”. To extra security I use a combination of ccap, , URI and other form element, like “description”.
  2. At final run wp_redirect() to a prepared page
  3. Templates are better, I think. Well, depends of what you mean as “change”…
  1. OK, cool. Might stick with using “custom” if it makes no difference. But I would think there would be some hook that allowed me to check the account details before the account was created. It feels kind of like I’m doing it wrong to delete the account afterwards instead of not creating it in the first place.
  2. Thanks. What if I want to direct them back to the same page with their info and stuff still entered, but with an error message? Like when their account can’t be created because their username/email isn’t unique. I can redirect them to the same page and show an error message by setting query vars, but the fields they filled out become empty.
  3. By change I just want them to either show up or not show up.

Thanks for the help!

  1. Just find a good one. I think there was an action hook during verification of WP subscription form, but can’t remember the name…
  2. Sure, needs some code to recognize if form is submitted already, and if yes, fill the fields.
  3. In this case can use settings of custom fields at s2M options -> General -> custom fields, can set them “invisible”, or editable after subscription", if needs.
  1. Doing it this way seems to actually be working out well enough, assuming there’s no hidden drawbacks I’m unaware of. It felt wrong, but hey, if it works…
  2. Ahh, duh. That should be easy enough.
  3. I’m aware of that functionality, but I want Form A to show field X but not Y, and form B to show field Y but not X. Both pro forms are for the same membership level, so I’ll need something a bit more advanced. So I’m guessing templates?

Thanks again :slight_smile:

  1. If sucks, but works, it don’t sucks - Murphy’s law :slight_smile: Will not be problems, s2M uses WP “subscribe” and “login” functions too, that hook fires always.
  2. Yes, must be a template, and put code to recognize which case is needs, to show the right form.

Haha, ok, nevermind, it actually doesn’t work. It’s fine for the free pro form, but for the form using a paypal button (we don’t have paypal pro), the hook doesn’t run until the user’s already gone through paypal. I need to show an error before the user is sent to paypal. Anyone know which hook I can use? Again, don’t think I can use ws_plugin__s2member_before_configure_user_registration since that doesn’t seem to get the necessary info.

So find some that runs early. Not easy to dig in code, I know…

Well, I found the hook. Turns out I was looking in the wrong place. Instead of looking for hooks in the registrations file I should’ve been looking at paypal hooks, since it was a paypal pro form. I use the ws_plugin__s2member_pro_paypal_form_submission_validation_response filter, and do something like
if(!member_info_is_valid()) { return array("response" => 'That Member Info is not valid. Please try again.', "error" =>true); }
It returns the same kind of error that s2member does if an email/username isn’t unique, and keeps all the fields filled out. So that works pretty well.

Unfortunately I don’t think I can use either solution to the issue of hiding custom fields. I’ll create a new thread for that since it’s a separate issue.

Hi grayson,

Can you please share the generic code you’re using to validate custom fields before registration?

We’re using PayPal Pro Form and want to validate a custom field before registration. This field should be unique in the database. In other words, no two members can have the same value in this field.

As grayson points out the filter hook you’ll want to use is:
ws_plugin__s2member_pro_paypal_form_submission_validation_response

To see where this filter is applied see the file:
s2member-pro/src/includes/classes/gateways/paypal/paypal-responses.inc.php

What you could do is, if you don’t already have one, create a file like wp-content/mu-plugins/s2-hacks.php and add something similar to this:

// Create a function that does the unique value check
function my_field_value_is_unique($value) {
  // do database checks here
  // return true if not found in database else false
}

// Create your function to do the form validation and return the "error" response data 
// if the field values are invalid.
// The function can be named whatever you like, this example uses: 
// __s2member_form_field_validation
function __s2member_form_field_validation($resposne, $form, $s) {
  // uncomment below to see what fields are available via the array $s 
  // print_r($s);

  // You'll need to pass this function the appropriate custom registration field 
  // that you should be able to find in $s
  if (!my_field_value_is_unique(/*pass in the field to check here*/) {
    return array("response" => 'Please supply another value that is already taken.', 
        "error" =>true);
  }
}

// Wire up your validation function to the filter hook
add_filter('ws_plugin__s2member_pro_paypal_form_submission_validation_response', 
    __s2member_form_field_validation, 10, 3);

Thanks Robert for the generic flow and structure.

I think I can carry it forward from here on.

Thanks once again for the help :slight_smile:

@robertgroves Worked like a charm. Thanks :grin: