0

I wrote this script to handle theme switching about four years ago. Since upgrading to WordPress 4.8, it is no longer working and is returning this error:

Fatal error: Call to undefined function wp_redirect() in /mnt/stor1-wc1-dfw1/388438/795069/www.flagstaffarizona.org/web/content/wp-content/plugins/custom-theme-switcher/custom-theme-switcher.php on line 50

Anyone have any ideas of what might be causing this? I've tried disabling all plugins except for this one, and it is still occuring.

<?php
/*
Plugin Name: Custom Theme Switcher
Description: Handles Mobile Theme Switching
Version: 1.0.1
*/

add_filter( 'template', 'custom_theme_redirect' );
add_filter( 'option_template', 'custom_theme_redirect' );
add_filter( 'option_stylesheet', 'custom_theme_redirect' );

function custom_get_subdomain() {
$subdomain = "";
if (!empty($_SERVER['HTTP_HOST'])) {
    $host_tokens = explode(".", $_SERVER['HTTP_HOST']);
    if (!empty($host_tokens)) {
        return strval($host_tokens[0]);
    }   
}
return $subdomain;
}


function custom_theme_redirect($theme) {
if (!is_admin()) {
    if (isset($_GET['mobile'])) {
        setcookie("mobile", true, time()+1, '/', CUSTOM_ROOT_DOMAIN);
        setcookie("nomobile", false, time()-1, '/', CUSTOM_ROOT_DOMAIN);
        $_COOKIE['mobile'] = true;
        $_COOKIE['nomobile'] = false;
    }
    if (DOMAIN_CURRENT_SITE == CUSTOM_MOBILE_DOMAIN || isset($_COOKIE['mobile'])) {
        if (isset($_GET['nomobile'])) {
            setcookie("mobile", false, time()-1, '/', CUSTOM_ROOT_DOMAIN);
            setcookie("nomobile", true, time()+1, '/', CUSTOM_ROOT_DOMAIN);
            wp_redirect('http://'.CUSTOM_MASTER_DOMAIN.$_SERVER['REQUEST_URI']);
            exit;
        }
        $theme = 'custom-mobile';
    } else if (DOMAIN_CURRENT_SITE == CUSTOM_MASTER_DOMAIN) {
        include_once("Mobile_Detect.php");
        $detect = new Mobile_Detect;
        if (CUSTOM_AUTO_MOBILE_REDIRECT && $detect->isMobile() && !$detect->isTablet()) {

            if (!isset($_COOKIE['nomobile']) || !$_COOKIE['nomobile']) {
                wp_redirect('http://'.CUSTOM_MOBILE_DOMAIN.$_SERVER['REQUEST_URI']);
                exit;
            }
        }
    }

}
return $theme;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.