public static function is_anonymous_user($user) {
        if (preg_match('/^anon\d*$/', $user->username)) {
            $match = preg_match('/^anonfirstname\d*$/', $user->firstname);
            $match = $match && preg_match('/^anonlastname\d*$/', $user->lastname);
            // Check .com for backwards compatibility.
            $emailmatch = preg_match('/^anon\d*@doesntexist\.com$/', $user->email) ||
                preg_match('/^anon\d*@doesntexist\.invalid$/', $user->email);
            if ($match && $emailmatch) {
                return true;
            }
        }
        return false;
    }