Advertisement
designbymerovingi

myCRED: Rank Progress with Visual Composer Progress Bar

Jan 2nd, 2014
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. /**
  2.  * Users Rank Progress
  3.  * @version 1.1
  4.  */
  5. add_shortcode( 'mycred_rank_progress', 'mycred_pro_users_rank_progress' );
  6. function mycred_pro_users_rank_progress( $user_id ) {
  7.  
  8.     if ( ! function_exists( 'mycred' ) ) return '';
  9.  
  10.     // Load myCRED
  11.     $mycred = mycred();
  12.  
  13.     // Ranks are based on a total
  14.     if ( $mycred->rank['base'] == 'total' )
  15.         $key = $mycred->get_cred_id() . '_total';
  16.     // Ranks are based on current balance
  17.     else
  18.         $key = $mycred->get_cred_id();
  19.  
  20.     // Get Balance
  21.     $users_balance = $mycred->get_users_cred( $user_id, $key );
  22.    
  23.     // Rank Progress
  24.    
  25.     // Get the users current rank post ID
  26.     $users_rank = (int) mycred_get_users_rank( $user_id, 'ID' );
  27.    
  28.     // Get the ranks set max
  29.     $max = get_post_meta( $users_rank, 'mycred_rank_max', true );
  30.    
  31.     // Calculate progress. We need a percentage with 1 decimal
  32.     $progress = number_format( ( ( $users_balance / $max ) * 100 ), 1 );
  33.    
  34.     // Visual Composer customization
  35.     $options = '';
  36.    
  37.     // If progress is less then 100%, use the stipped animation to indicate progress
  38.     if ( $progress < number_format( 100, 1 ) )
  39.         $options = 'options="striped,animated"';
  40.     // Else use the fixed background color to indicate completion
  41.     else
  42.         $progress = number_format( 100, 1 );
  43. ?>
  44.  
  45. <div class="bp-widget mycred-field">
  46.     <div class="wpb_row row">
  47.         <div class="col-md-12 col-sm-12 wpb_column column_container">
  48.             <div class="wpb_wrapper">
  49.                 <div class="vc_text_separator wpb_content_element separator_align_left"><div>Rank Progress</div></div>
  50.             </div>
  51.         </div>
  52.     </div>
  53.     <?php echo do_shortcode( '[vc_row][vc_column width="1/1"][vc_progress_bar values="' . $progress . '|' . get_the_title( $users_rank ) . '" bgcolor="custom" ' . $options . ' custombgcolor="#E74C3C" title="" units="%"]<p><span class="description">your current progress towards the next rank</p>[/vc_column][/vc_row]' ); ?>
  54.  
  55. </div>
  56. <?php
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement