Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Sessions, Logins and Themes for Mobile Users
I'm trying to set the theme based on the HTTP_USER_AGENT string.
I have a plug-in that works as long as the user is logged-in. The constructor is below. Unfortunately if the user isn't logged in I can't set the Preview Theme. Does anyone know how to set this or if there is any other way to change the theme for a specific user session. When I changed the theme with the EnabledTheme method it changed it for all users.
I have a plug-in that works as long as the user is logged-in. The constructor is below. Unfortunately if the user isn't logged in I can't set the Preview Theme. Does anyone know how to set this or if there is any other way to change the theme for a specific user session. When I changed the theme with the EnabledTheme method it changed it for all users.
public function __construct() {
/**
* Set the theme temporarily to a mobile theme if the browser matches or it is forced
*/
$Session = Gdn::Session();
$PreviewThemeName = $Session->GetPreference('PreviewThemeName', 'default');
if ( $PreviewThemeName == 'mobile' && $_GET['mobile'] == "false" ) {
$Session->SetPreference('PreviewThemeName', 'vanilla');
$Session->SetPreference('PreviewThemeFolder', 'vanilla');
}
elseif ( $this->checkmobile() || $_GET['mobile'] == "true" || $PreviewThemeName == 'mobile' ) {
$PreviewThemeName = $Session->SetPreference('PreviewThemeName', 'mobile');
$PreviewThemeFolder = $Session->SetPreference('PreviewThemeFolder', 'mobile');
}
}
0
Comments
Gdn::Session()->UserID
Something like:
if(Gdn::Session()->UserID>0) { // do logged in stuff } else { // do not logged in stuff }
If that does not fire, it is likely due to the order of things in bootstrap.php. They support a custom post bootstrap so you may be able to recall your constructor there after the session has been setup.
Cheers
But clearly I'm an idiot. Adding this to the config file solved my problem:
$Configuration['Garden']['MobileTheme'] = 'mobile';