-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Using Ban Hammer is, for the most part, install it, add the emails you hate, and move on.
-
[email protected]
- Blocks only this email -
@domain.com
- Blocks everyone fromdomain.com
, but not anyone fromotherdomain.com
-
domain.com
- Blocks everyone fromdomain.com
and everyone fromotherdomain.com
-
.domain.com
- Blocks everyone fromfoo.domain.com
andbar.domain.com
but notdomain.com
Some plugins use customized registration methods. Supporting them all in this plugin is a little outside the realm of what I'm able to do, however I have some examples of how all this works.
The basic check you'll want to do is an IF check for this: (new BanHammer)->banhammer_drop( USERNAME, EMAIL, ERRORS )
If that returns true, then you have a banned user.
To echo the default message, you can call (new BanHammer)->options['message']
I know this is confusing so here are some functional examples.
In order to block on WooCommerce you need to add a custom filter:
<?php
add_action('init', 'mydomain_plugin_checks');
function mydomain_plugin_checks(){
if ( class_exists('BanHammer') ) {
add_filter( 'woocommerce_register_post', 'woocommerce_banhammer_validation', 10, 3 );
}
}
function woocommerce_banhammer_validation( $validation_errors, $username, $email ) {
if( (new BanHammer)->banhammer_drop( $username, $email, $validation_errors ) ) {
$validation_errors->add( 'registration-error-bad-email',(new BanHammer)->options['message'] );
}
return $validation_errors;
}
The reason we do it this way is because you cannot check if the class exists for Ban Hammer before init is running. This is not true of all plugins.
function gravity_form_user_registration_validation( $form )
{
$form['errors'] = new WP_Error();
$BanHammer = new BanHammer();
if ( $BanHammer->banhammer_drop( $form['user_name'], $_POST['input_2'], $form['errors'] ) )
{
$form = gf_user_registration()->add_validation_error( 2, $form, 'Your email has been banned from registration. Please use your business email address and not a free or non-business email address.' );
}
return $form;
}
add_filter( 'gform_user_registration_validation', 'gravity_form_user_registration_validation', 10, 3 );
Credit @amityweb, who said "I had some trouble matching fields and accessing $form['errors']. $_POST['input_2'] may not be the best way to access the forms email field"
Pull requests are always welcome :)