MyBB Community Forums

Full Version: hooking into UserCP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys
I've almost finished a plugin I've been working on for a while and have hit a brick wall when it comes to adding stuff to the UserCP
Basically I want to put another table below the "Brief Account Summary" table.
I can do this by manually editing the usercp template, but thats the last thing I want to do. So, just in the back of my head, I'm thinking of something along these lines:: (not exact, but you get the idea)
function my_stuff($page, $my_file)
{
ob_start();
$my_file= include("my_directory/my_file.php");
$my_file= ob_get_contents();
ob_end_clean();
$page = str_replace("reputation}</table>", "reputation}</table>$my_file", $page);
return $page;
 }
I've done this before, and it works perfectly for the "pre_output_page" hook, but I'm at a complete loss as to how to get this one hooked into the UserCP.
Anybody have any ideas??
[attachment=12818]
If you're hooking into usercp_end, you can just replace on the variable $usercp, eg:
function my_stuff() {
 global $usercp;
 $usercp = str_replace('a','b',$usercp);
}
That works perfectly, thankyou very much.
The working code:
$plugins->add_hook('usercp_end', 'my_stuff');
function my_stuff($usercp) {
 global $usercp;
  ob_start($my_file);
$my_file = include("test.php");
$my_file = ob_get_contents();
ob_end_clean();
 $usercp = str_replace("<!-- end: usercp_reputation -->","<!-- end: usercp_reputation -->$my_file",$usercp);
 return $usercp;
} 
[attachment=12819]
I do have one other question, on the same subject, an alternative idea to the above.
I have placed a new item in usercp_nav_misc, but when I click the link it opens the page in a new tab (obviously). but how can I go about loading that page in the body of the UserCP?
Pretty much the same as adding new stuff to the AdminCP!!
So you basically want it to load the link in the current tab, not a new one?
(2009-02-18, 01:41 AM)Tom Loveric Wrote: [ -> ]So you basically want it to load the link in the current tab, not a new one?

Yes, but still retain the UserCP's header/footer and the nav menu.
For the link:
<a href="link" target="_self">TITLE</a>

And to make it keep the layout, you'd need to make a new php file and a new template.