[Membership 2 Pro] membership plugin should force specific criteria

It would be awesome if the membership pro plugin could force that certain criteria be met when it comes to passwords. For example require users to have one upper case, one letter, one number and at least eight characters in their password. Then prevent them from registering until they hit these requirements.

  • Ash
    • WordPress Hacker

    Hello cornelius_butler

    You can try using ms_model_membership_create_new_user_validation_errors hook to set your own validation rule. Here is an example:

    add_filter( 'ms_model_membership_create_new_user_validation_errors', function( $validation_errors, $member ) {
            // Validate here
            if( trim( $_POST['user_extra'] ) == '' ) // Considering user_extra is the extra field name, you can add more validation rules here
            {
                    $validation_errors->add(
                            'user_extra',
                            'Extra field is mandatory!'
                    );
            }
    
            return $validation_errors;
    }, 99, 2 );

    Hope it helps! Have a nice day!

    Cheers,
    Ash

  • Tony G
    • Mr. LetsFixTheWorld

    I was just looking at one of my sites where I saw the exact feature described here. There is a numeric spinner for the required min/max length, number of letters, number of numbers, checks for Caps required, etc. Where the heck was that?!! I'm going to go nuts until I find it. :astonished:

  • Tony G
    • Mr. LetsFixTheWorld

    Here's an idea :

    - Use Forminator to create a form that looks like the one I just posted.
    - Add that form into a private page and then fill it in. Or put it in a widget and add that to your admin dashboard.
    - Use the hook provided by Ash to read the last Entry for that form and parse the detail. The hook code will then check the user entry with the required parameters.

    There's not much code there at all. I've done a lot of this myself but at the moment I don't think there are any public examples for retrieving form data like this.

    Now that I think about it, this technique could be used with all kinds of customisations in WordPress. The way I've been doing that is that I have a plugin which creates a dashboard settings page, and has multiple tabs for each group of features that want to save. But with Forminator I wouldn't need to change the UI code whenever adding a new tab, just add a form shortcode.

    Hey guys, this has possibilities...

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.