Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Created December 7, 2018 16:18
Show Gist options
  • Save MrVibe/e73cd19650bbcfe03fd6bb52e272f81a to your computer and use it in GitHub Desktop.
Save MrVibe/e73cd19650bbcfe03fd6bb52e272f81a to your computer and use it in GitHub Desktop.
Show number of Certificates and Badges won by a Student
//USage : [wplms_student_certifiacate_badge_count type='certificate'] [wplms_student_certifiacate_badge_count type='badge']
//optionally mention user_id
add_shortcode('wplms_student_certifiacate_badge_count',function($atts,$content){
if(empty($atts['user_id'])){
if(is_user_logged_in()){
$atts['user_id] = get_current_user_id();
}else{
return;
}
}
if(!empty($atts) && !empty($atts['type']) && $atts['type'] == 'badge'){
$badges = get_user_meta($user_id,'badges',true);
if(empty($badges)){$badges = array();}
return '<div class="user_badge_count">'.count($badges).'</div>;
}else{
$certificates = get_user_meta($user_id,'certificates',true);
if(empty($certificates)){$certificates = array();}
return '<div class="user_certificate_count">'.count($certificates).'</div>;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment