15, 'time-in-min' => 1, 'display-content' => '', 'notification-mail' => '')); register_setting( 'ipBlockOptionGroup', 'ipBlockOptionName', 'ipBlockCallback' ); } add_action( 'admin_init', 'ais_ipBlocker_register_settings' ); function ais_ipBlocker_admin_actions() { add_options_page("IP Blocker", "IP Blocker", "manage_options", "ip-blocker", "ais_ipBlocker_plugin_options"); } function ais_ipBlocker_plugin_options(){ if(!current_user_can('manage_options')){ wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } /*-- Start of Block IP --*/ /*--- Start of include css --*/ wp_register_style( 'ais_ipBlocker_bootstrap-css', IPBLOCKER__PLUGIN_URL.'css/bootstrap.css', false, '1.0.0'); wp_enqueue_style('ais_ipBlocker_bootstrap-css'); wp_register_style('ais_ipBlocker_css', IPBLOCKER__PLUGIN_URL.'css/ipBlocker.css', false, '1.0.0'); wp_enqueue_style('ais_ipBlocker_css'); /*--- End of include css --*/ /*--- Start of include scripts --*/ wp_register_script('ais_ipBlocker_dataTablesJS.min', IPBLOCKER__PLUGIN_URL.'js/jquery.dataTables.min.js', false, '1.0.0'); wp_enqueue_script('ais_ipBlocker_dataTablesJS.min'); wp_register_script('ais_ipBlocker_bootstrap4JS', IPBLOCKER__PLUGIN_URL.'js/dataTables.bootstrap4.min.js', false, '1.0.0'); wp_enqueue_script('ais_ipBlocker_bootstrap4JS'); wp_register_script('ais_ipBlocker_JS', IPBLOCKER__PLUGIN_URL.'js/ip-blocker.js', false, '1.0.0'); wp_enqueue_script('ais_ipBlocker_JS'); /*--- End of include scripts --*/ ?>

prefix; $ipblocksTable = $wpdb->prefix.'ipBlocker'; if(isset($_POST['ais_ipBlocker_user_ip_nonce_field']) && wp_verify_nonce($_POST['ais_ipBlocker_user_ip_nonce_field'], 'ais_ipBlocker_user_ip_action')){ if(isset($_POST['checkValue'])){ $removedId = intval(base64_decode($_POST['checkValue'])); $getUserIPAdd = sanitize_text_field($_POST['userIPAdd']); $counterInit = 1; $crntTimeInit = date("Y-m-d H:i:s"); $updateData = array('counter' =>$counterInit, 'status' => 'unblocked', 'visitTime' => $crntTimeInit); $whereData = array('id' =>$removedId); $updateDB = $wpdb->update( $ipblocksTable, $updateData, $whereData); if($updateDB){ _e('
Successfully removed IP Address '.$getUserIPAdd.' from Banned IP list.
', 'ais-ip-blocker'); } } } else { /* Invalid nonce. you can throw an error here. */ } $myrows = $wpdb->get_results( "SELECT * FROM $ipblocksTable WHERE status = 'blocked' ORDER BY id DESC" ); ?>
">

. ipAddress; ?> visitTime; ?>
prefix; $ipblocksTable = $wpdb->prefix.'ipBlocker'; $crntTime = date("Y-m-d H:i:s"); $myrows = $wpdb->get_results( "SELECT * FROM $ipblocksTable WHERE ipAddress = '$client_ip' ORDER BY id DESC" ); if($myrows){ $counter = $myrows[0]->counter; $status = $myrows[0]->status; $visitTime = $myrows[0]->visitTime; $visitTimeTempMinutes = '+'.$blockDefaultDataUserTimeInMin.' minutes'; $visitTimeAddMinutes = date('Y-m-d H:i:s',strtotime($visitTimeTempMinutes,strtotime($visitTime))); if(($counter >= $blockDefaultDataUserHitCount)){ if($status === 'unblocked'){ $updateData = array('status' => 'blocked'); $whereData = array('ipAddress' =>$client_ip); $updateDB = $wpdb->update( $ipblocksTable, $updateData, $whereData); $toMail = $blockDefaultDataNotificationMail; $subjectMail = 'Banned User Notification'; $messageMail = 'Some one with '.$client_ip.' IP tried to access your site many times. So automatically banned to access site. If you want to allow him then please unblock him from IP-BLocker.'; if($toMail){ $mailStatus = wp_mail( $toMail, $subjectMail, $messageMail); } } echo html_entity_decode($blockDefaultDataDisplayContent); exit; } else{ if($crntTime <= $visitTimeAddMinutes){ $counter++; /*Increment counter if same user visit again in stipulated time*/ $updateData = array('counter' =>$counter, 'status' => 'unblocked', 'visitTime' => $visitTime); $whereData = array('ipAddress' =>$client_ip); $updateDB = $wpdb->update( $ipblocksTable, $updateData, $whereData); } else{ $counter = 1; $updateData = array('counter' =>$counter, 'status' => 'unblocked', 'visitTime' => $crntTime); $whereData = array('ipAddress' =>$client_ip); $updateDB = $wpdb->update( $ipblocksTable, $updateData, $whereData); /*If time is not same then update time and set counter to zero*/ } } } else{ $counter = 1; $insertData = array('ipAddress' => $client_ip, 'counter' => $counter, 'status' => 'unblocked', 'visitTime' => $crntTime); $inserIntoDB = $wpdb->insert( $ipblocksTable, $insertData); /*If Current IP is not available then Insert IP in DB*/ } /*-- End of Block IP --*/ } } /*-- End of Init action --*/ /*-- Start of Create Table, When Plugins activated --*/ function ais_ipBlocker_install() { global $wpdb; $table_name = $wpdb->prefix . 'ipBlocker'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, ipAddress varchar(20) NOT NULL, counter mediumint(9) NOT NULL, status varchar(10) NOT NULL DEFAULT 'unblocked', visitTime TIMESTAMP NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } register_activation_hook( __FILE__, 'ais_ipBlocker_install' ); /*-- End of Create Table, When Plugins activated --*/ /*-- Start of Delete Table, When Plugins Deleted --*/ function ais_ipBlocker_uninstall() { global $wpdb; $table_name = $wpdb->prefix . 'ipBlocker'; $wpdb->query( "DROP TABLE IF EXISTS $table_name" ); } register_uninstall_hook( __FILE__, 'ais_ipBlocker_uninstall' ); /*-- End of Delete Table, When Plugins Deleted --*/ ?>