Skip to content

Instantly share code, notes, and snippets.

@annuman97
Created March 31, 2026 09:52
Show Gist options
  • Select an option

  • Save annuman97/e053d939d36ed9204f76114ffec6ebcc to your computer and use it in GitHub Desktop.

Select an option

Save annuman97/e053d939d36ed9204f76114ffec6ebcc to your computer and use it in GitHub Desktop.
Show community username instead of full name in Fluent Community leaderboard
<?php
add_filter('fluent_community/leaderboard_api_response', function ($response, $xProfiles, $requestData) {
if (empty($response['leaderboard']) || !is_array($response['leaderboard'])) {
return $response;
}
foreach ($response['leaderboard'] as $groupIndex => $group) {
if (empty($group['items']) || !is_array($group['items'])) {
continue;
}
foreach ($group['items'] as $itemIndex => $item) {
if (empty($item['xprofile'])) {
continue;
}
$xprofile = $item['xprofile'];
if (is_array($xprofile) && !empty($xprofile['username'])) {
$response['leaderboard'][$groupIndex]['items'][$itemIndex]['xprofile']['display_name'] = $xprofile['username'];
} elseif (is_object($xprofile) && !empty($xprofile->username)) {
$response['leaderboard'][$groupIndex]['items'][$itemIndex]['xprofile']->display_name = $xprofile->username;
}
}
}
return $response;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment