How to check permissions

If you are writing custom code for SMF, such as a mod or a website integration with SSI.php, you can easily check for standard or custom permissions. The membergroup and board permissions are available through a few simple functions, and it works for guests too.

There are two ways to check for permissions. You can either check only whether someone has a permission, or you can run this check and then have an error displayed if the user does not have the permission.

Examples:

 

Here is a practical example: suppose you are writing a custom page with SSI integration that allows a user to manage your forum news. You can use:  If a user has such permission, the function will be called. If not, the code processing will continue normally.

Checking Board Permissions
When inside a board there is no difference between checking board or membergroup permissions. Board permissions are, however, only given to users when they are inside a board, so testing for board permissions outside of a board or topic will generally return false.

Local permissions also complicate the system. If users have a certain board permission in one board, but not in another because of local permissions, they will only have that permission in one board. SMF will only tell you the permissions in the current board and not reveal the permissions of other boards.

If, however, you want to check board permissions when not inside a board or topic, or you want to check the permissions of a different board, this is possible as the following example shows:

 Through a different function you can check which boards a user has a permission on:

