Skip to content
Ipstenu (Mika Epstein) edited this page Feb 1, 2017 · 3 revisions

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

Examples of Blocks

  • foo@domain.com - 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_registration_errors', 'woocommerce_banhammer_validation', 10, 3 );
	}	
}

function woocommerce_banhammer_validation( $validation_errors, $username, $email ) {
	if( (new BanHammer)->banhammer_drop( $username, $email, $validation_errors ) )
		return new WP_Error( '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.

Contributing

Pull requests are always welcome :)

Clone this wiki locally
You can’t perform that action at this time.