Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Users Rank Progress
- * @version 1.1
- */
- add_shortcode( 'mycred_rank_progress', 'mycred_pro_users_rank_progress' );
- function mycred_pro_users_rank_progress( $user_id ) {
- if ( ! function_exists( 'mycred' ) ) return '';
- // Load myCRED
- $mycred = mycred();
- // 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 = (int) mycred_get_users_rank( $user_id, 'ID' );
- // Get the ranks set max
- $max = get_post_meta( $users_rank, 'mycred_rank_max', true );
- // Calculate progress. We need a percentage with 1 decimal
- $progress = number_format( ( ( $users_balance / $max ) * 100 ), 1 );
- // Visual Composer customization
- $options = '';
- // If progress is less then 100%, use the stipped animation to indicate progress
- if ( $progress < number_format( 100, 1 ) )
- $options = 'options="striped,animated"';
- // Else use the fixed background color to indicate completion
- else
- $progress = number_format( 100, 1 );
- ?>
- <div class="bp-widget mycred-field">
- <div class="wpb_row row">
- <div class="col-md-12 col-sm-12 wpb_column column_container">
- <div class="wpb_wrapper">
- <div class="vc_text_separator wpb_content_element separator_align_left"><div>Rank Progress</div></div>
- </div>
- </div>
- </div>
- <?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]' ); ?>
- </div>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement