Refactor connection check to functions.php