first(); if (!$user || !$xprofile) { return; } $firstName = $user->first_name; $lastName = $user->last_name; $displayName = trim($firstName . ' ' . $lastName); if ($displayName && $xprofile->display_name != $displayName) { $xprofile->display_name = $displayName; $xprofile->save(); } }); add_action('wp_ajax_fluent_community_renew_nonce', [$this, 'renewNonce']); // Logged-out: without this, WP returns "0"/200 and the SPA loops on a stale nonce. add_action('wp_ajax_nopriv_fluent_community_renew_nonce', function () { wp_send_json(['message' => __('Your session has expired. Please log in again.', 'fluent-community')], 401); }); } public function renewNonce() { $ajax_nonce = Arr::get($_REQUEST, 'ajax_nonce'); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if (!wp_verify_nonce($ajax_nonce, 'fluent_community_ajax_nonce')) { wp_send_json(['message' => __('Invalid nonce', 'fluent-community')], 400); } $currentProfile = Helper::getCurrentProfile(); if (!$currentProfile) { wp_send_json(['message' => __('Invalid user', 'fluent-community')], 401); } wp_send_json([ 'rest_nonce' => wp_create_nonce('wp_rest'), 'ajax_nonce' => wp_create_nonce('fluent_community_ajax_nonce'), ], 200); } public function handleNewCommentEvent($comment, $feed) { $isPublic = 1; $space = $feed->space_id ? $feed->space : null; if ($space) { $isPublic = $space->privacy == 'public'; } $data = [ 'user_id' => $comment->user_id, 'feed_id' => $feed->id, 'space_id' => $feed->space_id, 'related_id' => $comment->id, 'action_name' => 'comment_added', 'is_public' => $isPublic, ]; Activity::create($data); do_action('fluent_community/track_activity'); } public function handleFeedCreated($feed) { $isPublic = 1; $space = $feed->space_id ? $feed->space : null; if ($space) { $isPublic = $space->privacy == 'public'; } $data = [ 'user_id' => $feed->user_id, 'feed_id' => $feed->id, 'space_id' => $feed->space_id, 'action_name' => 'feed_published', 'is_public' => $isPublic, ]; Activity::create($data); do_action('fluent_community/track_activity'); } public function trackActivity() { $currentProfile = Helper::getCurrentProfile(); if (!$currentProfile) { return false; } // Debounce: skip the write if last_activity was updated within the last 5 minutes. // The ticker polls every ~45-75s per session; without this each poll issues an // xprofile UPDATE, saturating the DB at scale. $throttleSeconds = apply_filters('fluent_community/track_activity_throttle_seconds', 300); if ($currentProfile->last_activity && (current_time('timestamp') - strtotime($currentProfile->last_activity)) < $throttleSeconds) { return false; } $currentProfile->last_activity = current_time('mysql'); $currentProfile->save(); } }