Advertisement
designbymerovingi

myCRED Ranks Archive example

Nov 26th, 2013
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.06 KB | None | 0 0
  1. <?php
  2. /**
  3.  * myCRED Rank Archive
  4.  * @since 0.1
  5.  * @version 1.0
  6.  */
  7. get_header();
  8.  
  9. // Load myCRED (if installed)
  10. $mycred = NULL;
  11. if ( function_exists( 'mycred_get_settings' ) )
  12.     $mycred = mycred_get_settings();
  13.  
  14. $user_id = false;
  15. $progress = false;
  16.  
  17. // Only show the progress bar for logged in users.
  18. if ( is_user_logged_in() ) {
  19.     // Grab the current user id
  20.     $user_id = get_current_user_id();
  21.  
  22.     // Make sure the current user is not excluded from using myCRED
  23.     if ( ! $mycred->exclude_user( $user_id ) ) {
  24.         // If ranks are based on total gains
  25.         if ( $mycred->rank['base'] == 'total' )
  26.             $key = $mycred->get_cred_id() . '_total';
  27.         // Else ranks are based on the current balance
  28.         else
  29.             $key = $mycred->get_cred_id();
  30.  
  31.         // Grab the "balance" or "total"
  32.         $users_balance = $mycred->get_users_cred( $user_id, $key );
  33.     }
  34. }
  35.  
  36. // Highlight admins
  37. $admin = false;
  38. if ( is_user_logged_in() && current_user_can( 'edit_users' ) )
  39.     $admin = true; ?>
  40.  
  41.     <div class="row">
  42.         <div class="col-md-12" id="content-header">
  43.             <h1 class="entry-title" id="bp-klein-page-title">myCRED Membership Ranks</h1>
  44.         </div>
  45.         <div class="klein-breadcrumbs col-md-12">
  46.             <a title="Go to myCRED." href="http://mycred.me" class="home">myCRED</a><span class="breadcrumb-separator">/</span><a title="Go to Members." href="http://mycred.me/members/" class="members">Members</a><span class="breadcrumb-separator">/</span>Ranks
  47.         </div>
  48.     </div>
  49.    
  50.     <div class="row">
  51.         <section id="primary" class="content-area col-md-8 col-sm-8">
  52.             <div id="content" class="site-content" role="main">
  53.  
  54.             <!-- Lets start the WordPress loop -->
  55.             <?php if ( have_posts() ) : ?>
  56.                 <?php while ( have_posts() ) : the_post(); ?>
  57.  
  58.                 <article id="post-<?php the_ID(); ?>" <?php post_class( array( 'blog-list' ) ); ?>>
  59.    
  60.                 <div class="entry-content">
  61.                     <div class="blog-author">
  62.                     <?php if ( function_exists( 'bp_core_fetch_avatar' ) ) { ?>
  63.                         <div class="blog-author-avatar"<?php if ( has_post_thumbnail() ) echo ' style="background-color:white;"'; ?>>
  64.                             <?php
  65.     // The default rank does not have a logo, instead we insert the users avatar
  66.     if ( has_post_thumbnail() )
  67.         the_post_thumbnail( 'thumbnail' );
  68.     else
  69.         echo bp_core_fetch_avatar( array( 'type' => 'full', 'item_id' => get_current_user_id() ) ); ?>
  70.                         </div>
  71.                         <div class="blog-author-name center"></div>
  72.                         <div class="blog-author-links"></div>
  73.                 <?php } else { ?>
  74.                     <div class="blog-author-avatar no-bp"><?php echo get_avatar( get_current_user_id(), 75 ); ?></div>
  75.                     <div class="blog-author-name no-bp center">
  76.                         <a class="tip" data-delay="0" data-placement="bottom" data-original-title="<?php _e( 'Posts', 'klein' ); ?>" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
  77.                             <?php echo get_the_author(); ?>
  78.                         </a>
  79.                     </div>
  80.                 <?php } ?>
  81.             </div>
  82.             <div class="blog-content">
  83.                 <div class="blog-pad blog-content-title">
  84.                     <h2>Rank: <?php the_title(); ?></h2>
  85.                 </div>
  86.                 <div class="blog-pad blog-content-excerpt">
  87.                     <?php
  88.                     // Get the rank details (ID, Minimum and Maximum points
  89.                     $post_id = get_the_ID();
  90.                     $min = get_post_meta( $post_id, 'mycred_rank_min', true );
  91.                     $max = get_post_meta( $post_id, 'mycred_rank_max', true );
  92.                     ?>
  93.  
  94.                         <p>This rank requires a minimum token earnings of <?php echo $mycred->format_creds( $min ); ?>.</p>        
  95.                     <?php if ( is_user_logged_in() ) : ?>
  96.  
  97.                         <h5>Your rank progress</h5>
  98.                         <?php
  99.                     // Calculate progress in percentage with one decimal
  100.                     $progress = number_format( ( ( $users_balance / $max ) * 100 ), 1 );
  101.                     $options = 'options="striped,animated"';
  102.  
  103.                     // If we have surpassed this role show 100
  104.                     if ( $users_balance > $min && $users_balance > $max ) {
  105.                         $progress = number_format( 100, 1 );
  106.                         $options = '';
  107.                     }
  108.                     // If we have not yet come up to this rank
  109.                     elseif ( $users_balance < $min ) {
  110.                         $progress = number_format( 0, 1 );
  111.                         $options = '';
  112.                     }
  113.  
  114.                     // Lets use the Visual Editors "Progress Bar"
  115.                     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="%"][/vc_column][/vc_row]' ); ?>
  116.                     <?php endif; ?>
  117.                    
  118.                     <h5>Privileges</h5>
  119.                     <?php
  120.                    
  121.                     // Show rank privileges
  122.                     $priv = array();
  123.                     if ( get_post_meta( get_the_ID(), 'allow_messages', true ) )
  124.                         $priv[] = 'Send messages in BuddyPress.';
  125.                
  126.                     if ( ! empty( $priv ) ) {
  127.                         echo '<ul>';
  128.                        
  129.                         foreach ( $priv as $privilige )
  130.                             echo '<li>' . $privilige . '</li>';
  131.                        
  132.                         echo '</ul>';
  133.                     }
  134.                     else {
  135.                         echo '<p>This rank has no special privileges.</p>';
  136.                     } ?>
  137.  
  138.                     <?php
  139.                     // Get some users of this rank, 9 fits nicely with our theme
  140.                     $users_of_rank = mycred_get_users_of_rank( get_the_ID(), 9 );
  141.                     if ( ! empty( $users_of_rank ) ) {
  142.                         echo '<small><strong>my</strong>CRED members with this rank:</small><br />';
  143.                         echo '<div class="mycred-users-of-rank">';
  144.                         // Loop though users and show their avatar
  145.                         foreach ( $users_of_rank as $member )
  146.                             echo '<a href="' . bp_core_get_user_domain( $member['user_id'] ) . '" style="display: block; float:left;">' . get_avatar( $member['user_id'], 50 ) . '</a>';
  147.                         echo '</div>';
  148.                     }
  149.                     else {
  150.                         echo '<p>There are no members with this rank.</p>';
  151.                     }
  152.                     ?>
  153.  
  154.                 </div>
  155.                 <div class="blog-pad blog-content-meta">
  156.                     <footer class="entry-meta">&nbsp;</footer>
  157.                 </div> 
  158.             </div>
  159.             <!-- blog content end -->
  160.     </div><!-- .entry-content -->
  161.     <div class="clear"></div>
  162. </article><!-- #post-## -->
  163.    
  164.                 <?php endwhile; ?>
  165.    
  166.                 <?php klein_content_nav( 'nav-below' ); ?>
  167.    
  168.             <?php else : ?>
  169.    
  170.                 <?php get_template_part( 'no-results', 'archive' ); ?>
  171.    
  172.             <?php endif; ?>
  173.    
  174.             </div><!-- #content -->
  175.         </section><!-- #primary -->
  176.    
  177.         <div class="col-md-4 col-sm-4">
  178.             <?php get_sidebar(); ?>
  179.         </div>
  180.        
  181.     </div><!--.row-->  
  182. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement