Is there a hook or filter that could be used to validate and/or modify user input for custom field values?

One use case example: in a form I’m working with it has a custom field that is a multiline textarea which accepts any text input. I’d like to be able to sanitize the data using something like the WordPress sanitize_text_field function at the time the user saves the initial registration form and/or at the time a user performs a profile update.

I’d try user_register first. The s2Member Codex lists all the s2Member hooks and filters related to registration here: https://www.s2member.com/codex/stable/s2member/registrations/package-filters/.

Hi Pat,

Thanks I’m not sure user_register will work for both user creation (likely) and profile edits/updates (unlikely), but I suppose I’ll have to really dig into the code more to figure it all out. Oh well, such is the nature of customization I guess.

I really wish more care was taken with the codex documentation and that it was more useful than just a list of hooks/filters/functions with no supporting doc around parameters or data available in context of each function (for example, when validating values what should be set to indicate a value is in error so that the form does not save and returns a sensible error to the end-user). Especially for paying customers.

I’m just surprised that no one has ever had to do this and there is not a supporting KB or a Q&A in this forum. User input validation is such a basic, yet extremely important, need.

I will march on and if I have the chance come back to update the path I took here.

The reason you can’t find anything is almost certainly that you are looking in the wrong place. What you are trying to do is much more dependent on core WordPress hooks and functions than anything connected with s2Member.

Pat’s suggestion of user_register, for example, is a WP hook, and there are plenty of others that might help you out.

s2Member’s role is to manage access to stuff, not to create it in the first place.

If you look at the WP Codex, and Google for examples with WP (omitting s2Member from the search query), you’ll find a ton of stuff to help you. Or, of course, you could just use a forms plugin that provides the functionality already.

Exactly, Tim.

@robertgroves,

Try https://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile_update for profile updates.

@robertgroves You should use both “profile_update”, “validate_password_reset” and “user_register” to catch the all events in the user’s account.

1 Like

Thanks, but if the core hooks are used my forms would be doing double work. (writing to database, retrieving values, sanitizing values and then rewriting to the database). I’d like to avoid that and just do it where it logically should happen in the workflow.

Tim, I disagree. s2Member Pro comes with rich form features which include adding custom fields and applying validation checks to them an additional form plugin should not be required in this case. Maybe if not using s2Member Pro I could see needing yet another plugin, but not when using Pro.

And I stand by my opinion that the docs are horrible. I can basically get what the s2Member Pro “docs” list by grepping the source code for do_action and do_filter. Not very helpful at all… but as always the code is the one source of truth so I dug in and found what I was looking for.

Here are the hooks needed for handling modificatons/sanitizing the posted form data:

  • ws_plugin__s2member_pro_before_sc_paypal_form - this action fires from s2member-pro/src/includes/classes/gateways/paypal/paypal-form-in.inc.php when a PayPal registration form is displayed or submitted.

  • ws_plugin__s2member_before_handle_profile_modifications - this action fires from s2member/src/includes/classes/profile-mods-in.inc.php where processing of the submitted profile modification form is handled.

[EDIT]
After further testing I’ve realized the hook ws_plugin__s2member_pro_before_sc_paypal_form fires too late in the process after the custom reg fields have already been saved.

The correct hook is:

  • ws_plugin__s2member_before_configure_user_registration - this action fires from s2member/src/includes/classes/registrations.inc.php during the processing of the user registration.

Well, we’ll have to agree to disagree then. But I’ll add another reason for my disagreement, which is that s2Member’s forms aren’t accessible. It’s one of the very few criticisms I have of s2Member.

For that reason, I don’t even use the default forms; I always customize them. But if I’m going to be making even more modifications, then, unless I can simply adapt something I’ve done before, I can see every reason for using a specialist forms plugin where accessibility is already taken into account.

s2Member is an open source plugin and WebSharks are a small team. There’s nothing to stop you writing some KB articles for them

Yes, definitely no worries and agree to disagree.

s2Member Pro does let you create your own customized form template so if the default table based ones aren’t doing it for you you could customize your own accessible ones… but if you’re already comfortable with the build from scratch model then que sera sera. Whatever works.

While s2Member is open source, s2Member Pro is very much a paid product, but to their defense they do say on their product page that they do not offer support beyond these community forums. So I have to be okay with that under the circumstances.

And trust me I get the whole “don’t complain, contribute” philosophy when it comes to open source. I just hold paid products to a higher standard I guess. I’m also not afraid to contribute and have already offered up a detailed bug report in github for something I’ve found with the profile modification form. Maybe one day I’ll fork and offer up a pull request for an enhancement of some kind. And I’ll always bring my questions here to the forum and provide my solution when it is figured out, which is another way to contribute since this forum is their primary “support” mechanism. I’ll also browse around the open questions and provide answers when I can.

I do appreciate time and effort of all the community members. Thanks!

Great! We will all appreciate that!