Switch theme via URL - doesn't switch until next page load for logged in users only.
frankcarey - June 23, 2008 - 18:28
| Project: | Switchtheme |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
This worked fine with anon users.
After much frustration, it seems something happens when user_save() is called so that changing $user->theme doesn't immediately change the displayed theme. I moved $user->theme = $form_values['theme']; out of the if statement and put it BEFORE user_save() and it worked.
I'm still a little confused as to why, but this change fixed our problem... I'll let another investigate further.
I changed the following code
<?php
function switchtheme_switch_form_submit($form_id, $form_values) {
global $user;
if ($user->uid > 0) {
// Save the setting in the db for logged in users.
// We do not validate the input here, because that is done in init_theme()
// already.
if (user_save($user, array('theme' => $form_values['theme']))) {
$user->theme = $form_values['theme'];
}
$_SESSION['custom_theme'] = $form_values['theme'];
}
elseif (user_access('switch theme')) {
// Save the setting in the session for anonymous users.
$_SESSION['custom_theme'] = $form_values['theme'];
}
}
?>TO:
<?php
function switchtheme_switch_form_submit($form_id, $form_values) {
global $user;
if ($user->uid > 0) {
// Save the setting in the db for logged in users.
// We do not validate the input here, because that is done in init_theme()
// already.
$user->theme = $form_values['theme'];
user_save($user, array('theme' => $form_values['theme']));
$_SESSION['custom_theme'] = $form_values['theme'];
}
elseif (user_access('switch theme')) {
// Save the setting in the session for anonymous users.
$_SESSION['custom_theme'] = $form_values['theme'];
}
}
?>
#1
Could you please compile a list of other contrib modules you have enabled?
#2
we have a lot :) is there an easy way to do that? module perhaps?
-Thanks
#3
@TextPlease: try Enabled modules.
#4
meh... installing a module for this purpose is quite a big overhead - just execute this query:
SELECT name FROM system WHERE status = 1 AND type = 'module';#5
Same problem, updated code works for me.
#6
Here's a patch with the code to make life easier.
#7
#8
#9
Well. Basically, attached patch should be the cleanest fix. However, untested - and please do not test this one on production sites.
#10
I've checked the Drupal 6 patch and it's the same as the Drupal 5 patch. We've got the Drupal 5 patch working on a production website and I can confirm it works.
#11
What means you "checked the Drupal 6 patch"? Actually it's not the same. That's why I was asking for testing (again, due to changes in the patch on test sites only, please).
#12
Tested this myself; fixed some more glitches, and committed attached patch(es) to all branches.
#13
Automatically closed -- issue fixed for two weeks with no activity.