MyBB Community Forums

Full Version: Where add hook in core
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
There are two ways
One that Omar G. show me a long time ago. But here we need to add to template {$GLOBALS['ucp_nav_menu']}

$plugins->add_hook('usercp_menu', 'ucp_nav_menu', -40);
function ucp_nav_menu()
{
	global $ucp_nav_menu;

	if(true)
	{
		$ucp_nav_menu = '<tr><td class="trow1 smalltext"><a href="./usercp.php?action=mecool" class="usercp_nav_item usercp_nav_mecool">Me Cool</a></td></tr>';
	}
}

end two but here we must add to teplate {newitem}

$plugins->add_hook("usercp_menu_built", "newutem_usercp_menu_built");
function newutem_usercp_menu_built()
{
	global $lang, $mybb, $templates, $usercpnav, $newutem;
	$lang->load("newutem");
	
	if($mybb->usergroup['newutem'] != '1')
	{
		$newutem = "";
	}
	else
	{
		eval("\$newutem = \"".$templates->get("newutem_usercp_menu")."\";");
	}

	$usercpnav = str_replace("{newutem}", $newutem, $usercpnav);
}


but this is not simple variable like attachments
Bump bump
I think what you need to do is hook to use this:
$plugins->add_hook("usercp_menu", "myfunction", $x);

Replace $x with 10 if you want it in the Messenger Box, 20 for the Your Profile Box, 30 for the Miscellaneous Box.
(2017-03-20, 02:44 AM)dragonexpert Wrote: [ -> ]I think what you need to do is hook to use this:
$plugins->add_hook("usercp_menu", "myfunction", $x);

Replace $x with 10 if you want it in the Messenger Box, 20 for the Your Profile Box, 30 for the Miscellaneous Box.

this was tested and doesn't work

thanks for replay
Bump



Euan pleas check this in your free time
bump

no one? even mybb devs?
I don't know if $ucp_nav_menu was updated or if it never worked.
<?php

defined('IN_MYBB') or die('This file cannot be accessed directly.');

if(!defined('IN_ADMINCP'))
{
	$plugins->add_hook('usercp_menu', 'hello2__home');
	$plugins->add_hook('usercp_menu', 'hello2__messenger', 20);
	$plugins->add_hook('usercp_menu', 'hello2__profile', 30);
	$plugins->add_hook('usercp_menu', 'hello2__misc', 40);

	$plugins->add_hook('usercp_menu', 'hello2__misc_var', -10);
	$plugins->add_hook('usercp_menu', 'hello2__misc_rep', 40);
}

function hello2_info()
{
	return array(
		'name'			=> 'Hello World 2!',
		'compatibility'	=> '18*',
		'codename'		=> 'hello2'
	);
}

function hello2__home()
{
	global $usercpmenu;

	$usercpmenu .= '<tr><td class="trow1 smalltext"><a href="./usercp.php?action=mecool" class="usercp_nav_item usercp_nav_mecool">Me Cool Home</a></td></tr>';
}

function hello2__messenger()
{
	global $usercpmenu;

	$usercpmenu .= '<tr><td class="trow1 smalltext"><a href="./usercp.php?action=mecool" class="usercp_nav_item usercp_nav_mecool">Me Cool Messenger</a></td></tr>';
}

function hello2__profile()
{
	global $usercpmenu;

	$usercpmenu .= '<tr><td class="trow1 smalltext"><a href="./usercp.php?action=mecool" class="usercp_nav_item usercp_nav_mecool">Me Cool Profile</a></td></tr>';
}

function hello2__misc()
{
	global $usercpmenu;

	$usercpmenu .= '<tr><td class="trow1 smalltext"><a href="./usercp.php?action=mecool" class="usercp_nav_item usercp_nav_mecool">Me Cool Misc</a></td></tr>';
}

function hello2__misc_var()
{
	global $hello2__misc_var;

	$hello2__misc_var = '<tr><td class="trow1 smalltext"><a href="./usercp.php?action=mecool" class="usercp_nav_item usercp_nav_mecool">Me Cool Misc Var</a></td></tr>';
	// insert "{$GLOBALS['hello2__misc_var']}" inside "usercp_nav_misc"
}

function hello2__misc_rep()
{
	global $usercpmenu;

	$usercpmenu = str_replace('<!--HELLO2_MISC_VAR-->', '<tr><td class="trow1 smalltext"><a href="./usercp.php?action=mecool" class="usercp_nav_item usercp_nav_mecool">Me Cool Misc Rep</a></td></tr>', $usercpmenu);
	// insert "<!--HELLO2_MISC_VAR-->" inside "usercp_nav_misc"
}
first three destroy templates, this must be in if in function
http://i.imgur.com/Nf8awwS.png

other two methods

why we can use normal variable (not $GLOBAL or html comments), that the question is Smile
Oh sure it doesn't work out of the box, I just provided you with working examples, you should be adapting these to your own needs.

Quote:why we can use normal variable (not $GLOBAL or html comments)

I don't think you can use "normal" variables inside the miscellaneous menu.
Pages: 1 2