Support » Plugin: Any Mobile Theme Switcher » Any Mobile Theme Switcher Interferes with Session Values in other plugins

  • Due to the way that the session is started in this plugin it interferes with any session values set in any other plugin.

    I come to this conclusion because the only other plugin that deals with session on the site where I am having a problem is this one.

    I believe that the correct way to start a session is not at the top of the plugin but by calling a function on init.

    function startSession() {
        if (!session_id()) {
    add_action('init', 'startSession', 1);

    I think that starting the session when this plugin does, when the plugin file is loaded, is before WordPress clears global values. Since this plugin is also using the session values it needs at the same time it does not cause an issue for it. Basically, in order to not interfere, the entire thing would need to run on init (like the function above) instead of when the plugin file is loaded.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I get the following error when making an ajax request:
    session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent
    It points to: “any-mobile-theme-switcher.php on line 14” which is the code mentioned above.
    I tried hacking the plugin as Hube2 suggested and the error goes away but the session data is still not available. My ajax request works fine on the homepage but not on internal pages on my mobile version. The same code works everywhere on the desktop version regardless.
    This is driving me nuts! Does anyone have an idea how to fix this?

    I never actually got this fixed. There are more problems than just when session start is called in this plugin.

    The problem is that the session is started and session values set when the plugin is loaded. Then, the session is completely destroyed when WP does it’s normal initialization, which happens after the plugin file is loaded.

    What has to happen with this plugin is that all actions need to be deferred until init.

    here is basically what needs to be done…

    Everything in the plugin file starting on line 13 and running through line 106 needs to be put into a function. Lets call it start_theme_switcher. Then, instead of calling the session starter function like I indicated before you would create an init action to call this new function

    Plugin Name: Any Mobile Theme Switcher
    Plugin URI:
    Description: This plugin allow you to detect all mobile platform and switch the theme. Supports most of the mobile platform including iphone, ipad, ipod, windows mobile, parm os, blackberry, android, andriod tab.
    Author: Dinesh Karki
    Version: 1.0
    Author URI:
    /*  Copyright 2012  Dinesh Karki  (email :*/
    add_action('init', 'start_theme_switcher', 1);
    function start_theme_switcher() {
      if (!session_id()){
      // ...
      // all code up until about line 107
      // ...
    } // end function start_theme_switcher
    // the following is the code that follows
    // where you would end the function.
    function loadMobileStyle(){
    	global $mobile_browser;
    	$mobileTheme =  $mobile_browser;
    	$themeList = get_themes();
    	foreach ($themeList as $theme) {
    	  if ($theme['Name'] == $mobileTheme) {
    	      return $theme['Stylesheet'];

    Now, I can’t be 100% certain this will work because I have not completely read all the code. But, if I were going to do this, that is where I’d start and then debug from there.

    The better solution, and the one that we used, was to rebuild the main theme to be responsive and then we removed this plugin.

    The sad part is that this plugin appears to have been updated just 2 days ago and neither this thread or the one I posted on the developers support forum got any response.

    Thanks for your help Hube2. Unfortunately it doesn’t work. Looks like the plugin HAS to start first or WordPress just loads the desktop theme. If the problem IS that the plugin is loading first then why would my ajax requests work on the home page and work on ‘pageinit’ on all the other pages?

    That, i don’t know, sorry I couldn’t help more.

    In my case I knew that this would be more work than I wanted to invest for a single site I inherited. It was much more cost effective to use a single theme and make it responsive. Like I said, responsive design with CSS is a better option than loading different themes. There are also plenty of responsive themes available now.

    You might want to try the developers other support forum, the link is on the description page for the plugin. But I posted this problem there and got no more response to it there than I got here.

    Today’s update appears to have fixed my problem. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Any Mobile Theme Switcher Interferes with Session Values in other plugins’ is closed to new replies.