If I want some content to only be visible for a custom membergroup, how/where could I write a function for that membergroup? Or is there a set function already for that? Or where is the $context array pieced together so I can add a custom membergroup to it?
Can I haz $context['user']['is_custommembergroup'] ?
So, I'm an admin at my board obviously, and stuck the follwing into index.template.php
if (in_array(1, $user_info['groups']))
{
echo '
<div>
Some other stuff here that you want to protect.
</div>';
}
else
{
echo 'Sorry you are not allowed to see this.';
}
but all I saw was "Sorry you are not allowed to see this." As, I'm an admin with ID_Group = 1 , I don't know what is going wrong?
$user_info['groups'] is an array of all the groups a user is in (group IDs not names). Can use in_array($group_id, $user_info['groups']) to see if a user is in a specific group... $group_id in that case would be the ID of the custom group you are asking about.
edit....
if (in_array(1, $user_info['groups']))
{
echo '
<div>
Some other stuff here that you want to protect.
</div>';
}
else
{
echo 'Sorry you are not allowed to see this.';
}
Will work
but the fact it didn't work in index.template.php in the default template folder would indicate...?
Sorry, but it is hard for me to troubleshoot a code that we agree should work but it doesn't :(
Are there other more laborious ways to do this?
I'm using smf 1.1.2 by the way for the database.
Anyways, I did the following...
echo array_sum($user_info['groups']);
And all I got back was nothing. I don't suspect that would be normal?
You have to add $user_info to the global thing at the top of whatever function you want to use it in.
Thank you!!! I know that is obvious for you, but that should really be added to this document page:
http://docs.simplemachines.org/index.php?topic=789.0
This is a follow up to coaxs' request to have the info about calling the "global" variables first when doing membergroup functions placed in the docs, I followed the info on the docs page and nothing worked until I was lucky enough to find this post. For the sake of others I hope a note about this can be added. Thank you Charles Hill and coaxs for finally getting the info that saved my day in this post!