Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Using your User Profile Fields in your postbit templates (w/ all plugin method)
Lynne's Avatar
Lynne
Join Date: Sep 2004
Posts: 41,180

 

California/Idaho
Show Printable Version Email this Page Subscription
Lynne Lynne is offline 09-12-2010, 10:00 PM

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.

Adding the Profile Field to your postbit (or postbit_legacy) template

For Single-Line Text Box, Multiple-Line Text Box, Single-Selection Radio Buttons, and Single-Selection Menu

Method 1
- Modifying the Template
Open the postbit or postbit_legacy template and find the area you want to add it to. For instance, to add it right after the user post count, find this:
Code:
<dt>{vb:rawphrase 'posts'}</dt> <dd>{vb:raw post.posts}</dd>
And then, add this underneath:
Code:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>
Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.
Method 2 - Using a template_hook
I have always found it easier to just use the existing $template_hooks in the template and write a plugin to add these. In this case, there is a $template_hook right where we want it, after the user post count:
Code:
{vb:raw template_hook.postbit_userinfo_right_after_posts}
So, we would create a plugin with these specifications:
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if ($post['fieldx'])
{
    $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}
Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.
For Multiple-Selection Menu and Multiple-Selection Checkbox

It is a bit more complicated for these two types of selections since the options selected are stored as a binary number. If you just display the field using the method above, you will get a number, not a list of options selected. So, in order to use these types of fields, you will have to use the method below. Here is a thead that will explain the binary scheme - http://www.vbulletin.com/forum/showt...To-The-Postbit

Method 1
- Modifying the Template
Open the template and find the area you want to add it to. For instance, to add it right after the user post count, find this:
Code:
<dt>{vb:rawphrase 'posts'}</dt> <dd>{vb:raw  post.posts}</dd>
And then add this underneath (this is assuming the field has 5 options):
Code:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>
<vb:if condition="$post['fieldx'] & 4">Your 3rd option</vb:if>
<vb:if condition="$post['fieldx'] & 8">Your 4th option</vb:if>
<vb:if condition="$post['fieldx'] & 16">Your 5th option</vb:if>
</dd>
</vb:if>
Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.
Method 2 - Using a template_hook
Find the template_hook you want to use. In this case, there is a $template_hook right where we want it, after the user post count:
Code:
{vb:raw template_hook.postbit_userinfo_right_after_posts}
So, we would create a plugin with these specifications:
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if ($post['fieldx'])
{
    $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>';
    
    if ($post['fieldx'] & 1)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 1rst option';
    if ($post['fieldx'] & 2)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 2nd option';
    if ($post['fieldx'] & 4)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 3rd option';
    if ($post['fieldx'] & 8)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 4th option';
    if ($post['fieldx'] & 16)  $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 5th option';
    
    $template_hook['postbit_userinfo_right_after_posts'] .= '</dd>';
}
Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.
More Advanced

If you like everything to be 'automatic' - meaning you don't have to supply any text at all, just use everything already stored in the database - then you can use a few of plugins to do the work for you.

Plugin 1
- This plugin is used to get the phrasegroup "cprofilefield" added for use in the page so that you may use $vbphrase[fieldx_title] to get the Profile Field Title you entered in the User Profile Field Manager.
? hook location - init_startup
? Title - Add User Profile Fields to Postbit Templates - 1
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if (THIS_SCRIPT == 'showthread') $GLOBALS['phrasegroups'][] = 'cprofilefield';
Plugin 2 - This plugin is used to get the fields you defined for the profile in the User Profile Field Manager.
? hook location - showthread_postbit_create
? Title - Add User Profile Fields to Postbit Templates - 2
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
if (THIS_SCRIPT == 'showthread') {
    $profilefieldx =  $vbulletin->db->query_first("SELECT profilefieldid, data, type  FROM " . TABLE_PREFIX . "profilefield WHERE profilefieldid = x");
    $post['profilefieldx'] = $profilefieldx;
}
Plugin 3 - This plugin simply spits the data out into the postbit using the template_hook and using the phrase for the Title and the Options are all spit out with commas between them (if needed) into the postbit.
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates - 3
? Plugin is Active - Yes
? Plugin PHP Code -
Code:
// for single-line fields - using fieldy
if ($post['fieldy']) {
     $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldy_title]. '</dt> <dd>' .$post[fieldy]. '</dd>';
 }

// for multiple-selection fields - using filedx
if ($post['fieldx'])
{
    $fieldarrayx = $post['profilefieldx'];
    fetch_profilefield_display($fieldarrayx, $post['fieldx']);
    $template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldx_title]. '</dt> <dd>' .$fieldarrayx['value']. '</dd>'; 
}
Change "fieldx" to your actual field name and the orange, purple, and brown fields should 'match-up' and have the same names.
Reply With Quote
  #112  
Old 08-30-2015, 12:32 AM
akz645 akz645 is offline
 
Join Date: Jul 2015
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
...
Quote:
Originally Posted by MarkFL View Post
...
Multiple-Selection Menu
&
Multiple-Selection Checkbox

1) How do I get some/all of those fields highlighted/checkboxes ticked as the default during registration?

2) How do I force all my existing members into updating their user profile settings?
I have some forced options now (like gender). Members who are registering now are forced to pick male or female.
Whereas members who have already signed up, they aren't forced as nothing appears in their postbit (gender) unless they go to their userCP profile and press save.


P.S=
Thank you Lynne for this brilliant article :up:
Reply With Quote
  #113  
Old 08-30-2015, 03:23 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1. For Multiple-Selection Menu, you may set the first one as default but that is the only option. There is no way to pre-select several checkboxes. I think you would need to write a plugin to do that.

2. I think you can set Field Required to Yes, Always and that should do what you want.

Quote:
Yes, always - User will be required to complete this field at registration. Enabling this setting will force all users to complete it before they can continue using your forum. This applies only if the field is shown on the "Edit Your Details" page.
Reply With Quote
  #114  
Old 08-30-2015, 08:14 PM
akz645 akz645 is offline
 
Join Date: Jul 2015
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
1. For Multiple-Selection Menu, you may set the first one as default but that is the only option.
http://i.imgur.com/oBVhrlM.png + http://i.imgur.com/6h0gmLS.png
How do I set the first option as the default (highlighted)?
As the current settings I'm using, doesn't do this...
Quote:
Originally Posted by Lynne View Post
2. I think you can set Field Required to Yes, Always and that should do what you want.
"Yes, always - User will be required to complete this field at registration. Enabling this setting will force all users to complete it before they can continue using your forum. This applies only if the field is shown on the "Edit Your Details" page."
Cheers, that worked.
Yes, at registration and profile updating - Doesn't work.
Yes, always - Worked
Reply With Quote
  #115  
Old 08-31-2015, 02:29 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1) Whoops, sorry, I was looking at the wrong type of profile field (single-selection menu, not multi-selection menu).
Reply With Quote
  #116  
Old 08-31-2015, 09:48 PM
akz645 akz645 is offline
 
Join Date: Jul 2015
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
1) Whoops, sorry, I was looking at the wrong type of profile field (single-selection menu, not multi-selection menu).
Ah alright. Anyway, thanks for the help

https://vborg.vbsupport.ru/showthread.php?t=320081
I made a request for somebody to make a plugin allowing the admin to set defaults for Multiple-Selection Menu/Checkbox when creating a User Profile Field.
Reply With Quote
  #117  
Old 09-17-2015, 12:52 AM
akz645 akz645 is offline
 
Join Date: Jul 2015
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
...
Quote:
Originally Posted by MarkFL View Post
...
1) Do you know any way to set it so only certain usergroups will have X User Profile Field option appear in their userCP?

2) How do I execute a SQL Query to force All Users/ Certain Usergroups/ Certain Users to have their X user profile field options changed into what I want?
They can change into what they want from the userCP later.
Reply With Quote
  #118  
Old 09-17-2015, 03:17 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1) No, I do not.

2) Very hard to say without specifics. But, you can probably use phpMyAdmin to do it.
Reply With Quote
  #119  
Old 09-17-2015, 03:22 PM
akz645 akz645 is offline
 
Join Date: Jul 2015
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
2) Very hard to say without specifics. But, you can probably use phpMyAdmin to do it.
I was hoping it would be something straight forward like this:

Invisible
On: UPDATE user SET options=options + 512 WHERE NOT(options & 512);
Off: UPDATE user SET options=options - 512 WHERE options & 512;

Run from Execute SQL Query

Where you'd just need to colour code what I need to change depending on my options & field number.
Reply With Quote
  #120  
Old 09-17-2015, 07:42 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would be something like that only on the userfield table (where the settings for the user profile fields are kept). But, if it is for a certain usergroup, your WHERE statement would have to include a SELECT of only certain users whose user.usergroupid was xx since the usergroupid is not included in the userfield table. I'm not good at writing those sort of queries.
Reply With Quote
  #121  
Old 09-27-2015, 08:03 PM
akz645 akz645 is offline
 
Join Date: Jul 2015
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by akz645 View Post
How do I execute a SQL Query to force All Users/ Certain Usergroups/ Certain Users to have their X user profile field options changed into what I want?
They can change into what they want from the userCP later.
Glenn Vergara posted how to do it, from vbulletin.com

1)
Code:
UPDATE userfield SET field5='Hide' where userid in (SELECT userid FROM user WHERE usergroupid IN (X, X, X))
This code allows you to change a usergroups' custom user profile field (any option they have), to whatever specific option you want them all to have changed to.
Key:
Red = User Profile Field ID.
Green = User Profile Field Option you want to change to.
Blue = Usergroup ID.

2)
Code:
UPDATE userfield SET field5='Hide' where field5='Male' AND userid in (SELECT userid FROM user WHERE usergroupid IN (X, X, X))
This code allows you to change a usergroups' custom user profile field (any single option), to whatever other specific option you want them all to have it changed to.
Key:
Red = User Profile Field ID.
Green = User Profile Field Option you want to change to.
Orange = Option you want changed.
Blue = Usergroup ID.

3)
Code:
UPDATE userfield SET field5='Hide' where (field5='Male' OR field5='Female') AND userid in (SELECT userid FROM user WHERE usergroupid IN (X, X, X))
This code allows you to change a usergroups' custom user profile field (multiple options), to whatever specific option you want them all to have it changed to. If they have selected an option you don't include (example: Other), then users who have selected that option will be left unaffected.
Key:
Red = User Profile Field ID.
Green = User Profile Field Option you want to change to.
Orange = Option you want changed.
Blue = Usergroup ID.

Note: Change usergroupid to userid to change for several users, instead of entire usergroups.
Note 2: You don't have to select more than 1 usergroup. Just selecting 1 usergroup still works.

P.S= If you want to know how to change 'Display Reputation', 'Invisible' etc, check out my guide here:
https://vborg.vbsupport.ru/showthrea...58#post2555258

--------------- Added [DATE]1443391500[/DATE] at [TIME]1443391500[/TIME] ---------------

Quote:
Originally Posted by akz645 View Post
Do you know any way to set it so only certain usergroups will have X User Profile Field option appear in their userCP?
That's the only question still left unanswered.

If anybody can help out, that would be great
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:52 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05447 seconds
  • Memory Usage 2,362KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (14)bbcode_code
  • (11)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (7)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete