-
-
Save brichards/efca231489941b5c0a63 to your computer and use it in GitHub Desktop.
Earned badges function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display earned badges for a given author | |
* | |
* @param integer $author_id The user's ID, defaults to current post author | |
* @param string $achievement_type A specific type of achievement to list (e.g. 'badge'), default: all | |
* @param integer $limit Number of achievements to include, default: 10 | |
*/ | |
function custom_badgeos_get_author_achievements( $author_id = 0, $achievement_type = '', $limit = 10 ) { | |
// Get the post author if no specific user specified. | |
if ( ! $author_id ) { | |
global $post; | |
$author_id = $post->post_author; | |
} | |
// Grab the user's current achievements, without duplicates | |
$achievements = array_unique( badgeos_get_user_earned_achievement_ids( $author_id, $achievement_type ) ); | |
// Setup a counter | |
$count = 0; | |
// Loop through the achievements | |
if ( ! empty( $achievements ) ) { | |
foreach( $achievements as $achievement_id ) { | |
// If we've hit our limit, quit | |
if ( $count >= $limit ) | |
break; | |
// Output our achievement image and title | |
echo badgeos_get_achievement_post_thumbnail( $achievement_id ); | |
echo '<span class="badgeos-title-wrap">' . get_the_title( $achievement_id ) . '</span>'; | |
// Increase our counter | |
$count++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment