2014-10-27, 05:48 PM
2014-10-28, 12:12 AM
Wouldn't be better to add
[i]usercp_menu_built_start[/i]
to [i]usercp_menu()[/i]
?2014-10-28, 09:13 AM
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:45 AM
(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
2014-10-28, 03:21 PM
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.
2014-10-28, 04:03 PM
Can you give an example of current code and possible simplified version with hooks?
2014-10-28, 05:13 PM
Sure. From a commit I did on MyProfile earlier. Note that $usergroups is already defined from reading the cache.
Current Code
Code with hook:
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;
}