Created
March 31, 2026 09:52
-
-
Save annuman97/e053d939d36ed9204f76114ffec6ebcc to your computer and use it in GitHub Desktop.
Show community username instead of full name in Fluent Community leaderboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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