View Full Version : Best way to obtain username from userid
mangus580
08-24-2009, 02:52 AM
What is the best method of getting a username when you have the userid?
I am working on a watermark plugin, that uses the hook attachment_display. It seems I can come up with the userid that posted the attachment quite easily, but I am unable to easily turn that into a username which is what I ultimately want.
Can anyone suggest anything?
Thanks!
Lynne
08-24-2009, 04:00 AM
If this is a continuation of your attachment mod from another thread, it might have been smart to keep this question in there so users have all the information. In this particular case, you should just JOIN the user table in the attachment query to grab the username at the same time all the other info about the user is grabbed. It looks like the hook to use would be attachment_start. It's always best to take a look at the code around any hook you are using (in this case the attachment_display hook) and see what else is going on (I said that before in regards to finding the userid).
mangus580
08-24-2009, 03:28 PM
I started a new tread, as I felt it was a different topic really... sorry :-(
What you describe sounds like an edit to a core file, is this true? I am really trying to avoid that if possible....
James Birkett
08-24-2009, 03:59 PM
Hooks are used to use custom code without having to edit source files.
Admin CP -> Plugins & Products -> Add New Plugin
Product: vBulletin
Hook: attachment_start
Title: Whatever you like
PHP Code: {Your code}
Plugin is Active: Yes
Lynne
08-24-2009, 04:30 PM
What you describe sounds like an edit to a core file, is this true? I am really trying to avoid that if possible....
Nope, just a plugin as James describes below:
Hooks are used to use custom code without having to edit source files.
Admin CP -> Plugins & Products -> Add New Plugin
Product: vBulletin
Hook: attachment_start
Title: Whatever you like
PHP Code: {Your code}
Plugin is Active: Yes
$hook_query_fields = ",user.username ";
$hook_query_joins = join the user table here ;
mangus580
08-24-2009, 10:55 PM
Got it, THANKS!!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.