Last active
          November 27, 2021 10:21 
        
      - 
      
 - 
        
Save MrVibe/0c6d7b0853673326f4d9e2017eb3db37 to your computer and use it in GitHub Desktop.  
    Stop user from Starting a course if profile incomplete. WPLMS V4
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | add_filter('wplms_before_course_status_api',function($stop,$course_id,$user_id){ | |
| $groups = bp_xprofile_get_groups( array( | |
| 'fetch_fields' => true | |
| ) ); | |
| $cflag= 1; | |
| foreach($groups as $group){ | |
| if(!empty($group->fields)){ | |
| foreach ( $group->fields as $field ) { | |
| if($cflag ){ | |
| if(xprofile_check_is_required_field( $field->id ) ){ | |
| $types = bp_xprofile_get_meta( $field->id, 'field', 'member_type', false ); | |
| $member_type = bp_get_member_type($user_id); | |
| if(empty($types) || (!empty($types) && in_array($member_type,$types))){ | |
| $val = xprofile_get_field_data( $field->id, $user_id); | |
| if(empty($val)){ | |
| $cflag = 0; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if(!$cflag){ //only if you want to stop user on incomplete profile | |
| $stop = array('icon'=>'vicon-lock','error_code'=>'profilecomplete','error_message'=>_x('Please complete your profile','','wplms')); | |
| } | |
| if(empty($stop)){ | |
| $fetch_user_avatar = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true,'html'=> false ) ); | |
| $default_avatar = bp_core_avatar_default(); | |
| if(defined('VIBE_URL')){ | |
| $default_avatar = VIBE_URL.'/assets/images/avatar.jpg'; | |
| } | |
| if(function_exists('vibe_get_option')){ | |
| if(!empty(vibe_get_option('default_avatar'))){ | |
| $default_avatar = vibe_get_option('default_avatar'); | |
| } | |
| } | |
| if ( $fetch_user_avatar == $default_avatar){ | |
| $stop = array('icon'=>'vicon-lock','error_code'=>'profilecomplete','error_message'=>_x('Please upload your profile image','error','wplms')); | |
| } | |
| } | |
| return $stop; | |
| },10,3); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment