Have you set the user preference before calling get_user_preference()?
$selectedcolour = ...
set_user_preference('theme_learningbell_chosen_colour', $selectedcolour);
Question
I am use this code for making a function for color changes my moodle lib.php the code is
function learningbell_initialise_colourswitcher(moodle_page $page) {
user_preference_allow_ajax_update('theme_learningbell_chosen_colour', PARAM_ALPHA);
$page->requires->yui_module('moodle-theme_learningbell-colourswitcher', 'M.theme_learningbell.initColourSwitcher', array(array('div'=>'#colourswitcher')));
}
/**
* Gets the colour the user has selected, or the default if they have never changed
*
* @param string $default The default colour to use, normally red
* @return string The colour the user has selected
*/
function learningbell_get_colour($default='blue') {
return get_user_preferences('theme_learningbell_chosen_colour', $default);
}
/**
* Checks if the user is switching colours with a refresh (JS disabled)
*
* If they are this updates the users preference in the database
*
* @return bool
*/
function learningbell_check_colourswitch() {
$changecolour = optional_param('learningbellcolour', null, PARAM_ALPHA);
if (in_array($changecolour, array('blue', 'green', 'red', 'orange', 'yellow', 'pink'))) {
return set_user_preference('theme_learningbell_chosen_colour', $changecolour);
}
return false;
}
but i want to make default color should be selected color like any color ('blue', 'green', 'red', 'orange', 'yellow', 'pink') which one currently selected by admin. If i am select pink color, but the problem is that after logout it takes automatic blue color please help me.
Solution
Have you set the user preference before calling get_user_preference()?
$selectedcolour = ...
set_user_preference('theme_learningbell_chosen_colour', $selectedcolour);