<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 7.1.05
// Randem Systems: https://randemsystems.support
// BotBanish Website Statistics
// Date: 02/14/2026
//
// Handle WordPress Hooks
///////////////////////////////////////////////////////////////////////////////////////////////////////

function BotBanishActivateFilters() {

	$filters = BotBanishGetFilters();

	foreach($filters as $filter) {

		$count = count($filter);

		switch ($count) {

			case 2:
				add_action($filter[0], $filter[1]);
				break;

			case 3:

				add_action($filter[0], $filter[1], $filter[2]);
				break;

			case 4:

				add_action($filter[0], $filter[1], $filter[2], $filter[3]);
				break;
		}
	}
}

function BotBanishActivateActions() {

	$actions = BotBanishGetActions();

	foreach($actions as $action) {

		$count = count($action);

		switch ($count) {

			case 2:
				add_action($action[0], $action[1]);
				break;

			case 3:

				add_action($action[0], $action[1], $action[2]);
				break;

			case 4:

				add_action($action[0], $action[1], $action[2], $action[3]);
				break;
		}
	}
}

function BotBanishDeactivateFilters() {

	// If plugin status is active, destroy the object
	
	if (defined('BOTBANISH_UNISTALL'))		
		$botbanishfirewall_pluginstatus = null;
	
	$filters = BotBanishGetFilters();

	foreach($filters as $filter)
		remove_filter($filter[0], $filter[1]);
}

function BotBanishDeactivateActions() {

	$actions = BotBanishGetActions();

	foreach($actions as $action)
		remove_action($action[0], $action[1]);
}

function BotBanishGetFilters() {
	
	$filters = array(
		array('wp_authenticate_user', 'BotBanish_Authenticate_User', 10, 1),
		array('pre_wp_mail','BotBanishValidateContact_WORDPRESS_Pre', 10, 2),
//		array('admin_footer_text', 'BotBanishRemoveFooterAdmin'),
//		array('update_footer', 'BotBanishRemoveFooterVersion'),
		array( 'admin_footer_text', '__return_empty_string', 11),
		array( 'update_footer', '__return_empty_string', 11),
		
		// Needed for WampServer not to trigger BotBanish on Bad Bot
		
		array( 'http_headers_useragent', 'BotBanishSetUserAgentHTTP', 10, 1),
		array( 'http_api_args', 'BotBanishSetUserAgent', 10, 2),
	);
	
	return $filters;
}

function BotBanishGetActions() {

	$actions = array(
		array( 'wp_head', 'BotBanishClientPageStart', 10),
//		array( 'publish_post', 'BotBanishClientPublishPost', 10),
//		array( 'comment_post', 'BotBanishClientCommentPost', 10, 2),
//		array( 'user_new_form', 'BotBanishClientNewUserAddField', 10),
		array( 'wp_login', 'BotBanishClientLogin', 10, 2),
//		array( 'user_register', 'BotBanishClientRegister', 10),
//		array( 'edit_user_created_user', 'BotBanishClientAddUser', 10, 2),
//		array( 'register_post', 'BotBanishClientRegisterPost', 10, 3),
//		array( 'authenticate', 'BotBanishAuthenticate', 10),
//		array( 'update_option_active_plugins', 'BotBanish_Activate_Sister'),
//		array( 'update_option_active_plugins', 'BotBanish_Deactivate_Sister'),
//		array(' wp_loaded', 'BotBanish_Redirect'),
		array( 'template_redirect', 'BotBanishRedirect404'),
		array( 'admin_init', 'BotBanishGoToSettings'),
		array( 'admin_enqueue_scripts', 'BotBanishJavaSciptLoad'),
//		array( 'phpmailer_init', 'BotBanishSendMailInit', 10, 1 ),
//		array('wp_mail_from', 'BotBanishSetFrom'),
//		array('plugins_loaded', 'BotBanishCheckDBVersion' );
	);
	
	return $actions;
}

function BotBanishJavaSciptLoad() {

     wp_enqueue_script('BotBanishScripts', plugin_dir_url( __FILE__ ) . 'bot/Include/BotBanish.js', array(), '2.0', true);
}
	
	BotBanishActivateFilters();
	BotBanishActivateActions();
?>
