Advertisement
Guest User

BadgeOS custom display shortcode

a guest
Oct 27th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2. /**
  3. * Display earned badges for a given user
  4. *
  5. * @param array $atts Our attributes array
  6. * @return string Concatenated markup
  7. */
  8. function prefix_badgeos_user_achievements_shortcode( $atts = array() ) {
  9.  
  10. // Parse our attributes
  11. $atts = shortcode_atts( array(
  12. 'user' => get_current_user_id(),
  13. 'type' => '',
  14. 'limit' => 5
  15. ), $atts );
  16.  
  17. $output = '';
  18.  
  19. // Grab the user's current achievements, without duplicates
  20. $achievements = array_unique( badgeos_get_user_earned_achievement_ids( $atts['user'], $atts['type'] ) );
  21.  
  22. // Setup a counter
  23. $count = 0;
  24.  
  25. $output .= '<div class="badgeos-user-badges-wrap">';
  26.  
  27. // Loop through the achievements
  28. if ( ! empty( $achievements ) ) {
  29. foreach( $achievements as $achievement_id ) {
  30.  
  31. // If we've hit our limit, quit
  32. if ( $count >= $atts['limit'] ) {
  33. break;
  34. }
  35.  
  36. // Output our achievement image and title
  37. $output .= '<div class="badgeos-badge-wrap">';
  38. $output .= badgeos_get_achievement_post_thumbnail( $achievement_id );
  39. $output .= '<span class="badgeos-title-wrap">' . get_the_title( $achievement_id ) . '</span>';
  40. $output .= '</div>';
  41.  
  42. // Increase our counter
  43. $count++;
  44. }
  45. }
  46. $output .= '</div>';
  47.  
  48. return $output;
  49. }
  50. add_shortcode( 'custom_badgeos_user_achievements', 'prefix_badgeos_user_achievements_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement