General developer forum

 
 
Picture of Michael E
Re: force users to complete custom profile fileds when login
Group Testers

I just found the answer myself.

    1. Open the file lib/moodlelib.php
    2. Search for: function user_not_fully_set_up($user) {(approx. line 3383)
    The complete function looks like this:
    function user_not_fully_set_up($user) {
        if (isguestuser($user)) {
            return false;
        }
        return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user));
    }
    3. Edit the return string according to your needs. Use the shortname of the field you want to force users to fill in. The correct usage is: empty($user->profile['short_fieldname'])
    If the fieldname for example is managersemail (from the Face-to-Face mod), change the return string to:

return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or empty($user->profile['managersemail']) or over_bounce_threshold($user));

Hope that helps!

 
Average of ratings:Useful (1)
Picture of David Hempy
Re: force users to complete custom profile fileds when login
 

Thank you, Michael!  I just implemented this on our 2.5 server

I added a permissions check to only require the extra fields from students (not admins, teachers, etc.).  That part kinda works, but has issues since students are difficult to detect outside of a course.  I'm going to tinker with it some more later, but here's a start if anyone else wants to pursue it.

    return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user)
       or (
           (    empty($user->profile['BirthMonth'])
             or empty($user->profile['BirthDate'])
             or empty($user->profile['BirthYear'])  
           ) and !has_capability('report/courseoverview:view', context_system::instance())  // Allows teacher to avoid required birthdate.
       )       
    );

 
Average of ratings: -