Announcement

Collapse
No announcement yet.

How to add usergroup permissions to custom pages with the PHP Module

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to add usergroup permissions to custom pages with the PHP Module

    Since vBulletin 5 has the site builder which easily enables you to add new pages to your site, you may want to add your own custom permissions to those pages. First you will need to create a new page with the site builder. To add permissions to this page directly you will need to select the PHP module.

    Place the PHP module(s) on your page and position them where you like. In this example I'll just check whether the user is logged in or not. If they are then I will echo Hello {username} and if not I'll echo a simple no permission message.

    In PHP Module:

    PHP Code:
    if (vB5_User::get('usergroupid') == 1)
    {
        echo 
    'You do not have permission to access this page.';
    }
    else
    {
        echo 
    'Hello, ' vB5_User::get('username');



    If you wanted to add multiple usergroups you could add extra conditions to the statement, for example:

    PHP Code:
    if (vB5_User::get('usergroupid') == OR vB5_User::get('usergroupid') == 2)
    {
       
    // Do whatever...
    }
    else
    {
       
    // Do whatever else...


    Here are some screenshots...


    Logged In: Click image for larger version

Name:	Screen Shot 2014-07-29 at 22.26.24.png
Views:	23
Size:	10.9 KB
ID:	4108818
    Logged Out: Click image for larger version

Name:	Screen Shot 2014-07-29 at 22.37.17.png
Views:	24
Size:	15.2 KB
ID:	4108831


    I hope this is helpful to someone. It may be small, but very useful.
    Attached Files
    Last edited by Kent55; Fri 19th Sep '14, 6:55am.

    ScreenShottr - Open Source Screen Capture Tool (Just pin to your taskbar)

Related Topics

Collapse

Working...
X