ID) ? $user->user_login : $username; $ip = apply_filters('aios_audit_log_event_user_ip', AIOWPSecurity_Utility_IP::get_user_ip_address()); $stacktrace = maybe_serialize(AIOWPSecurity_Utility::normalise_call_stack_args(debug_backtrace(false))); $network_id = get_current_network_id(); $site_id = get_current_blog_id(); $details = json_encode($details, true); $this->add_new_event($network_id, $site_id, $username, $ip, $event_level, $event_type, $details, $stacktrace); } /** * This function adds the event to the audit log database table * * @param integer $network_id - the id of the current network * @param integer $site_id - the id of the current site * @param string $username - the username of the user who triggered the event * @param string $ip - the IP address of the user * @param string $event_level - the event level * @param string $event_type - the event type * @param string $details - details about the event * @param string $stacktrace - the event stacktrace * * @return void */ private function add_new_event($network_id, $site_id, $username, $ip, $event_level, $event_type, $details, $stacktrace) { global $wpdb; $sql = $wpdb->prepare("INSERT INTO ".AIOWPSEC_TBL_AUDIT_LOG." (network_id, site_id, username, ip, level, event_type, details, stacktrace, created) VALUES (%d, %d, %s, %s, %s, %s, %s, %s, UNIX_TIMESTAMP())", $network_id, $site_id, $username, $ip, $event_level, $event_type, $details, $stacktrace); $wpdb->query($sql); } /** * This method will try to delete all audit logs older than 3 months from the database. * * @return void */ public function delete_old_events() { global $wpdb; $after_days = 90; if (defined('AIOWPSEC_PURGE_AUDIT_LOGS_AFTER_DAYS')) { $after_days = abs(AIOWPSEC_PURGE_AUDIT_LOGS_AFTER_DAYS); } $after_days = empty($after_days) ? 90 : $after_days; $older_than_date = strtotime("-{$after_days} days", time()); $sql = $wpdb->prepare("DELETE FROM ".AIOWPSEC_TBL_AUDIT_LOG." WHERE created < %s", $older_than_date); $wpdb->query($sql); } } AIOWPSecurity_Audit_Event_Handler::instance();