Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles

Reply
 
Thread Tools
[HOW TO - vB4] Adding a New Tab in Member Profile - Reloaded
cellarius's Avatar
cellarius
Join Date: Aug 2005
Posts: 1,987

 

Show Printable Version Email this Page Subscription
cellarius cellarius is offline 06-28-2011, 10:00 PM

This tutorial is an update of Dylanblitz' howto for older versions. Credits to him, and thanks for giving me green light for building on his ideas.

This has been tested with [S]4.1.4[/S] 4.2,[S] but should work as far back as 4.0.8, when profile customization was reintroduced. [/S]
[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:

Attachment 130539

First step

To create a new member profile tab, create a plugin at hook member_complete
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('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.
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>
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
Reply With Quote
  #22  
Old 04-09-2012, 12:12 AM
rgf207 rgf207 is offline
 
Join Date: Mar 2008
Location: Maryland
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

PHP Code:
if (isset($vbulletin->GPC['tab']))
{
    
$selected_tab $vbulletin->GPC['tab'];
}

$blockinfo['title'] = $vbphrase['who_quoted'];
$blockid "quoted";
$taburl $memberurl fetch_seo_url('member'$prepared) . "&amp;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
HTML Code:
<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>
Reply With Quote
  #23  
Old 04-25-2012, 08:15 PM
DannyV DannyV is offline
 
Join Date: Mar 2012
Posts: 30
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What should I do to have to extra tab only be shown to certain usergroups ?

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

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
Reply With Quote
  #24  
Old 05-22-2012, 02:08 PM
Dave234 Dave234 is offline
 
Join Date: Mar 2012
Posts: 256
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #25  
Old 05-22-2012, 02:25 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #26  
Old 05-22-2012, 04:51 PM
Dave234 Dave234 is offline
 
Join Date: Mar 2012
Posts: 256
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #27  
Old 05-23-2012, 01:12 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you follow the tutorial by the letter, it will be there. I cannot know what you did wrong.
Reply With Quote
  #28  
Old 05-24-2012, 03:38 PM
Dave234 Dave234 is offline
 
Join Date: Mar 2012
Posts: 256
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I copied and pasted the code you showed in my AdminCP, where you told me to.

Was that what I was supposed to do?
Reply With Quote
  #29  
Old 05-24-2012, 05:33 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #30  
Old 05-24-2012, 11:32 PM
Dave234 Dave234 is offline
 
Join Date: Mar 2012
Posts: 256
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #31  
Old 05-25-2012, 05:45 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could always try and revert those templates.
Reply With Quote
Reply

Thread Tools

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 10:22 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.05133 seconds
  • Memory Usage 2,340KB
  • 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
  • (2)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (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
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (17)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