Website Membership Plugin - Restrict Access based on Access Level

3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: July 10, 2011   (RSS)

By (Deleted User) - July 7, 2011

I am using the Website Membership Plugin. I have successfully integrated it into my site to restrict certain pages. I have one page that I want to restrict based on user level. For example, is a user is an Editor or an Admin, I want them to be able to see this page. Otherwise, I do now want the page (or it at the very least it's content) to be visible. I want to either display a message on the page that says you don't have access to this page, or redirect them. I am sure this is simple to do. Suggestions?

Re: [cKopyar] Website Membership Plugin - Restrict Access based on Access Level

By Jason - July 8, 2011

Hi,

There are a couple of ways of doing this depending on how you are setting up your user levels. If you're using the section access list inside the accounts section, here are a couple of things you can check for inside the $CURRENT_USER array.

You can check the "isAdmin" field to see if they have administrative access and take action if they don't:

<?php if (!$CURRENT_USER['isAdmin']): ?>
.. code for what to do if they are not an admin.
<?php end if ?>


If you want to check to other user levels, you can look at the 'accessList' field. This is an array inside the $CURRENT_USER variable that uses the name of the section as a key and has a field called "accessLevel" which stores a number.

For example, if you're checking to see if a user has editor access to all sections, and take action if they don't, you can try this:

<?php if ($CURRENT_USER['accessList']['all']['accessLevel'] != 9): ?>
.. code for what to do if the user doesn't have editor access to "all" sections.
<?php endif ?>

For accessLevel, none = 0, author = 6, and editor = 9

Hope this helps get you started. Let me know if you have any other questions.

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/