Move redirect-handling from functions.php to the plugin, where it belongs.