PDA

View Full Version : [vB4] Add new Tab at User's Profile and make it preselected


TheAdminMarket
19 Oct 2014, 16:15
Hello,

Important: This Article will shows you the way to create your own tab in user's Profile page, set it as first or last, and if you want, make it preselected. If you already have the tabs (custom or vB default) and the only that you want is to change the default Activity tab to another tab, then Ozzy47 has released a nice and easy addon. You can find it here (http://www.vbulletin.org/forum/showthread.php?t=302655).

If you want to build your own tab the steps that you must follow are listing below. for easy convertion we assume that your tab name is: mytabname

1.- Create a New Plugin:

a] Name: My Profile Tab
b] Hook Location: member_complete
c] Plugin PHP code:

global $vbulletin;
require_once(DIR . '/includes/class_postbit.php');
require_once(DIR . '/includes/functions_user.php');
if (isset($vbulletin->GPC['tab']))
{
$selected_tab = $vbulletin->GPC['tab'];
}
$blockinfo['title'] = 'My Tab';
$blockid = "mytabname";
$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&tab=mytabname#mytabname";
// Drawing the Tab
$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_first'] .= $templater->render();
Comments:

1.- You can use a Global phrase for $blockinfo['title']. For example:

$blockinfo['title'] = $vbphrase["my_global_phrase"];
2.- You can choose the position of your tab. In my code above the tab will appears first of all. If you want it at the end, use as template hook: profile_tabs_last

The code above draws only the tab. Nothing more. To add content we must extend the php code and also use a template for it. Let's continue with the PHP code. Should be on the same code block above. No different plugin !!


// Here you can add your PHP code for querying the database, assigning variables etc

// This is the setup for the tab template
$templater = vB_Template::create('my_profile_tab_template');
$templater->register('selected_tab', $selected_tab);
$templater->register('userinfo', $userinfo);
$templater->register('userid', $userinfo);

// Here you must assign all variables to be used in the template

$template_hook['profile_tabs'] .= $templater->render();
Now click Save and you finished with the first step. Let's continue:

2.- [U]Create your template.

There are many articles teaching how to create a template. Here I'll show you only the data that this template must has. Don't forget to use the same template name. In our example is: my_profile_tab_template


<div id="view-mytabname" class="<vb:if condition="$selected_tab == 'mytabname'">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">My Header Title goes here</h4>
</div>
// Real tab content goes here
</div>
3.- [U]Cache the template

You must create a new Plugin for caching the template. Use the example data below:

a] Name: My Tab Template Cache
b] Hook Location: cache_templates
c] PHP code:

if (THIS_SCRIPT == 'member')
{
$cache = array_merge($cache, array(
'my_profile_tab_template',
));
}
4.- Make Tab preselected (Optional)

If you want to make your tab preselected which means that from any link that someone will clicks to see user's profile, your tab should be the first in view (default is the Activity tab), add one more plugin:

a] Name: My Tab Preselected
b] Hook Location: member_build_blocks_start
c] PHP code:

$vbulletin->GPC['tab'] = 'mytabname';