display badges to users

Home   »   display badges to users

 'collaborator.id = ' . $company_post_id,
    'limit' => -1,
);
$usersPod = pods('user', $params);

// loop through company user ids
while ($usersPod->fetch()) {
    $userID     = $usersPod->id();
    $user_caps  = get_user_meta($userID, 'wp_capabilities', true);
    $user_roles = array_keys((array) $user_caps);

    $user                            = array();
    $user["ID"]                      = $userID;
    $user["has_rcp_paid_membership"] = rcp_user_has_paid_membership($userID) ? true : false;
    $user["is_rcp_group_member"]     = rcpga_user_is_group_member($userID) ? true : false;
    $user["is_active_influencer"]    = user_can($userID, 'can_view_member_insights') && in_array('contributor', (array) $user_roles) ? true : false;

    // current member of past member
    if ($user["is_rcp_group_member"]) {
        $current_members[] = $user;
    } else {
        $past_members[] = $user;
    }

}

display_members_by_group($current_members, "current");
display_members_by_group($past_members, "past");

function display_members_by_group(array $members_array, string $group)
{

    if (count($members_array) > 0) {

        $membersPluarl = count($members_array) == 1 ? $group . " member." : $group . " members.";
        echo count($members_array) . " " . $membersPluarl . "\n";

        foreach ($members_array as $member) {

            $golden_style = "style='background: linear-gradient(160deg,#900,#fc6);'";
            $badges       = "";
            // determine if influencer badge should be displayed
            if ($member["is_active_influencer"]) {
                $badges = " Influencer ";
            } else {
                // determine if leader/lite badge should be displayed
                if ($member["is_rcp_group_member"] or $member["has_rcp_paid_membership"]) {
                    $badges = "Leader";
                } else {
                    $badges = "Lite";
                }

            }

            do_short('
                    [is admin]
                        [users include=' . $member["ID"] . ' orderby=last_name  user_file=archive-link list=div class="m-0 p-0" item=div]
                            [user avatar]
                            
                            [user archive-link] ' . $badges . '
                            [user position] 
                            [user edit-link]
                            
                        [/users]
                    [else]
                          [users include=' . $member["ID"] . ' orderby=last_name  user_file=archive-link list=div class="m-0 p-0" item=div]
                            [user avatar]
                            
                            [user archive-link] ' . $badges . '
                            [user position] 
                            
                        [/users]
                    [/is]
            ');
        }

    } else {
        echo "No " . $group . " members found.";
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *