Advertisement
designbymerovingi

Add rank progress in the bottom of the rank post type conten

Aug 18th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. add_filter( 'the_content', 'mycred_rank_progress_bar_in_bottom' );
  2. function mycred_rank_progress_bar_in_bottom( $content ) {
  3.  
  4. global $post;
  5.  
  6. if ( $post->post_type == 'mycred_rank' && function_exists( 'mycred' ) ) {
  7.  
  8. $mycred = mycred();
  9.  
  10. $min = get_post_meta( $post->ID, 'mycred_rank_min', true );
  11. $max = get_post_meta( $post->ID, 'mycred_rank_max', true );
  12.  
  13. ob_start(); ?>
  14.  
  15. <div class="blog-pad blog-content-excerpt">
  16. <p>This rank requires a minimum token earnings of <?php echo $mycred->format_creds( $min ); ?>.</p>
  17. <?php if ( is_user_logged_in() ) : $users_balance = $mycred->get_users_balance( get_current_user_id() ); ?>
  18.  
  19. <h5>Your rank progress</h5>
  20. <?php
  21. $progress = number_format( ( ( $users_balance / $max ) * 100 ), 1 );
  22. $options = 'options="striped,animated"';
  23.  
  24. if ( $users_balance > $min && $users_balance > $max ) {
  25. $progress = number_format( 100, 1 );
  26. $options = '';
  27. }
  28. elseif ( $users_balance < $min ) {
  29. $progress = number_format( 0, 1 );
  30. $options = '';
  31. }
  32.  
  33. echo do_shortcode( '[vc_row][vc_column width="1/1"][vc_progress_bar values="' . $progress . '|' . get_the_title() . '" bgcolor="custom" ' . $options . ' custombgcolor="#E74C3C" title="" units="%"]<div class="mycred-progress-desc"><div class="rank-minimum">' . $mycred->format_creds( $min ) . '</div><div class="rank-maximum">' . $mycred->format_creds( $max ) . '</div></div>[/vc_column][/vc_row]' );
  34.  
  35. endif;
  36. ?>
  37.  
  38. </div>
  39. <?php
  40. $bottom = ob_get_contents();
  41. ob_end_clean();
  42. $content .= $bottom;
  43. }
  44.  
  45. return $content;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement