User profile custom field in newusernewpasswordsubj

User profile custom field in newusernewpasswordsubj

by Dave Varon -
Number of replies: 1

Hi,

I've created a custom user profile field, a simple text field with short name:  StudyID.  

I would like to add this custom profile field to both newusernewpasswordsubj and newusernewpasswordtext

I have customized the en lang pack to send custom email notifications to manually created users, e.g., in newusernewpasswordtext

Hi {$a->firstname}, A new account has been created for you at '{$a->sitename}'

My assumption that I could do something like below is evidently incorrect:

Hi {$a->firstname}, A new account for {$a->StudyID} has been created for you at '{$a->sitename}'
or, even more importantly, in newusernewpasswordsubj:
{$a->StudyID}: New user account

Obviously, this doesn't work.  What will?

Any insight you can provide will be most helpful.

Thank you!

Dave

PS. incidentally, the {$a->firstname} substitution is returning the fullname (i.e., "firstname lastname") but I've not been able to pinpoint how.


Average of ratings: Useful (1)
In reply to Dave Varon

Re: User profile custom field in newusernewpasswordsubj

by Dave Varon -

I resolved this by customizing  

moodle/lib/moodlelib.php

specifically the function:

setnew_password_and_mail

more specifically, lines 5951-5953 (other lines incl. for context):

5943     $a = new stdClass();
5944     $a->firstname   = fullname($user, true);
5945     $a->sitename    = format_string($site->fullname);
5946     $a->username    = $user->username;
5947     $a->newpassword = $newpassword;
5948     $a->link        = $CFG->wwwroot .'/login/';
5949     $a->signoff     = generate_email_signoff();
5950
5951     require_once($CFG->dirroot.'/user/profile/lib.php');
5952     profile_load_data($user);
5953     $a->studyid      = $user->profile_field_StudyID;
5954
5955     $message = (string)new lang_string('newusernewpasswordtext', '', $a, $lang);
5956
5957     $subject = format_string($site->fullname) .': '. (string)new lang_string('newusernewpasswordsubj', '', $a, $lang);

and then I customized the "newusernewpasswordsubj" string in the language pack to use the {$a->studyid} placeholder.

H/t to Olumuyiwa Taiwo in his response to "Get Custom Fields info"  and to Shane Elliott in How do I get a custom profile field in the code?

Thanks eb,

Dave

Average of ratings: Useful (1)