Back to vBulletin 5 Connect Articles

[vB5] User Profile Fields in the postbit templates
by Lynne 10 Apr 2013
Rating: (2 votes - 5.00 average)

Using your User Profile Fields on your site

This article is written with the assumption that you have already created your own User Profile Fields in the User Profile Field Manager. If you need help with this, you may read about it in the manual here - http://www.vbulletin.com/docs/html/profile

For the Purposes of this article, I will be referring to "fieldx" as the name of your profile field. Your real name will be found in the User Profile Manager in the "Name" column - field1, field2, etc.

First thing to do is figure out which fields you want to add to your postbit. Go to your Admincp > User Profile Fields > User Profile Field Manager and note both the Field Name (field1, field2, etc) and the Category the field is in (see image 1). The Profile Fields are listed under their Category Title on this page. It should either be "(Uncategorized)" or have some other category listed. To then get the Category ID, go to User Profile Field Categories, click to Edit the category you want the ID of, and it will be listed at the top - id x (see image 2). Uncategorized Categories have no Category ID.
Image 1:


Image 2:
So, now that you have a list of field ids and category ids, you can now easily add them to your postbit.

First make sure your hook system is active (it is turned off by default). Go to Admincp > Settings > Products/Hook System > Enable/Disable Hook System > Yes.

Now, go to Admincp > Products & Hooks > Manage Hooks and click the link that says "[Add New Hook]". In that new hook, set the following:
Hook is Active: Yes
Hook Location: conversation_userstats
Title: Show Profile Fields in Postbit
Template Name: conversation_fields
Hook Arguments: conversation=conversation
SAVE
Now go to Admincp > Styles & Templates > Style Manager > Add New Template and on that page, set the following:
Title: conversation_fields
Template:
Code:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}
For each field you want shown, you will need to add this code under that line:
Code:
<vb:if condition="$userInfo['fieldX']"><li><label>{vb:phrase fieldX_title}:</label> <span>{vb:raw userInfo.customFields.default.fieldX_title.val}</span></li></vb:if>
Replace the X in "FieldX" (three times) with the fieldid and, if your field is in a Category other than Uncategoried, then replace "default" with "categoryY_title" where Y is the category id.

So, for instance, say I have the following I want to add:
Name Category
field5 (uncategoried)
field7 New Cat(id 1)
Then my template would look like this:
Code:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}
<vb:if condition="$userInfo['field5']"><li><label>{vb:phrase field5_title}:</label> <span>{vb:raw userInfo.customFields.default.field5_title.val}</span></li></vb:if>
<vb:if condition="$userInfo['field7']"><li><label>{vb:phrase field7_title}:</label> <span>{vb:raw userInfo.customFields.category1_title.field7_title.val}</span}</li></vb:if>
That's it!

If running 5.1.0, there is a code fix to apply http://www.vbulletin.com/forum/forum/vbulletin-5-connect/vbulletin-5-connect-questions-problems-troubleshooting/vbulletin-5-support-issues-questions/4029953-problem-with-user-profile-fields.

Quote by Zachery
In the templates, after applying the following change to

core/vb/library/content/text.php

Find

PHP Code:
 if (!$canseehiddencustomfields)
{
// Get profile fields information
$fieldsInfo vB_Cache::instance(vB_Cache::CACHE_STD)->read('vBProfileFields');

if (empty(
$fieldsInfo))
{
$fieldsInfo $this->assertor->getRows('vBForum:profilefield');
vB_Cache::instance(vB_Cache::CACHE_STD)->write('vBProfileFields'$fieldsInfo1440, array('vBProfileFieldsChg'));
}

foreach (
$fieldsInfo as $field)
{
$fields['field' $field['profilefieldid']] = $field['hidden'];
}

Change it to:

PHP Code:
// Get profile fields information
$fieldsInfo vB_Cache::instance(vB_Cache::CACHE_STD)->read('vBProfileFields');
  if (empty(
$fieldsInfo))
{
$fieldsInfo $this->assertor->getRows('vBForum:profilefield');
vB_Cache::instance(vB_Cache::CACHE_STD)->write('vBProfileFields'$fieldsInfo1440, array('vBProfileFieldsChg'));
}
  foreach (
$fieldsInfo as $field)
{
$fields['field' $field['profilefieldid']] = $field['hidden'];

Attached Thumbnails
Click image for larger version
Name:	UPF Categories.png
Views:	1827
Size:	25.5 KB
ID:	144483   Click image for larger version
Name:	UPF Manager.png
Views:	1841
Size:	62.7 KB
ID:	144484  

vblts.ru supports vBulletin®, 2022-2024