get_charset_collate(); $audit_table = $wpdb->prefix . 'aio_audit_logs'; $lockouts_table = $wpdb->prefix . 'aio_lockouts'; $logs_404_table = $wpdb->prefix . 'aio_404_logs'; $sql = "CREATE TABLE $audit_table ( id bigint(20) NOT NULL AUTO_INCREMENT, time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, user_id bigint(20) NOT NULL, user_login varchar(60) NOT NULL, event varchar(100) NOT NULL, details text NOT NULL, ip_address varchar(45) NOT NULL, PRIMARY KEY (id) ) $charset_collate; CREATE TABLE $lockouts_table ( id bigint(20) NOT NULL AUTO_INCREMENT, ip_address varchar(45) NOT NULL, reason varchar(255) NOT NULL, blocked_at datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, expires_at datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, PRIMARY KEY (id), KEY ip_address (ip_address) ) $charset_collate; CREATE TABLE $logs_404_table ( id bigint(20) NOT NULL AUTO_INCREMENT, url varchar(255) NOT NULL, hits int(11) DEFAULT 1 NOT NULL, last_hit datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, PRIMARY KEY (id), KEY url (url) ) $charset_collate;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); // Migrate 404 logs from options $old_404_logs = get_option('aio_404_logs'); if (is_array($old_404_logs) && !empty($old_404_logs)) { foreach ($old_404_logs as $url => $data) { $wpdb->insert($logs_404_table, [ 'url' => substr($url, 0, 255), 'hits' => isset($data['count']) ? intval($data['count']) : 1, 'last_hit' => isset($data['last_hit']) ? wp_date('Y-m-d H:i:s', $data['last_hit']) : current_time('mysql') ]); } delete_option('aio_404_logs'); } // Migrate blocked IPs from options $old_blocked_ips = get_option('aio_blocked_ips'); if (is_array($old_blocked_ips) && !empty($old_blocked_ips)) { foreach ($old_blocked_ips as $ip => $expires_timestamp) { $expires_at = ($expires_timestamp > 0) ? wp_date('Y-m-d H:i:s', $expires_timestamp) : '2099-12-31 23:59:59'; $wpdb->insert($lockouts_table, [ 'ip_address' => substr($ip, 0, 45), 'reason' => 'Migrated from v3.0.x options', 'blocked_at' => current_time('mysql'), 'expires_at' => $expires_at ]); } delete_option('aio_blocked_ips'); } // Generate a unique encryption key if not exists if ( ! get_option('aio_encryption_key') ) { update_option('aio_encryption_key', wp_generate_password(64, true, true)); } } register_activation_hook( __FILE__, 'aio_tools_activate' ); function run_aio_tools() { if( preg_match( '/(\.txt|\.pdf|\.xml|\.ico|\.gz|\/feed\/?)/', $_SERVER['REQUEST_URI'] ) ) {return;} $plugin = new AIO_Tools(); $plugin->run(); } run_aio_tools();