User theme enabled but hidden within user profile

User theme enabled but hidden within user profile

by Fred Berry -
Number of replies: 2
Hi there

I searched for this for about 2 hours online and could not find anything similar to the function I would like.

Basically I want to enable user themes for my Moodle 1.9 site but only allow administrators to actually select the theme for the user. The field should either be locked or hidden when the user edits their profile.

I have slight variations of a theme I would like to use for different groups of users and this is the only way I can see this working.

Any help, suggestions or advice is greatly appreciated!

Regards

Fred
Average of ratings: -
In reply to Fred Berry

Re: User theme enabled but hidden within user profile

by Matt Campbell -
I would do it by hacking the code just a little bit.

Look at /user/editlib.php, about line 196 - this is where the theme selection is built.

if (!empty($CFG->allowuserthemes)) {
$choices = array();
$choices[''] = get_string('default');
$choices += get_list_of_themes();
$mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
$mform->setAdvanced('theme');
}

You're going to change this slightly (changes in red):

$syscontext = get_context_instance(CONTEXT_SYSTEM);
if ((!empty($CFG->allowuserthemes)) & (has_capability('moodle/user:update', $syscontext))) {
$choices = array();
$choices[''] = get_string('default');
$choices += get_list_of_themes();
$mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
$mform->setAdvanced('theme');
}

Now, anyone that has the moodle/user:update capability at the site level will be able to change a user's theme, but normal users will not be able to change their theme.

Thanks,
Matt
In reply to Matt Campbell

Re: User theme enabled but hidden within user profile

by Ric Crouch -

I realize this post is five years old, but just wanted to say that this was VERY helpful!  Solved a huge problem for me.

 

Thanks!