Index: lib/moodlelib.php
===================================================================
--- lib/moodlelib.php	(revision 1709)
+++ lib/moodlelib.php	(working copy)
@@ -2133,6 +2133,10 @@
 
     global $USER, $CFG, $SESSION;
 
+    $was_logged_in = false;
+    
+    $authsequence = null; // dummy var creation for scoping purposes
+    
     if (isloggedin()) {
         add_to_log(SITEID, "user", "logout", "view.php?id=$USER->id&course=".SITEID, $USER->id, 0, $USER->id);
 
@@ -2141,6 +2145,8 @@
             $authplugin = get_auth_plugin($authname);
             $authplugin->prelogout_hook();
         }
+        
+        $was_logged_in = true;
     }
 
     if (ini_get_bool("register_globals") and check_php_version("4.3.0")) {
@@ -2168,6 +2174,16 @@
     unset($SESSION);
     unset($USER);
 
+    // if we were logged in, run the post logout hooks
+    if($was_logged_in) {
+    	foreach($authsequence as $authname) {
+            $authplugin = get_auth_plugin($authname);
+            if(method_exists($authplugin, 'postlogout_hook')) {
+				$authplugin->postlogout_hook();            	
+            }
+        }
+    }
+    
 }
 
 /**

