MyBB Community Forums

Full Version: hook in function usercp_menu_misc()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This hook will facilitate add own items (with plugin) to user menu
Wouldn't be better to add [i]usercp_menu_built_start[/i] to [i]usercp_menu()[/i]?
You can simply hook to "usercp_menu" with priority <30 and add your variable to the corresponding template. No need for a special hook.
(2014-10-28, 09:13 AM)JonesĀ H Wrote: [ -> ]You can simply hook to "usercp_menu" with priority <30 and add your variable to the corresponding template. No need for a special hook.

I try it before but maybe I am doing something wrong

http://community.mybb.com/thread-161986.html
While on the subject of hooks, I really think there should be a hook that lets you alter the $zerogroupgreater array. Without one, a plugin author has to load the entire usergroups cache to be able to parse against it. It gets really ugly doing this.
Can you give an example of current code and possible simplified version with hooks?
Sure. From a commit I did on MyProfile earlier. Note that $usergroups is already defined from reading the cache.

Current Code
 /* Make sure they still have comments remaining */
        $cutoff = TIME_NOW - 86400;
        $countquery = $db->simple_select("myprofilecomments", "COUNT(cid) as dailycommenttotal", "time >= $cutoff");
        $dailycommenttotal = $db->fetch_field($countquery, "dailycommenttotal");
        // Because the $zerogroupgreater array can't be edited at this time, we have to do this the hard way.
        $myusergroups = $user['usergroup'];
        if($user['additionalgroups'])
        {
            $myusergroups .= "," . $useradditionalgroups;
        }
        $explodedgroups = explode(",", $myusergroups);
        $commentsallowed = -1;
        foreach($explodedgroups as $exgroup)
        {
            $groupcommentsallowed = $usergroups[$exgroup]['commentsperday'];
            if($groupcommentsallowed == 0)
            {
                $commentsallowed = 0;
                break;
            }
            else
            {
                if($groupcommentsallowed > $commentsallowed)
                {
                    $commentsallowed = $groupcommentsallowed;
                }
            }
        }

        if($commentsallowed != 0)
        {
            if($dailycommenttotal >= $commentsallowed)
            {
                return false;
            }
        }

Code with hook:

 /* Make sure they still have comments remaining */
        $cutoff = TIME_NOW - 86400;
        $countquery = $db->simple_select("myprofilecomments", "COUNT(cid) as dailycommenttotal", "time >= $cutoff");
        $dailycommenttotal = $db->fetch_field($countquery, "dailycommenttotal");
if($mybb->usergroup['commentsperday'] != 0 && $dailycommenttotal >= $mybb->usergroup['commentsperday'])
{
return false;
}