Add custom user profile fields to statistic

Home Forums Legacy Support Support queries How-to & Troubleshooting Add custom user profile fields to statistic

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #340233
    Marco
    Spectator
    Hi, I have I would like to know if is possible in WPLMS version 4 to add more fields from user (like email address) and from profile (like first name and last name) to the statistics. I tryed all the code tips in the forum, but didn't work and the values are empty https://wplms.io/support/knowledge-base/add-custom-user-field-in-download-course-stats/ https://wplms.io/support/knowledge-base/add-a-custom-information-in-course-stats-download-report/ Thank you, Marco
    #340487
    Diana
    Participant
    Before: http://prntscr.com/zphen4 After: http://prntscr.com/zphqv0
    
    
    add_filter('wplms_course_stats_list','add_custom_course_stat');
    add_action('wplms_course_stats_process','process_custom_course_stat',10,6);
    
              
            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';
              
             }
    
             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;
    }
    
    Add this in wp-admin > Plugins > editor > Select WPLMS Customizer Plugin > wplms-customizer.php
    #340556
    Marco
    Spectator
    Dear Diana, thank you for suggestion, but I think that there is something wrong, I added the code in the wp-admin > Plugins > editor > WPLMS Customizer Plugin but only the labels are shown. In my profile fields I have the 2 fields "Nome" and "Cognome": https://prnt.sc/zqdtft Thank you for support, Marco
    #340792
    Diana
    Participant
    There is nothing wrong with the code, the field you are passing in the code to show there. make sure you have the same fields in the wp-admin > Users > profile fields So it can fetch some data
    #340802
    Marco
    Spectator
    Dear Diana, I have fields in User > Profile Fields but in frontend nothing is displayed, I need to update something like buddypress navigation or permalinks? From your code I replaced "Location" with "Nome" that is my custom profile field name that students fill during the registration. The field is correctly filled if I look at the student profile, but in statistics is empty. Thank you for any suggestion!
    #341724
    Marco
    Spectator
    Dear Diana, I tryed a lot of times, also without any plugin ore code activated, but all the time the table with the custom fields are empty. Can you confirm that the solution works in version 4? Thank you for help. Marco
    #342007
    Diana
    Participant
    This reply has been marked as private.
    #342148
    Marco
    Spectator
    Dear Diana, do you have any update on this? Thank you, Marco
    #342388
    Anshuman Sahu
    Keymaster
    try this :
    add_action('wplms_course_stats_process','process_custom_course_stat',10,8);
    add_filter('wplms_course_stats_list','add_custom_course_stat');
    
     function add_custom_course_stat($list){
       $new_list = array(
                        'user_field1'=>'Location',
                        'nome'=>'Nome'
                        //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,&$ccsv,&$k){
      if($field != 'nome') // Ensures the field was checked.
         return;
    
        $title=__('Nome','wplms');
    	if(!in_array($title,$csv_title))
    	 $csv_title[$k]=array('title'=>$title,'field'=>'nome');
    		$ifield = 'Nome'; 
      	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;
    	      	$ccsv[$i]['nome'] =  $field_val;
    	   
        }else{
    
          $csv[$i][]= 'NA';
          $ccsv[$i]['nome'] = 'NA';
        }
    	
    
     }
Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Add custom user profile fields to statistic’ is closed to new replies.