PluginProbe
BotBlocker Security – Complete security platform / 1.7.1
BotBlocker Security – Complete security platform v1.7.1
1.7.5 1.7.4 1.7.3 1.7.2 1.7.1 1.7 1.6.21 1.6.20 1.6.19 trunk 1.6.10 1.6.11 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 All 26 releases
botblocker-security / botblocker-security.php

botblocker-security.php in BotBlocker Security – Complete security platform 1.7.1, at botblocker-security.php

265 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly
6 }
7 /**
8 * The BotBlocker Security bootstrap file
9 *
10 * This file is responsible for loading the necessary files and initializing the plugin functionality.
11 * It defines various constants and includes the main class file, which is responsible for running the plugin.
12 * The plugin is activated and deactivated using the activate_botblocker() and deactivate_botblocker() functions.
13 * The bbcs_run_botblocker_shield() function initializes the plugin and its admin functionality.
14 *
15 * @link https://globus.studio
16 * @package botblocker-security
17 * @version 1.7.1
18 *
19 * @wordpress-plugin
20 * Plugin Name: BotBlocker Security - Firewall & Bot Protection
21 * Plugin URI: https://botblocker.top/
22 * Description: Blocks bots, brute force attacks, spam and automated threats in real time. Captcha, IP rules, proxy/vpn/tor detection, login protection, reCAPTCHA, customizable security rules - all in one plugin. Maximum Security for WordPress.
23 * Version: 1.7.1
24 * Author: Yevhen Leonidov
25 * Author URI: https://leonidov.dev/
26 * License: GPL-2.0+
27 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
28 * Requires at least: 5.1
29 * Tested up to: 7.0
30 * Requires PHP: 7.4
31 * Text Domain: botblocker-security
32 * Domain Path: /languages
33 */
34
35
36 // Check minimum requirements (PHP)
37 if ( version_compare( phpversion(), '7.4.0', '<' ) ) {
38 function bbcs_minimum_php_version_notice(): void {
39 echo '<div class="notice notice-error"><p>' . esc_html__( 'BotBlocker requires PHP 7.4 or higher.', 'botblocker-security' ) . '</p></div>';
40 }
41 add_action( 'admin_notices', 'bbcs_minimum_php_version_notice' );
42 return;
43 }
44
45 // Check minimum requirements (WordPress)
46 if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
47 function bbcs_minimum_wp_version_notice(): void {
48 echo '<div class="notice notice-error"><p>' . esc_html__( 'BotBlocker requires WordPress 5.1 or later.', 'botblocker-security' ) . '</p></div>';
49 }
50 add_action( 'admin_notices', 'bbcs_minimum_wp_version_notice' );
51 return;
52 }
53
54 /**
55 * Constants for the BotBlocker plugin.
56 * These constants define various settings and values used throughout the plugin.
57 */
58 if ( ! defined( 'BOTBLOCKER' ) ) {
59 define( 'BOTBLOCKER', true );
60 }
61 define( 'BOTBLOCKER_DIR', plugin_dir_path( __FILE__ ) );
62 define( 'BOTBLOCKER_URL', plugin_dir_url( __FILE__ ) );
63 define( 'BOTBLOCKER_BASENAME', plugin_basename( __FILE__ ) );
64
65 // Include the helper functions file
66 require_once BOTBLOCKER_DIR . 'helpers.php';
67 // Include the core helpers file
68 require_once BOTBLOCKER_DIR . 'core-helpers.php';
69 if ( is_admin() || wp_doing_cron() ) {
70 require_once BOTBLOCKER_DIR . 'helpers-admin.php';
71 }
72
73 // Include license functionality
74 bbcs_handleBotblockerPro();
75
76 // Marketing blocks (changelog parser, in-plugin update message, social proof, etc.)
77 add_action( 'in_plugin_update_message-' . BOTBLOCKER_BASENAME, 'bbcs_render_in_plugin_update_message', 10, 2 );
78 $bbcs_relative_basename = basename( __DIR__ ) . '/' . basename( __FILE__ );
79 if ( BOTBLOCKER_BASENAME !== $bbcs_relative_basename ) {
80 add_action( 'in_plugin_update_message-' . $bbcs_relative_basename, 'bbcs_render_in_plugin_update_message', 10, 2 );
81 }
82
83 // Guard: fix nonce_user_logged_out uid at 0 for unauthenticated AJAX requests.
84 // Without this, a third-party plugin hooking the filter could return a different
85 // uid during nonce creation vs verification, causing nopriv nonce mismatch.
86 add_filter( 'nonce_user_logged_out', '__return_zero', 0 );
87
88 /**
89 * Checks if the request is an AJAX request and performs logic.
90 *
91 * This function is responsible for checking if the current request is an AJAX request and performing the necessary bot blocking logic.
92 * It prevents automated bots from accessing or submitting data through AJAX requests.
93 *
94 * @return void
95 */
96 function bbcs_botblocker_ajax_check(): void {
97 check_ajax_referer( 'botblocker_nonce', 'nonce' );
98
99 // Rate-limit: max 100 check-requests per IP per hour.
100 /*
101 if ( ! BotBlockerIp::rateLimit( 'bbcs_botblocker_check', 100, HOUR_IN_SECONDS ) ) {
102 wp_send_json_error( array( 'message' => __( 'Too many requests. Please try again later.', 'botblocker-security' ) ), 429 );
103 }
104 */
105
106 /* Include the BotBlocker main class file */
107 require_once BOTBLOCKER_DIR . 'includes/botblocker/class-botblocker.php';
108 BotBlockerAddons::includePreRunAddons();
109 $botBlocker = new BotBlocker();
110 $botBlocker->init_visitor_pages();
111 $botBlocker->initialize();
112 wp_die();
113 }
114 add_action( 'wp_ajax_bbcs_botblocker_check', 'bbcs_botblocker_ajax_check' );
115 add_action( 'wp_ajax_nopriv_bbcs_botblocker_check', 'bbcs_botblocker_ajax_check' );
116
117 /**
118 * Activates the BotBlocker plugin.
119 *
120 * This function is called when the plugin is activated.
121 * It includes the necessary files, performs database operations, and creates rule files.
122 *
123 * @return void
124 */
125 register_activation_hook( __FILE__, array( 'Botblocker_Activator', 'activate' ) );
126
127 /**
128 * Deactivates the BotBlocker plugin.
129 *
130 * This function is called when the plugin is deactivated.
131 * It includes the necessary files and performs cleanup operations.
132 *
133 * @return void
134 */
135 register_deactivation_hook( __FILE__, array( 'Botblocker_Deactivator', 'deactivate' ) );
136
137 /**
138 * Runs the BotBlocker plugin.
139 *
140 * This function initializes the plugin and its admin functionality.
141 *
142 * @return void
143 */
144 function bbcs_run_botblocker_shield(): void {
145 /* Check installation and create tables if necessary (for corrupted installations) */
146 BotBlockerInstall::checkInstall();
147
148 /* Include the BotBlocker main interface class file */
149 $plugin = new Cyber_Secure_Botblocker();
150 BotBlockerAddons::includePreRunAddons();
151 $plugin->run();
152 /* Include active addons after database is ready */
153 BotBlockerAddons::includeAll();
154
155 if ( is_admin() ) {
156 // Admin UI, menu registration, plugin action links
157 $bbcs_admin = Botblocker_Admin::getInstance();
158 add_action( 'admin_menu', array( $bbcs_admin, 'add_admin_menu' ) );
159 $bbcs_admin->run();
160
161 // Notification system
162 require_once BOTBLOCKER_DIR . 'includes/class-botblocker-toastify.php';
163 BBCS_Toastify::init();
164
165 // Setup Wizard
166 require_once BOTBLOCKER_DIR . 'admin/class-botblocker-setup-wizard.php';
167 $bbcs_wizard = new BotBlocker_SetupWizard();
168 $bbcs_wizard->hooks();
169 }
170 }
171
172 add_action( 'plugins_loaded', 'bbcs_run_botblocker_shield', -9998 );
173
174 //BBCS-MULTISITE
175 function bbcs_on_wp_initialize_site( $new_site ): void {
176 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
177 require_once ABSPATH . 'wp-admin/includes/plugin.php';
178 }
179 if ( ! is_plugin_active_for_network( BOTBLOCKER_BASENAME ) ) {
180 return;
181 }
182 switch_to_blog( (int) $new_site->blog_id );
183 try {
184 require BOTBLOCKER_DIR . 'includes/database/inc-botblocker-tables.php';
185 Botblocker_Activator::activate();
186 } finally {
187 restore_current_blog();
188 }
189 require BOTBLOCKER_DIR . 'includes/database/inc-botblocker-tables.php';
190 }
191 add_action( 'wp_initialize_site', 'bbcs_on_wp_initialize_site', 200 );
192
193 //BBCS-MULTISITE
194 function bbcs_on_wp_uninitialize_site( $old_site ): void {
195 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
196 require_once ABSPATH . 'wp-admin/includes/plugin.php';
197 }
198 if ( ! is_plugin_active_for_network( BOTBLOCKER_BASENAME ) ) {
199 return;
200 }
201
202 switch_to_blog( (int) $old_site->blog_id );
203 try {
204 require BOTBLOCKER_DIR . 'includes/database/inc-botblocker-tables.php';
205 if ( class_exists( 'BotBlockerAddons' ) ) {
206 BotBlockerAddons::deactivateAll();
207 }
208 BotBlockerCron::removeTasks();
209 } finally {
210 restore_current_blog();
211 }
212 require BOTBLOCKER_DIR . 'includes/database/inc-botblocker-tables.php';
213
214 if ( defined( 'BOTBLOCKER_INTEGRATE_MU_PLUGINS' ) && BOTBLOCKER_INTEGRATE_MU_PLUGINS && method_exists( 'BotBlockerInstall', 'uninstallMuPlugin' ) ) {
215 BotBlockerInstall::uninstallMuPlugin();
216 }
217
218 update_site_option( 'bbcs_sites_map_dirty', 1 );
219 }
220 add_action( 'wp_uninitialize_site', 'bbcs_on_wp_uninitialize_site', 1 );
221
222 // Multisite: flag sites map for regeneration when site URLs change.
223 if ( is_multisite() ) {
224 add_action(
225 'update_option_siteurl',
226 function () {
227 update_site_option( 'bbcs_sites_map_dirty', 1 );
228 }
229 );
230
231 add_action(
232 'wp_update_site',
233 function ( $new_site, $old_site ) {
234 if ( $new_site->domain !== $old_site->domain || $new_site->path !== $old_site->path ) {
235 update_site_option( 'bbcs_sites_map_dirty', 1 );
236 }
237 },
238 10,
239 2
240 );
241 }
242
243 /* Add preconnect for Google Fonts and Google Charts*/
244 function bbcs_add_google_fonts_preconnect(): void {
245 echo '<link rel="preconnect" href="https://fonts.googleapis.com">';
246 echo '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>';
247 }
248 add_action( 'wp_head', 'bbcs_add_google_fonts_preconnect' );
249
250 /**
251 * Add custom links to plugin meta row
252 */
253 function bbcs_plugin_row_meta( array $links, string $file ): array {
254 if ( BOTBLOCKER_BASENAME === $file ) {
255 $row_meta = array(
256 'docs' => '<a href="https://botblocker.top/docs/" target="_blank">' . esc_html__( 'Docs and FAQs', 'botblocker-security' ) . '</a>',
257 'video' => '<a href="https://globus.studio/contact-us-to-develop-agency-solutions/" target="_blank">' . esc_html__( 'Hire Developers', 'botblocker-security' ) . '</a>',
258 );
259 return array_merge( $links, $row_meta );
260 }
261 return $links;
262 }
263 add_filter( 'plugin_row_meta', 'bbcs_plugin_row_meta', 10, 2 );
264
265 /* End of file botblocker-security.php */