Last active
April 12, 2022 02:46
-
-
Save MrVibe/c0ea6131147072b61dfa to your computer and use it in GitHub Desktop.
Custom User field in Course stats download version 4 compatible.
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 | |
if(!class_exists('WPLMS_Customizer_Plugin_Class')) | |
{ | |
class WPLMS_Customizer_Plugin_Class // We'll use this just to avoid function name conflicts | |
{ | |
public function __construct(){ | |
add_filter('wplms_course_stats_list',array($this,'add_custom_course_stat')); | |
add_action('wplms_course_stats_process',array($this,'process_custom_course_stat'),10,7); | |
} // END public function __construct | |
function add_custom_course_stat($list){ | |
$list['user_field']='Gender'; | |
return $list; | |
} | |
function process_custom_course_stat(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$data){ | |
if($field != 'user_field') // Ensures the field was checked. | |
return; | |
$csv_row_title='Gender'; | |
$x = array_filter($csv_title,function($item){ $csv_row_title='Gender';return $item['title'] == $csv_row_title; }); | |
if(count($x) < 1){ | |
$csv_title[$i]=['title'=>$csv_row_title, 'field'=> 'user_field']; | |
} | |
$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; | |
$data[$i][$field]=$field_val; | |
}else{ | |
$csv[$i][]= 'N.A'; | |
$data[$i][$field]='N.A'; | |
} | |
} | |
// ADD custom Code in clas | |
} // END class WPLMS_Customizer_Class | |
} // END if(!class_exists('WPLMS_Customizer_Class')) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment