I'm trying to add the email and whstapp field to the course report but I'm not succeeding. The email field is working, but the WhatsApp field is not.
I have already created a custom profile field and in the code I have also specified its ID. When I issue the report with the WhatsApp field, instead of pulling the number, it brings up the BR symbol.
Can you help me with this?
Below is the code I'm using in wplms customizer
/* * This code adds the Email and Whatsapp field to the export list in the course statistics. */
function add_custom_course_stat($list){ $new_list = array( 'email'=>'Email', 'user_field29'=>'Whatsapp' );
function process_custom_course_stat_email(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$ccsv,&$k){ if($field != 'email') // Ensures that the field has been verified. return;
function process_custom_course_stat_whatsapp(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$ccsv,&$k){ if($field != 'user_field29') // Ensures that the field has been verified. return;
Could you tell me if you have any position on this point? I really need help with this solution. My client is charging for this field in the course report and I'm stuck.
function process_custom_course_stat_whatsapp(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$ccsv,&$k){ if($field != 'user_field29') // Ensures the field was checked. return;
Hello everything is fine?
I'm trying to add the email and whstapp field to the course report but I'm not succeeding. The email field is working, but the WhatsApp field is not.
I have already created a custom profile field and in the code I have also specified its ID. When I issue the report with the WhatsApp field, instead of pulling the number, it brings up the BR symbol.
Can you help me with this?
Below is the code I'm using in wplms customizer
/*
* This code adds the Email and Whatsapp field to the export list in the course statistics.
*/
function add_custom_course_stat($list){
$new_list = array(
'email'=>'Email',
'user_field29'=>'Whatsapp'
);
$list=array_merge($list,$new_list);
return $list;
}
add_action('wplms_course_stats_process','process_custom_course_stat_email',10,8);
add_filter('wplms_course_stats_list','add_custom_course_stat');
function process_custom_course_stat_email(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$ccsv,&$k){
if($field != 'email') // Ensures that the field has been verified.
return;
$title=__('Email','wplms');
if(!in_array($title,$csv_title))
$csv_title[$k]=array('title'=>$title,'field'=>'Email');
$ifield = 'Email';
$user = get_user_by('id',$user_id);
$field_val = $user->data->user_email;
if(isset($field_val) && $field_val){
$csv[$i][]= $field_val;
$ccsv[$i]['Email'] = $field_val;
}else{
$csv[$i][]= 'NA';
$ccsv[$i]['Email'] = 'NA';
}
}
//CAMPO WHATSAPP
add_action('wplms_course_stats_process','process_custom_course_stat_whatsapp',10,8);
add_filter('wplms_course_stats_list','add_custom_course_stat');
function process_custom_course_stat_whatsapp(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$ccsv,&$k){
if($field != 'user_field29') // Ensures that the field has been verified.
return;
$title=__('Whatsapp','wplms');
if(!in_array($title,$csv_title))
$csv_title[$k]=array('title'=>$title,'field'=>'user_field29');
$ifield = 'Whatsapp';
if(bp_is_active('xprofile'))
$field_val= bp_get_profile_field_data( 'field=8&user_id=' .$user_id );
if(isset($field_val) && $field_val){
$csv[$i][]= $field_val;
$ccsv[$i]['user_field29'] = $field_val;
}else{
$csv[$i][]= 'NA';
$ccsv[$i]['user_field29'] = '';
}
}
Attached files: Captura de Tela 2023-10-26 às 16.11.14.png
bp_get_profile_field_data( 'field=8&user_id=' .$user_id ); , try entering field Name instead of field ID
OR send an array with field ID, if passing a string use field name.
optionally you can just replace the function bp_get_profile_field_data with xprofile_get_field_data
I replaced the bp_get_profile_field_data function with xprofile_get_field_data and it didn't work. Could you look at that for me?
I will share with you in private reply url, login and password for access.
checking this...
Hello how are you?
Could you tell me if you have any position on this point? I really need help with this solution. My client is charging for this field in the course report and I'm stuck.
I managed to make it work using the code below:
add_action('wplms_course_stats_process','process_custom_course_stat_whatsapp',10,8);
add_filter('wplms_course_stats_list','add_custom_course_stat');
function process_custom_course_stat_whatsapp(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$ccsv,&$k){
if($field != 'user_field29') // Ensures the field was checked.
return;
$title=__('Whatsapp','wplms');
if(!in_array($title,$csv_title))
$csv_title[$k]=array('title'=>$title,'field'=>'user_field29');
$ifield = 'Whatsapp';
if(bp_is_active('xprofile'))
$field_val= bp_get_profile_field_data( 'field=29&user_id=' .$user_id );
if(isset($field_val) && $field_val){
$csv[$i][]= $field_val;
$ccsv[$i]['user_field29'] = $field_val;
}else{
$csv[$i][]= 'NA';
$ccsv[$i]['user_field29'] = '';
}
}
this looks great, thank you for sharing this with us.