Skip to Content Skip to Menu

🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

[SOLVED] Retrieve access level of user to show hide elements

  • AlanJones
  • AlanJones
  • OFFLINE
  • Posts: 510
  • Thanks: 42
  • Karma: 2
9 years 11 months ago - 9 years 11 months ago #257336 by AlanJones
I have made a photo gallery plugin, which is nearly complete. I just need to make a view based on access level so administrators can remove galleries and images from the user profile frontend. I have currently tried using $my->usertype; and $user->usertype; both echo empty.

Own Your Own Community!
Last edit: 9 years 11 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48622
  • Thanks: 8302
  • Karma: 1446
9 years 11 months ago #257374 by krileon
If you're using CB 2.x you can use the below CB API to test if a user has access to a view access level as follows.

Current User:
Code:
$canAccess = Application::MyUser()->canViewAccessLevel( VIEW_ACCESS_LEVEL_ID_HERE );

Specific User:
Code:
$canAccess = Application::User( USER_ID_HERE )->canViewAccessLevel( VIEW_ACCESS_LEVEL_ID_HERE );

You can retrieve their view access levels with the below API as an array.

Current User:
Code:
$myViewAccessLevels = Application::MyUser()->getAuthorisedViewLevels();

Specific User:
Code:
$myViewAccessLevels = Application::User( USER_ID_HERE )->getAuthorisedViewLevels();

Both need to have the Application use statement at the top of your PHP file, which is as follows.

Code:
use CBLib\Application\Application;


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • AlanJones
  • AlanJones
  • OFFLINE
  • Posts: 510
  • Thanks: 42
  • Karma: 2
9 years 11 months ago #257420 by AlanJones
That worked like a charm, thank you. Also gathering arrays will be helpful in the future, so that is good to know.

Own Your Own Community!

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum