Access USER data in renderers.php in themes

Access USER data in renderers.php in themes

by Mitch Douglas -
Number of replies: 2

I've edited some of the code in the renderers.php file in the Afterburner theme in order to block certain menu items from showing to certain users. I've managed to set it so if a certain string of text is in the menu name, namely (staff), is present, not to show the menu.

However I want to allow this to be shown if the current user is a member of staff. I'm storing this info in the department variable in the user's data. Below is the code I've added;

if (substr(trim($menunode->get_text()),-7) == '(staff)' && trim($USER->department) != 'Staff'){
}
else
{...normal renderers.php code

At the moment $USER->department just returns a blank value, even when logged in with a user with the department field filled in. Any insight into how I can get access to this info?

Any help is appreciated in advance.

Average of ratings: -
In reply to Mitch Douglas

Re: Access USER data in renderers.php in themes

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you are inside a function, you need to say

global $USER;

first.