Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get user's rank progress
- function get_mycred_users_rank_progress( $user_id = NULL, $show_rank = 'no' ) {
- if ( ! function_exists( 'mycred' ) ) return '';
- // Change rank data to displayed user when on a user's profile
- if ( function_exists( 'bp_is_user' ) && bp_is_user() && $user_id === NULL ) {
- $user_id = bp_displayed_user_id();
- }
- // Load myCRED
- $mycred = mycred();
- // Check if user is excluded
- if ( $mycred->core->exclude_user( $user_id ) ) return '';
- // Ranks are based on a total
- if ( $mycred->rank['base'] == 'total' )
- $key = $mycred->get_cred_id() . '_total';
- // Ranks are based on current balance
- else
- $key = $mycred->get_cred_id();
- // Get Balance
- $users_balance = $mycred->get_users_cred( $user_id, $key );
- // Rank Progress
- // Get the users current rank post ID
- $users_rank = mycred_get_users_rank_id( $user_id );
- // Get the name of the users current rank
- $users_rank_name = get_the_title( $users_rank );
- // Get the ranks set max
- $max = get_post_meta( $users_rank, 'mycred_rank_max', true );
- global $wpdb;
- $tabl_name = $wpdb->prefix . 'postmeta';
- // Get the users next rank post ID
- $next_ranks = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM {$tabl_name} WHERE meta_key = %s AND meta_value > %d ORDER BY meta_value * 1 LIMIT 1;", 'mycred_rank_min', $max ) );
- foreach( $next_ranks as $next_rank ) {
- $next_rank = $next_rank->post_id;
- }
- // Get the name of the users next rank
- $next_rank_name = get_the_title( $next_rank );
- // Get the ranks set min
- $next_rank_min = get_post_meta( $next_rank, 'mycred_rank_min', true );
- // Calculate progress. We need a percentage with 1 decimal
- if ( $users_balance > 0 )
- $progress = number_format( ( ( $users_balance / $max ) * 100 ), 0 );
- else
- $progress = 0;
- // Display rank progress bar
- echo '<div class="mycred-rank-progress">';
- echo '<h3 class="rank-progress-label" style="font-weight:bold;">Rank Progress ('. $progress .'%)</h3>';
- echo '<progress max="' . $max . '" value="' . $users_balance . '" class="rank-progress-bar">';
- echo '</progress>';
- if ( $show_rank == 'yes' ) {
- echo '<span class="current-rank" style="float:left;padding-top:1%;font-weight:bold;">'. $users_rank_name .'</span>';
- echo '<span class="next-rank" style="float:right;padding-top:1%;font-weight:bold;">'. $next_rank_name .'</span>';
- echo '<span class="points-progress" style="width:100%;float:left;margin-top: -4.5%;padding-top:1%;font-weight:bold;text-align:center;">'. $users_balance .' of '. $next_rank_min .'</span>';
- }
- echo '</div>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement