Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Created November 29, 2020 14:25
Show Gist options
  • Save MrVibe/20e1747a7eacb562a8538a4fe9425468 to your computer and use it in GitHub Desktop.
Save MrVibe/20e1747a7eacb562a8538a4fe9425468 to your computer and use it in GitHub Desktop.
Capture Batch details for Certificate
add_shortcode('certificate_batch_details',function($atts,$content=null){
extract(shortcode_atts(array(
'student_id' => '',
'course_id' =>'',
'detail'=>'0' //name, administartor,
), $atts));
if(!isset($course_id) || !is_numeric($course_id)){
$course_id=$_GET['c'];
}
if(!isset($student_id) || !is_numeric($student_id)){
$student_id=$_GET['u'];
}
if(wplms_course_has_batches($course_id)){
global $wpdb,$bp;
$batches = $wpdb->get_results(
$wpdb->prepare("SELECT gm.group_id as batch_id
FROM {$bp->groups->table_name_members} as g
LEFT JOIN {$bp->groups->table_name_groupmeta} as gm
ON g.group_id = gm.group_id
WHERE g.user_id = %d
AND gm.meta_key = %s
AND gm.meta_value = %d",
$student_id,'batch_course',$course_id));
if(!empty($batches)){
$batch_id = $batches[0]->batch_id; //Capture the first batch user is enrolled into
if($detail == 'name'){
$group = groups_get_group($batch_id);
return $group->name;
}
if($detail == 'administrator'){
$admins = groups_get_group_admins( $batch_id );
return bp_core_get_user_displayname($admins[0]->user_id);
}
}
}
return '[certificate_batch_details]';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment