MyBB Community Forums

Full Version: Adding items to the usercp_nav template?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to add a new navigation item to the usercp_nav template area and have so far got this code:

$plugins->add_hook("usercp_menu", "userpages_usercpmenu");

function userpages_usercpmenu() 
{
	global $mybb, $cahce, $lang, $changeuserpage;
	
	require_once MYBB_ROOT."/inc/class_datacache.php";
	$cache = new datacache;
	$cache->cache();
	$usergroups_cache = $cache->read("usergroups");
	
	$lang->load("userpages");
	
	echo $lang->changeuserpage;
	
	if ($usergroups_cache[$mybb->user['usergroup']]['canuserpage'] && $usergroups_cache[$mybb->user['usergroup']]['canuserpageedit']) {
		$changeuserpage = '<tr>
	<td class="trow1">
		<div><a href="usercp.php?action=edituserpage" class="usercp_nav_item usercp_nav_profile">'.$lang->changeuserpage.'</a></div>
	</td>
</tr>';
	}
}

In the actual template, the code is virtually unchanged, except I've added {$changeuserpage} (obviously).

The problem is, I can echo out $changeuserpage and it is echoed at the top of the page fine. However, it is not displayed in the page via the template when you view it. I have no idea why this should be as I've checked and the usercp_nav template is definitely built after the hook I'm using.

If anybody's got any idea, I'd love to have it Toungue
Actually, nevermind. I found a fix. The code to do it (if anybody wants it) is as follows:

$plugins->add_hook("usercp_menu", "userpages_usercpmenu");

function userpages_usercpmenu() 
{
	global $db, $mybb, $templates, $theme, $usercpmenu, $lang, $collapsed, $collapsedimg, $lang, $cache;
	
	require_once MYBB_ROOT."/inc/class_datacache.php";
	$cache = new datacache;
	$cache->cache();
	$usergroups_cache = $cache->read("usergroups");
	
	$lang->load("userpages");
	
	if ($usergroups_cache[$mybb->user['usergroup']]['canuserpage'] && $usergroups_cache[$mybb->user['usergroup']]['canuserpageedit']) {
		eval("\$usercpmenu .= \"".$templates->get("usercp_nav_userpages")."\";");
	}
}
Nice work.
nice keep going impressive!
Thanks a bunch for sharing, been frustrating me forever trying to figure this one out -.-
Hi euantor,

Thank you for this thread. I am also trying to include a usergroup dependend link into the usercp. However, I would like to see this link in the usercp_nav_misc area. With your above code the link is placed directly under the User CP Home link. Any idea?
It's actually possible to do that, it's just slightly more difficult. I'll post up some code for you in a few minutes Smile
Hi euantor,

Thank you for your reply. However, I have already got it working by using the priority paramater like this
$plugins->add_hook("usercp_menu", "my_plugin_run", 100);
in the plugin file.
Yeah, that's how I was going to suggest doing it Wink I did it for the recent version update of MyXBL.