Where did you get wpum/form/validate=register'
as the filter from?
Hello Mika,
Thank you for your fast reply. As i searched from the code of WP User Manager the filter is located here.
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.
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.
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 🙁
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 🙂
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