diff --git a/user_badges.module b/user_badges.module index e54b167..5c458b7 100644 --- a/user_badges.module +++ b/user_badges.module @@ -196,29 +196,26 @@ function user_badges_user($op, &$edit, &$account, $category = 'account') { if (isset($badges[$account->uid])) { $account->badges = $badges[$account->uid]; } + else { + $account->badges = array(); + } if ($account->uid > 0) { //Get all user badges for this user, regardless of whether we filter the ones we show. $account->badges_all = user_badges_get_badges($account->uid, array('nolimit' => TRUE)); //Now make the array of badges we will show. - if (variable_get('user_badges_showone', 0)) { - //Figure out our limit to the number of badges - if (variable_get('user_badges_showone', 0)) { - $limit = variable_get('user_badges_showone', 1); - } - else { - //Set to -1 for no limit - $limit = -1; - } + if ($limit = variable_get('user_badges_showone', 0)) { //Loop through all potential badges and get the ones we can show - foreach ($account->badges_all as $bid => $badge) { - //Display the badge if there's no limit or if the badge is unhideable or if we are within our limit - if ( $limit != 0 || $badge->unhideable == 1 ) { - $account->badges[$bid] = $badge; - //Count down our limit, unless the badge doesn't count towards it - if (!$badge->doesnotcounttolimit) { - $limit--; + if (is_array($account->badges_all)) { + foreach ($account->badges_all as $bid => $badge) { + //Display the badge if there's no limit or if the badge is unhideable or if we are within our limit + if ( $limit != 0 || $badge->unhideable == 1 ) { + $account->badges[$bid] = $badge; + //Count down our limit, unless the badge doesn't count towards it + if (!$badge->doesnotcounttolimit) { + $limit--; + } } } }