Index: wp-login.php
===================================================================
--- wp-login.php	(revision 13356)
+++ wp-login.php	(working copy)
@@ -372,14 +372,25 @@
 case 'retrievepassword' :
 	if ( $http_post ) {
 		$errors = retrieve_password();
-		if ( !is_wp_error($errors) ) {
-			wp_redirect('wp-login.php?checkemail=confirm');
-			exit();
-		}
+    	if ( !is_wp_error($errors) ) {
+    		if ( isset( $_REQUEST['redirect_to'] ) ) {
+    			wp_safe_redirect($_REQUEST['redirect_to']);
+    		} else {
+    			wp_redirect('wp-login.php?checkemail=confirm');
+    		}
+    		exit();
+    	}
 	}
 
 	if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
 
+	if ( isset( $_REQUEST['redirect_to'] ) ) {
+		$redirect_to = $_REQUEST['redirect_to'];
+	} else {
+		$redirect_to = '';
+	}
+	$redirect_to = apply_filters('lostpassword_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '');
+
 	do_action('lost_password');
 	login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username or e-mail address. You will receive a new password via e-mail.') . '</p>', $errors);
 
@@ -394,6 +405,7 @@
 	</p>
 <?php do_action('lostpassword_form'); ?>
 	<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="<?php esc_attr_e('Get New Password'); ?>" tabindex="100" /></p>
+	<input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
 </form>
 
 <p id="nav">
@@ -452,12 +464,23 @@
 		$user_login = $_POST['user_login'];
 		$user_email = $_POST['user_email'];
 		$errors = register_new_user($user_login, $user_email);
-		if ( !is_wp_error($errors) ) {
-			wp_redirect('wp-login.php?checkemail=registered');
-			exit();
-		}
+    	if ( !is_wp_error($errors) ) {
+    		if ( isset( $_REQUEST['redirect_to'] ) ) {
+    			wp_safe_redirect($_REQUEST['redirect_to']);
+    		} else {
+    			wp_redirect('wp-login.php?checkemail=registered');
+    		}
+    		exit();
+    	}
 	}
 
+	if ( isset( $_REQUEST['redirect_to'] ) ) {
+		$redirect_to = $_REQUEST['redirect_to'];
+	} else {
+		$redirect_to = '';
+	}
+	$redirect_to = apply_filters('registration_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '');
+
 	login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
 ?>
 
@@ -474,6 +497,7 @@
 	<p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
 	<br class="clear" />
 	<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="<?php esc_attr_e('Register'); ?>" tabindex="100" /></p>
+	<input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
 </form>
 
 <p id="nav">
