View Full Version : Custom Field/Userfield in Subscription
Bundschuh
07-20-2012, 11:01 AM
Hi there,
does somebody knows a elegant way to use custom fields in the subscription mails?
I have to send Mails with the users real name like "Dear John, there are new replies ...."
In Lang & Phrases -> Email Body Text -> notify, there are only the variable $touser which doesn't contains any custom user fields.
$vbulletin->userinfo[field5] only give me the custom field of the user who has post the reply by whom the subscription notification was initiated.
Greetings for every advices
Bundschuh
There are two ways of doing that that I can see (I don't know if either would qualify as "elegant"): One would be to edit the file includes/functions_newpost.php and change the query that finds the users (around line 1186). You could add a JOIN of the userfield table, and add the fields you want to the fields being selected, then they should be available in $touser.
The other way would be to write a plugin using hook newpost_notification_message and write your own query to get the field. This way you're not modifying any files, but it would add 1 query per subscribed user every time someone posts.
Bundschuh
07-20-2012, 01:44 PM
These were also my first thoughts.
Using of hook location is more "elegant" than direct code modification. :)
But in this case, I thinks it's not the fastest solution.
I tried to get the custom field with $vbulletin->db->query_first('SELECT `field5` AS realname FROM `'.TABLE_PREFIX.'userfield` AS uf LEFT JOIN `'.TABLE_PREFIX.'user` AS u ON u.`userid` = uf.`userid` WHERE u.`userid` = ' . $touser['userid']) but its pretty slow.
Also I can't simply str_replace the username in the template with the fetched custom field because the template will be rendered after the hook location .
So I have to use the loaded template in array $evalemail[$touser['languageid']] and write back my changes...
TI tried to get the custom field with $vbulletin->db->query_first('SELECT `field5` AS realname FROM `'.TABLE_PREFIX.'userfield` AS uf LEFT JOIN `'.TABLE_PREFIX.'user` AS u ON u.`userid` = uf.`userid` WHERE u.`userid` = ' . $touser['userid']) but its pretty slow.
If you have the userid and just want field5, you don't really need a join, just SELECT field5 FROM userfield WHERE userid = $touser['userid'].
Also I can't simply str_replace the username in the template with the fetched custom field because the template will be rendered after the hook location .
So I have to use the loaded template in array $evalemail[$touser['languageid']] and write back my changes...
Hmm..yeah, that's a problem. I was thinking you were just going to edit the phrase and put in $touser['realname'] or something.
Bundschuh
07-23-2012, 02:21 PM
If you have the userid and just want field5, you don't really need a join, just SELECT field5 FROM userfield WHERE userid = $touser['userid'].
Yeah, that's right.
Hmm..yeah, that's a problem. I was thinking you were just going to edit the phrase and put in $touser['realname'] or something.
No I will do some more complex modifications based on different conditions. But I simply copied the Code from functions_newpost.php (around line 1178) which will eval the notify templates and fill the variables $message and $subject. Now I can parse it and change it for my needs.
// copied from functions_newpost.php (line 1178)
eval(
iif(empty($evalemail["$touser[languageid]"]),$evalemail["-1"],
$evalemail["$touser[languageid]"])
);
For preventing override of these two variables I emptied the array holding the notify templates.
$evalemail[$touser['languageid']] = null;
$evalemail['-1'] = null;
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.