function settings_field_points_shares_callback() { if (!bppp_has_point_items()) { return false; } $total_points = bppp_get_total_points(); while (bppp()->have_points()) { bppp()->the_point(); $current_point = bppp()->query->point; $percent = 0; if ($current_point['points']) { $percent = round($current_point['points'] / $total_points * 100, 1); } ?> <span> <strong><?php echo $current_point['label']; ?> : </strong> <?php printf(__('%1d points (%2d%% of total)', 'bppp'), $current_point['points'], $percent); ?> — <?php printf(__('Callback used : %1s', 'bppp'), '<code>' . $current_point['callback'] . '</code>'); ?> </span><br/> <?php } }
function bppp_get_user_progression_percent($user_id = false) { $user_id = bppp_get_user_id($user_id); if (!$user_id) { return false; } if (!bppp_has_point_items()) { return false; } while (BuddyPress_Profile_Progression()->have_points()) { BuddyPress_Profile_Progression()->the_point(); $item = BuddyPress_Profile_Progression()->query->point; $potential_points += $item['points']; $item_points = BuddyPress_Profile_Progression()->query->point['callback'](); if ($item_points === true) { //returned TRUE, wich means 100% of potential points $item_points = 100; } //balance points $add_points = $item_points / 100 * $item['points']; $user_points += $add_points; } //calculate total if (!empty($potential_points)) { $percent = round($user_points / $potential_points * 100); } return (int) $percent; }