View Full Version : [HOW TO - vB4] Adding a New Tab in Member Profile - Reloaded
cellarius
06-28-2011, 10:00 PM
This tutorial is an update of Dylanblitz (https://vborg.vbsupport.ru/member.php?u=114019)' howto for older versions (https://vborg.vbsupport.ru/showthread.php?t=235860). Credits to him, and thanks for giving me green light for building on his ideas.
This has been tested with 4.1.4 4.2, but should work as far back as 4.0.8, when profile customization was reintroduced.
[Explanation: At least with version 4.1.8, the template name convention for profile tabs was changed. If you want to code for an earlier version, use custom_profile_tab_test as template name.]
The result will look like this:
130539
First step
To create a new member profile tab, create a plugin at hook member_complete
if (isset($vbulletin->GPC['tab']))
{
$selected_tab = $vbulletin->GPC['tab'];
}
$blockinfo['title'] = "Test Title";
$blockid = "test";
$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&tab=test#test";
$templater = vB_Template::create('memberinfo_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$templater->register('blockinfo', $blockinfo);
$templater->register('blockid', $blockid);
$templater->register('taburl', $taburl);
$template_hook['profile_tabs_last'] .= $templater->render();
// ### Your code to fill the tab ###
// Don't forget you need to register any variables for use in templates
$test_tab_content = "Congratulations, you can see me, I'm your PHP Code!";
$templater = vB_Template::create('memberinfo_block_test');
$templater->register('selected_tab', $selected_tab);
$templater->register('test_tab_content', $test_tab_content);
$template_hook['profile_tabs'] .= $templater->render();
This code creates the tab and inserts it as the last tab in the row. You
should give the tab its own unique id. In this case, we use test. If you change it, make sure you do so everywhere in the plugin and in the template. It has to be identical everywhere
can add custom code to fill your tab, if the content is not static html. In that case you would only add code to the template.
have to register any variables you want to output in the template, if you add custom code. You will be able to call that variable by using {vb:var test_tab_content} in the template.
choose a name for the template you will be calling to show your tab's content.
Note that template names are case sensitive: test is not the same as TEST or Test. Remember that in step 2!
Second step
The second step to a custom profile tab is to create a new template. It has to be the name you used in your php code to create it, in our case: memberinfo_block_test.
<div id="view-test" class="<vb:if condition="$selected_tab == 'test'">selected_view_section<vb:else />view_section</vb:if><vb:if condition="$userinfo['userid'] != $bbuserinfo['userid']"> vm_other_prof</vb:if>">
<div class="blocksubhead subsectionhead userprof_headers userprof_headers_border">
<h4 class="subsectionhead-understate">Test</h4>
</div>
<br />This is a <b>custom tab</b> test.<br />
{vb:raw test_tab_content}
</div>
This is the template for your tab content. You
have to adapt the id in several cases. Note that they have to be absolutely identical again.
can add static text and html code into the template.
can print the output of the variable that you saved the result of your php code in and that you registered correctly.
Direct access
If you want to access your custom profile tag directly, append &tab=test#testto the profile URL.
That's it :)
Princeton
06-29-2011, 01:38 PM
thank you cellarius - great article! :up:
cellarius
06-29-2011, 01:42 PM
Thanks :D
BirdOPrey5
06-29-2011, 07:46 PM
Will come in handy!
Pandemikk
06-29-2011, 08:41 PM
Great job. I wish this article was here when I first wanted to add a new profile tab! Would have saved me hours of headache over such a small little problem.
BCP Hung
07-03-2011, 02:21 PM
It really important with me !
Great work !
(I can't like your post, why ??? :()
tkhalbiz
07-04-2011, 08:56 AM
I followed all the steps, but it does not work
can some one help me ?
cellarius
07-04-2011, 10:40 AM
No, sorry, you're just giving too much information... :rolleyes:
What vB version exactly are you using?
What exactly does not work?
What code did you use where?
Honestly, what help exactly do you expect on the simple statement "it does not work"? Only thing I possibly could offer on that grounds would be: fix the error, then it will. ;)
--------------- Added 1309779783 at 1309779783 ---------------
(I can't like your post, why ??? :()
They improved the likes system, maybe that was the problem. Feel free to try again :D
tkhalbiz
07-06-2011, 06:37 AM
Hello,
Im sorry for no precision :)
My vbulletin version : 4.1.4
i have create a plugin at hook member_complete
with this code :
if (isset($vbulletin->GPC['tab']))
{
$selected_tab = $vbulletin->GPC['tab'];
}
$blockinfo['title'] = "Test Title";
$blockid = "test";
$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&tab=test#test";
$templater = vB_Template::create('memberinfo_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$templater->register('blockinfo', $blockinfo);
$templater->register('blockid', $blockid);
$templater->register('taburl', $taburl);
$template_hook['profile_tabs_last'] .= $templater->render();
// ### Your code to fill the tab ###
// Don't forget you need to register any variables for use in templates
$test_tab_content = "Congratulations, you can see me, I'm your PHP Code!";
$templater = vB_Template::create('custom_profile_tab_test');
$templater->register('selected_tab', $selected_tab);
$templater->register('test_tab_content', $test_tab_content);
$template_hook['profile_tabs'] .= $templater->render();
i just copy past original code
then i have create template custom_profile_tab_test with this code :
<div id="view-test" class="<vb:if condition="$selected_tab == 'test'">selected_view_section<vb:else />view_section</vb:if><vb:if condition="$userinfo['userid'] != $bbuserinfo['userid']"> vm_other_prof</vb:if>">
<div class="blocksubhead subsectionhead userprof_headers userprof_headers_border">
<h4 class="subsectionhead-understate">Test</h4>
</div>
<br />This is a <b>custom tab</b> test.<br />
{vb:raw test_tab_content}
</div>
and after i go to profile page to check new tabs but nothing to see :(
cellarius
07-06-2011, 07:18 AM
Then you either have not activated the plugin you created, have deactivated plugins globally, created the template for the wrong style, or use a customized style where the needed template hook is not present.
Since that's, as far as I can see, the unchanged code from the firstpost, I can guarantee this works.
tkhalbiz
07-06-2011, 07:25 AM
Ok i will check all this point and come back :)
WorldCraft
07-26-2011, 10:45 AM
Awesome thanks!
John Tran
07-28-2011, 01:20 PM
Installed, but I have a quick question. I know I am asking this in the wrong area but I can't seem to find help anywhere. I installed this tab plugin, now I would like it to display member albums in the tab, is there anyway you can help with this?
n.stanley
08-25-2011, 01:45 PM
Sorry to sound silly, but where can I find these hooks/plugins?
Is it editing a file directly, or something found within the Administration section?
Sorry..
Edit: Found it out, god bless, google.
n.stanley
08-29-2011, 09:43 AM
Question;
After creating this tab, how can you specify the USER ID of the members profile you're on?
cellarius
09-01-2011, 06:31 AM
Try
$prepared['userid']
in the plugin,
to use it in the template you would probably have to register it first.
berritt
10-13-2011, 07:20 PM
this might be a stupid question, but is this an area that is editable by the user? Like if said user wanted to add more to their profile such as their favorite things, etc.
BirdOPrey5
10-14-2011, 03:18 AM
no.
You would have to supply fields to everyone via the Admin CP -> User Profile Field Manager. You can make them optional so only users who want to fill them out have to- but they would all show under "About Me."
Altari
03-21-2012, 04:53 PM
Hello,
Sorry for my bad english, i'm french
How to add this profile tab with php code in a file .php and not in a plugin ?
Thank you
cellarius
03-21-2012, 05:43 PM
Sorry, I don't know what you want to do. If you want to add any tabs to any php page, this is not for you.
rgf207
04-09-2012, 12:12 AM
Any ideas why this only works if "test" is used in the $taburl variable? If I change the #test to #quoted ($blockid var) nothing shows up.
if (isset($vbulletin->GPC['tab']))
{
$selected_tab = $vbulletin->GPC['tab'];
}
$blockinfo['title'] = $vbphrase['who_quoted'];
$blockid = "quoted";
$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&tab=quoted#test";
$templater = vB_Template::create('memberinfo_tab');
$templater->register('selected_tab', $selected_tab);
$templater->register('relpath', $relpath);
$templater->register('blockinfo', $blockinfo);
$templater->register('blockid', $blockid);
$templater->register('taburl', $taburl);
$template_hook['profile_tabs_last'] .= $templater->render();
// ### Your code to fill the tab ###
// Don't forget you need to register any variables for use in templates
$quoted_tab_content = "Congratulations, you can see me, I'm your PHP Code!";
$templater = vB_Template::create('memberinfo_block_WhoQuoted');
$templater->register('selected_tab', $selected_tab);
$templater->register('quoted_tab_content', $quoted_tab_content);
$template_hook['profile_tabs'] .= $templater->render();
Template
<div id="view-quoted" class="<vb:if condition="$selected_tab == 'quoted'">selected_view_section<vb:else />view_section</vb:if><vb:if condition="$userinfo['userid'] != $bbuserinfo['userid']"> vm_other_prof</vb:if>">
<div class="blocksubhead subsectionhead userprof_headers userprof_headers_border">
<h4 class="subsectionhead-understate">Test</h4>
</div>
<br />This is a <b>custom tab</b> test.<br />
{vb:raw quoted_tab_content}
</div>
DannyV
04-25-2012, 08:15 PM
What should I do to have to extra tab only be shown to certain usergroups ?
--------------- Added 1335389174 at 1335389174 ---------------
nevermind. figured it out:
if (is_member_of($vbulletin->userinfo,x,y,z)) {
}
in the plugin
where x,y,z are the group Id's
Dave234
05-22-2012, 02:08 PM
Alright, so I've got the "Gallery" tab added. Now how would I add the content? How can I add photos?
Also I notice that none of my blog entries are showing up under my "Blog" tab in my user profile. I am logged in and everything.
cellarius
05-22-2012, 02:25 PM
You have the tab working - this is all this article is about.
It is not about querying whatever it is you want to show on that tab. It sure is not about general support issues (your blog tab not working). Please ask for help in your own thread in the proper forums.
Dave234
05-22-2012, 04:51 PM
But the "Congratulations, you can see me, I'm your PHP Code!" is not appearing under the new tab I added.
Can you please help me to determine why? I had deleted some of the code in the memberinfo_block_statistics template and cleared out the code in the memberinfo_block_contactinfo template, because I did not like all of that ("Number of Posts per Day: 0.25" etc) content in my User Profile.
cellarius
05-23-2012, 01:12 PM
If you follow the tutorial by the letter, it will be there. I cannot know what you did wrong.
Dave234
05-24-2012, 03:38 PM
I copied and pasted the code you showed in my AdminCP, where you told me to.
Was that what I was supposed to do?
cellarius
05-24-2012, 05:33 PM
Article updated. Obviously the template name convention was changed somewhere along the line.
The template needs to be named memberinfo_block_test now (remember to adapt the create_template call in the plugin accordingly.
Dave234
05-24-2012, 11:32 PM
I did it exactly as you have it, but it does the same thing......I'm wondering if it is because I had deleted some of the code in the memberinfo_block_statistics template and cleared out the code in the memberinfo_block_contactinfo template, because I did not like all of that ("Number of Posts per Day: 0.25" etc) content in my User Profile? Could that affect it at all?
cellarius
05-25-2012, 05:45 AM
You could always try and revert those templates.
Dave234
05-25-2012, 09:28 PM
How do I do that? Do I press the "Revert" button and that will do it?
cellarius
05-26-2012, 05:45 AM
Yes.
Dave234
05-28-2012, 12:17 PM
Still doesn't work......
cellarius
05-29-2012, 09:03 AM
I have the code from the article working in 4.2.
Dave234
08-01-2012, 07:36 PM
Can someone please help? I want to have this custom tab added to each person's profile, and have that tab be called "Gallery". When you click on it, it shows all the photos they've uploaded.
Then in the menu at the top of the webpage, I want to have "Gallery" and have that connect to random members' photos, possibly based on their popularity.
I hope it's not too much that I'm asking...
cellarius
08-02-2012, 09:03 PM
You'll find the code to create the tab in this article. For all the rest you'll have to create your own thread in the general forums.
TheSupportForum
09-10-2012, 06:27 PM
now that i have this setup
how do i include custom fields for that tab
cellarius
09-11-2012, 05:02 AM
You'll find the code to create the tab in this article. For all the rest you'll have to create your own thread in the general forums.
^^^ This, please.
Scanu
09-16-2012, 04:55 PM
now that i have this setup
how do i include custom fields for that tab
Thanks for the article cellarius! :)
@simonhind i was having your problem and i've done this
Create a new plugin and choose "userprofile_create" as hook, use this php code
vB_Template::preRegister('name of the template for your tab',array('fieldX' => $this->userinfo['fieldX'],));
I'll write an article soon with this
Dave234
10-02-2012, 08:16 PM
Is there not a way to have this new tab connect directly to the user's pictures within their profile?
Glenn379
11-18-2013, 07:30 AM
no.
You would have to supply fields to everyone via the Admin CP -> User Profile Field Manager. You can make them optional so only users who want to fill them out have to- but they would all show under "About Me."
That is how I personally have it now. There isn't a way to then call on those profile fields to appear within the new tab?
Easy5s.net
07-12-2015, 06:58 AM
i use
$template_hook['profile_tabs_first'] .= $templater->render();
Anh if members do not have the data, for example adding tabs thank, but members no have thank then no default tab is selected, how to fix?
friendlymela
07-21-2015, 03:13 PM
wow this is very useful for me thanks to share
Skyrider
08-02-2015, 06:42 AM
It's working perfectly for me, however. Direct access isn't working for me:
If you want to access your custom profile tag directly, append &tab=test#testto the profile URL.
It just forwards me to (for example):
&tab=test#
And shows the main profile.. Any clue what it might be?
The tab itself works just great.
grey_goose
08-03-2015, 02:20 PM
Thanks for the article cellarius! :)
@simonhind i was having your problem and i've done this
Create a new plugin and choose "userprofile_create" as hook, use this php code
vB_Template::preRegister('name of the template for your tab',array('fieldX' => $this->userinfo['fieldX'],));
I'll write an article soon with this
I couldn't find this article :)
I tried your instructions, but it's not working:
vB_Template::preRegister('custom_profile_tab_Chara cters',array('field109' => $this->userinfo['field109'],));
Template name: custom_profile_tab_Characters
Within the template: {vb:raw userinfo.field109}
jagtpf
01-06-2016, 04:02 PM
Working on 4.2.3 - Great article - Thank you ....
satsat
10-02-2016, 12:36 PM
I did the first step, and it showed in profile tabs. When I add the 2nd step and activate it, it gives this error:
Parse error: syntax error, unexpected '<' in /home/bloggers/public_html/member.php(685) : eval()'d code on line 35
I didn't change id or anything.
What should be the title of both step? I set the 2nd one to "memberinfo_block_test" and 1st one to anything I want.
Both orders are 5 and hook locations are member_info
What did I do wrong?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.