Search This Blog

Thursday, January 17, 2013

Only show "preferred theme" to admins

Something I've been wanting to do, is hide the themeselector on the profile page -- only for normal users. This allows me to choose a default theme for a new user and they can never change it.

1) Go to:  /moodleroot/user/editlib.php
2)  Close to the end of the file, you will see this code:


if (!empty($CFG->allowuserthemes)) 
    {
        $choices = array();
        $choices[''] = get_string('default');
        $themes = get_list_of_themes();
        foreach ($themes as $key=>$theme) {
            if (empty($theme->hidefromselector)) {
                $choices[$key] = $theme->name;
            }
        }
        $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
    }

3)  All we are going to do is add an extra statement within the "if", to check also if the user is an admin:


if (!empty($CFG->allowuserthemes) && is_siteadmin($user)) 

4)  And voila! Only admins can see that field on the profile page now.