• Resolved zwalker

    (@zwalker)


    Hello,

    Just recently, I tried to use the passkey link to switch themes while not logged in. The cookies are being set but it doesn’t go to my other theme. I’m not sure why as it has always worked before and still works on my staging serve which is more or less exactly the same app wise.

    Another thing that happens is I cannot log in after using the link. I have to clear the cookies it sets first.

    Any help or direction is most appreciated.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 16 through 19 (of 19 total)
  • Thread Starter zwalker

    (@zwalker)

    You’ll want to test this on your side but I added a check for this condition in the function and works across the board for my use case.

    function theme_switcha_active_theme() {
    	global $theme_switcha_options;
    	
    	$get_theme = wp_get_theme();
    	$options = $theme_switcha_options;
    	
    	$active_theme = $get_theme->get('Name');
    	
    	$pass_overload = ($options['allowed_users'] == "passkey" && !isset($_COOKIE['theme_switcha_passkey_'. COOKIEHASH]) && !is_admin())? FALSE: TRUE;
    	
    	if (isset($_COOKIE['theme_switcha_theme_'. COOKIEHASH]) && $pass_overload) {
    		
    		$active_theme = $_COOKIE['theme_switcha_theme_'. COOKIEHASH];
    		
    	}
    	
    	return $active_theme;
    	
    }
    Plugin Author Jeff Starr

    (@specialk)

    Just to follow up. I added a filter hook thru which a boolean can be passed to the cookie hash check in theme_switcha_active_theme(). So you can add a condition via functions.php or simple custom plugin. For example, adapting the code you provided in your previous comment, something like this:

    function theme_switcha_active_theme_custom($value) {
    
    	global $theme_switcha_options;
    	$options = $theme_switcha_options;
    
    	return ($options['allowed_users'] == "passkey" && !isset($_COOKIE['theme_switcha_passkey_'. COOKIEHASH]) && !is_admin()) ? FALSE: TRUE;
    
    }
    add_filter('theme_switcha_active_theme_custom', 'theme_switcha_active_theme_custom');

    It’s just a way to “hook” into the function and modify the conditional cookie check as needed. I hope it helps, @zwalker.

    Thread Starter zwalker

    (@zwalker)

    Thank you for adding the filter @specialk. This is perfect.

    Plugin Author Jeff Starr

    (@specialk)

    You are welcome, @zwalker. Glad to have helped. Please rate Theme Switcha if you have not already. It really helps and is appreciated.

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘Theme Switcher sets cookies then stays on current theme’ is closed to new replies.