0. Install WPLMS customiser plugin.
1. Go to WP Admin -> Plugins ->Editor -> Wplms customizer -> customizer_class.php
2. Add this code in __construct function :
Assuming the custom user field is Location :
3. Add this code in the class :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
function add_custom_course_stat($list){ $list['user_field']= 'Location'; return $list; } function process_custom_course_stat(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field){ if($field != 'user_field') // Ensures the field was checked. return; $title=__('Location','vibe'); if(!in_array($title,$csv_title)) $csv_title[$i]=$title; $ifield = 'Location'; if(bp_is_active('xprofile')) $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id ); if(isset($field_val) && $field_val) $csv[$i][]= $field_val; else $csv[$i][]= 'N.A'; } |
For adding multiple fields:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
function add_custom_course_stat($list){ $new_list = array( 'user_field1'=>'Location', 'user_field2'=>'Bio' //add another element like same above 'user_field3'=>'Gender' ); $list=array_merge($list,$new_list); return $list; } function process_custom_course_stat(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field){ if( strpos($field, 'user_field1') === false && strpos($field, 'user_field2') === false)//if another field please include it here like this if( strpos($field, 'user_field1') === false && strpos($field, 'user_field2') === false && strpos($field, 'user_field3') === false) return; if($field == 'user_field1'){ $title=__('Location','vibe'); if(!in_array($title,$csv_title)) $csv_title[$i]=$title; $ifield = 'Location'; if(bp_is_active('xprofile')) $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id ); if(isset($field_val) && $field_val) $csv[$i][]= $field_val; else $csv[$i][]= 'N.A'; return; } if($field == 'user_field2'){ $title=__('Bio','vibe'); if(!in_array($title,$csv_title)) $csv_title[$i]=$title; $ifield = 'Bio'; if(bp_is_active('xprofile')) $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id ); if(isset($field_val) && $field_val) $csv[$i][]= $field_val; else $csv[$i][]= 'N.A'; return; } //add process doe another field like : /* if($field == 'user_field3'){ $title=__('Gender','vibe'); if(!in_array($title,$csv_title)) $csv_title[$i]=$title; $ifield = 'Gender'; if(bp_is_active('xprofile')) $field_val= bp_get_profile_field_data( 'field='.$ifield.'&user_id=' .$user_id ); if(isset($field_val) && $field_val) $csv[$i][]= $field_val; else $csv[$i][]= 'N.A'; return; } */ } |
Github gist : https://gist.github.com/MrVibe/c0ea6131147072b61dfa