Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
Ipstenu (Mika Epstein) edited this page Feb 13, 2023 · 5 revisions

Using Ban Hammer is, for the most part, install it, add the emails you hate, and move on.

Examples of Blocks

  • [email protected] - Blocks only this email
  • @domain.com - Blocks everyone from domain.com, but not anyone from otherdomain.com
  • domain.com - Blocks everyone from domain.com and everyone from otherdomain.com
  • .domain.com - Blocks everyone from foo.domain.com and bar.domain.com but not domain.com

Advanced Blocking

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.

WooCommerce

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.

Gravity Forms

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"

Contributing

Pull requests are always welcome :)

Clone this wiki locally