MyBB Community Forums

Full Version: Adding user & usergroup option problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Im having a problem adding both user and user group options to my plugin.


This is the function with only the user option (working perfectly)
function userpoblker_run($post)
{
	global $db, $mybb, $uid, $fid, $thread;
	
	$gid = $mybb->user['uid'];
	$xgid = explode(",",$mybb->settings['userpoblker_1']);
	$fid = $thread['fid'];
	$xfid = explode(",",$mybb->settings['userpoblker_4']);
	
	$usergrpmess = $mybb->settings['userpoblker_2'];

		if ($mybb->settings['userpoblker_3']== "1")
		{
		if (in_array($gid,$xgid, TRUE) && in_array($fid,$xfid))
		{
                     $post['message'] = $usergrpmess;
		}
	} 
}


This is the same function with the "usergroup" option added (not working)
function userpoblker_run($post)
{
	global $db, $mybb, $uid, $fid, $thread;
	
	$gid = $mybb->user['uid'];
	$xgid = explode(",",$mybb->settings['userpoblker_1']);
	$fid = $thread['fid'];
	$xfid = explode(",",$mybb->settings['userpoblker_4']);
	$user = $mybb->user['usergroup'];
	$xuser = explode(",",$mybb->settings['userpoblker_1']);
	
	$usergrpmess = $mybb->settings['userpoblker_2'];

		if ($mybb->settings['userpoblker_3']== "1")
		{
		if (in_array($gid,$xgid, TRUE) && in_array($fid,$xfid) && in_array($user,$xuser))
		{
            $post['message'] = $usergrpmess;
		}
	} 
}

Cant seem to figure this out Dodgy
You are using $mybb->user['uid']; for User Groups.. Try to add $mybb->user['usergroup'];
Im not , im using both. Look at the second function.
Try this function;
function userpoblker_run($post)
{
    global $db, $mybb, $groupscache, $uid, $fid, $thread;
    
    $gid = $mybb->user['uid'];
    $xgid = explode(",",$mybb->settings['userpoblker_1']);
    $fid = $thread['fid'];
    $xfid = explode(",",$mybb->settings['userpoblker_4']);
    $user = $mybb->user['usergroup'];
    $xuser = explode(",",$mybb->settings['userpoblker_1']);
    
    $usergrpmess = $mybb->settings['userpoblker_2'];

        if ($mybb->settings['userpoblker_3']== "1")
        {
        if (in_array($gid,$xgid) && in_array($fid,$xfid) && in_array($user,$xuser))
        {
            $post['message'] = $usergrpmess;
        }
    } 
}

Remember that all these variables are true, no need to right TRUE again.
Yes i understand that , but this is not the problem. That wouldnt be the reason why the groups wont work.

I have tried it though.
Care to elaborate the permissions for these vars ? e.g. User, Groups and Forums. Are users of uid and usergroup should see the code in those selected forums ? Also what hook you are using ?

It would nice if you paste or PM me your entire plugin code, so I could look into.
Yes the user and usergroup see the "$post['message'] = $usergrpmess;" when the admin add the IDs in ACP

My hook
$plugins->add_hook("postbit", "userpoblker_run");
Remove the $usergrpmess from $post var. I would advice you to use the settings var within the loop, so your new function looks;

function userpoblker_run($post)
{
    global $db, $mybb, $groupscache, $uid, $fid, $thread;
    
    $gid = $mybb->user['uid'];
    $xgid = explode(",",$mybb->settings['userpoblker_1']);
    $fid = $thread['fid'];
    $xfid = explode(",",$mybb->settings['userpoblker_4']);
    $user = $mybb->user['usergroup'];
    $xuser = explode(",",$mybb->settings['userpoblker_1']);
    
        if ($mybb->settings['userpoblker_3']== "1")
        {
        if (in_array($gid,$xgid) && in_array($fid,$xfid) && in_array($user,$xuser))
        {
            $post['message'] = $mybb->settings['userpoblker_2'];
        }
    } 
}

This is because adding a var outside the loop runs tooo slowly.
Yes good idea , although my problem still remains.
In my dictionary, code is perfect. You need to check where you are using this function. If you are using inside the post then use "parse_message_end" hook instead of postbit hook.
Pages: 1 2