Support » Plugin: Ban Hammer » Customized registration method and compatibility with WP user manager plugin

  • Hello,

    I am using the plugin WP User Manager for registration and it uses its own customized registration method. I have found exactly here that there is a hook with filter in the registration form of the plugin.

    So from your example i have tried to do something like this:

    add_action('init', 'mydomain_plugin_checks');
    
    function mydomain_plugin_checks(){
    	if ( class_exists('BanHammer') ) {
    		add_filter( 'wpum/form/validate=register', 'wpum_verify_email_domain', 10, 2 );
    	}	
    }
    
    function wpum_verify_email_domain( $passed, $values ) {
    
        $email_domain  = $values['register'][ 'user_email' ];
    	if( (new BanHammer)->banhammer_drop($email_domain) ) {
    		return new WP_Error( 'email-validation-error',  (new BanHammer)->options['message'] );
    	}
    
    	
    	return $passed;
    
    }

    But yet it doesn’t work (breaks the page or just don’t uses your IF check, when submitting the registration form. ) 🙁

    I am not so good with .php, so if you can help me out with this i would really appreciate. Maybe to suggest some code.

    I have tested your plugin in general and rocks!

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Plugin Review Team Rep

    Where did you get wpum/form/validate=register' as the filter from?

    Thread Starter honoluluman

    (@honoluluman)

    Hello Mika,

    Thank you for your fast reply. As i searched from the code of WP User Manager the filter is located here.

    Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Plugin Review Team Rep

    I’ll see if I can poke around but I’m afraid I don’t have a lot of free time at the moment 🙁 My GUESS is that’s the wrong filter.

    Thread Starter honoluluman

    (@honoluluman)

    Hello Mika,

    I am not so sure, but i believe that this filter should be used for validation. I tested the filter with just some simple if statement and it works.
    I can use those 2 parameters

    $mail = $values['register'][ 'user_email' ]; and $nickname = $values['register'][ 'username' ];

    to get the username and mail, but i am not really sure what is the ERRORS key that i can use. The plugin uses $passed, $fields, $values as you can see.

    Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Plugin Review Team Rep

    So in my example, you’ll notice I have THREE params:

    
    	if( (new BanHammer)->banhammer_drop( $username, $email, $validation_errors ) )
    		return new WP_Error( 'registration-error-bad-email', (new BanHammer)->options['message'] );
    	return $validation_errors;
    

    You only have one:

    
    	if( (new BanHammer)->banhammer_drop($email_domain) ) {
    		return new WP_Error( 'email-validation-error',  (new BanHammer)->options['message'] );
    	}
    

    You should have at least the username, the email, AND the validation error being passed through. Which implies this is not the correct place for THIS call, since it’s not getting what it needs.

    Check out https://github.com/Ipstenu/ban-hammer/blob/master/ban-hammer.php#L129 which is much the same idea, only for BuddyPress.

    Now that said, your plugin ALREADY has a way to block usernames and a validate EMAIL check:

    https://github.com/alessandrotesoro/wp-user-manager/blob/origin/master/includes/forms/class-wpum-form-register.php#L194

    And that doesn’t appear to be hookable 🙁

    Thread Starter honoluluman

    (@honoluluman)

    Hello Mika,

    Thank you for your explanation.
    As i’ve wrote by the following code

    function wpum_verify_email_domain( $passed, $fields, $values ) {
    
            $email_domain  = $values['register'][ 'user_email' ];
    	$nickname = $values['register'][ 'username' ];
    	$validation_errors = ???
    	
    	if( (new BanHammer)->banhammer_drop($validation_errors, $nickname, $email_domain) ) {
    		return new WP_Error( 'email-validation-error',  (new BanHammer)->options['message'] );
    	}
    	
    	
    	return $passed;
    
    }
    
    add_action('init', 'mydomain_plugin_checks');
    function mydomain_plugin_checks(){
    	if ( class_exists('BanHammer') ) {
    add_filter( 'wpum/form/validate=register', 'wpum_verify_email_domain', 10, 3 );
    }	
    }

    The only key that is actually needed to make it work is the $validation_errors that your plugin needs. What if i could manually add true on this key so, that the validation is proceeded?(What is actually this key needed?) Then if there is not any validation error returns $passed which means that the registration can proceed.

    Thank you again for your time 🙂

    Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Plugin Review Team Rep

    First of all, the ORDER is important

    Yours: if( (new BanHammer)->banhammer_drop($validation_errors, $nickname, $email_domain) )

    Mine: if( (new BanHammer)->banhammer_drop( $username, $email, $validation_errors ) )

    You MUST keep the order THE SAME otherwise the plugin won’t know what each variable is (it looks for placement, not name).

    Now. What should validation_errors be is a good question.

    The validation errors are what WooCommerce expects… Based on this https://github.com/alessandrotesoro/wp-user-manager/blob/origin/master/includes/forms/class-wpum-form-register.php#L240 it appears that instead of returning errors, it returns the ERROR:

    return new WP_Error( 'honeypot-validation-error', __( 'Failed Honeypot validation', 'wpum' ) );

    So … Try putting in $validation_errors = $errors;

    It is required (we kind of HAVE to tell WP what errors were faced) but since we’re adding it after, you may be okay with a default here… https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_errors

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Customized registration method and compatibility with WP user manager plugin’ is closed to new replies.