record_event('auth.login', [ 'login_method' => 'wordpress', 'login_timestamp' => current_time('mysql'), 'detected_via' => 'wp_login_hook', ], null, [ 'wp_user_id' => (int) $user->ID, 'wp_username' => (string) $user->user_login, 'is_admin_user' => $is_admin, 'is_internal' => $is_admin && !vasp_event_should_ignore_internal_traffic(), 'producer' => 'wordpress_auth', ]); if (!$result['success'] && !in_array($result['error'] ?? '', ['tracking_disabled', 'not_client_context', 'no_session'], true)) { vasp_log('User login event was not recorded', 'warning', [ 'error' => $result['error'] ?? 'unknown', ]); } } function vasp_track_user_logout($user_id = null) { if (!vasp_is_event_tracking_enabled()) { return; } if (function_exists('vasp_is_client_event_context') && !vasp_is_client_event_context()) { return; } if (!$user_id && is_user_logged_in()) { $user_id = get_current_user_id(); } if (!$user_id) { return; } $user = get_user_by('id', $user_id); if (!$user) { return; } $is_admin = user_can($user, 'manage_options'); if ($is_admin && vasp_event_should_ignore_internal_traffic()) { return; } $result = (new VASP_Event_Recorder())->record_event('auth.logout', [ 'logout_method' => 'wordpress', 'logout_timestamp' => current_time('mysql'), 'detected_via' => 'wp_logout_hook', ], null, [ 'wp_user_id' => (int) $user->ID, 'wp_username' => (string) $user->user_login, 'is_admin_user' => $is_admin, 'is_internal' => $is_admin && !vasp_event_should_ignore_internal_traffic(), 'producer' => 'wordpress_auth', ]); if (!$result['success'] && !in_array($result['error'] ?? '', ['tracking_disabled', 'not_client_context', 'no_session'], true)) { vasp_log('User logout event was not recorded', 'warning', [ 'error' => $result['error'] ?? 'unknown', ]); } }