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
  #42  
Old 11-18-2013, 07:30 AM
Glenn379's Avatar
Glenn379 Glenn379 is offline
 
Join Date: Aug 2002
Location: San Francisco, California
Posts: 111
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by BirdOPrey5 View Post
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?
Reply With Quote
  #43  
Old 07-12-2015, 06:58 AM
Easy5s.net Easy5s.net is offline
 
Join Date: Jun 2011
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #44  
Old 07-21-2015, 03:13 PM
friendlymela's Avatar
friendlymela friendlymela is offline
 
Join Date: Dec 2012
Location: Karachi, Pakistan
Posts: 272
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

wow this is very useful for me thanks to share
Reply With Quote
  #45  
Old 08-02-2015, 06:42 AM
Skyrider Skyrider is offline
 
Join Date: Feb 2006
Location: Netherlands
Posts: 1,392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's working perfectly for me, however. Direct access isn't working for me:

Quote:
If you want to access your custom profile tag directly, append &tab=test#testto the profile URL.
It just forwards me to (for example):
Quote:
&tab=test#
And shows the main profile.. Any clue what it might be?

The tab itself works just great.
Reply With Quote
  #46  
Old 08-03-2015, 02:20 PM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Scanu View Post
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
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:
PHP Code:
vB_Template::preRegister('custom_profile_tab_Characters',array('field109' => $this->userinfo['field109'],)); 
Template name: custom_profile_tab_Characters
Within the template: {vb:raw userinfo.field109}
Reply With Quote
  #47  
Old 01-06-2016, 04:02 PM
jagtpf jagtpf is offline
 
Join Date: Mar 2015
Location: Scotland
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Working on 4.2.3 - Great article - Thank you ....
Reply With Quote
  #48  
Old 10-02-2016, 12:36 PM
satsat satsat is offline
 
Join Date: Aug 2005
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did the first step, and it showed in profile tabs. When I add the 2nd step and activate it, it gives this error:
Quote:
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?
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:15 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.07495 seconds
  • Memory Usage 2,306KB
  • Queries Executed 23 (?)
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
  • (2)bbcode_php
  • (5)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
  • (2)pagenav_pagelink
  • (8)post_thanks_box
  • (17)post_thanks_box_bit
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)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