cyberrant Posted June 20, 2013 Posted June 20, 2013 (edited) i need help and was wondering if anyone has any ideas on this one i need to create an if statement for moodle that will look at the current user login and if they are a site administrator it will give me back a different result. i know it will need to look like this if ($user->???? == ???) { WHAT I WANT TO HAPPEN } else { WHAT I WANT TO HAPPEN } does anyone have any ideas on how to fill the blanks? Edited June 20, 2013 by cyberrant
cyberrant Posted June 20, 2013 Author Posted June 20, 2013 answer found if (is_siteadmin()) { // do something for site admins } else { // do something else }
Marci Posted June 21, 2013 Posted June 21, 2013 (edited) That function is for use within core or for temporary fudges, and could end up deprecated without warning. The recommended method in a block / plugin etc is to check capabilities: If user is an admin... global $CFG; require_once($CFG->dirroot.'/lib/accesslib.php'); if (has_capability('moodle/site:config, get_context_instance(CONTEXT_SYSTEM))){ echo 'Congrats, you're an admin!'; } And, if user isn't an admin... global $CFG, $OUTPUT; require_once($CFG->dirroot.'/lib/accesslib.php'); if (!has_capability('moodle/site:config, get_context_instance(CONTEXT_SYSTEM))){ echo 'You're not an admin - bailing out'; echo $OUTPUT->footer(); die(); } Core API Capabilities ref: Roles - MoodleDocs Access API ref: Access API - MoodleDocs Edited June 21, 2013 by Marci 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now