I had a closer look, and essentially it is only the following addition at the end of the pagrestrict.php file that does the trick:
// The redirect from the login form fails sometimes.
// We save the target page url in a transient, and redirect very late (at action 'template_redirect') if we are not on the target page
function pr_save_url() {
$url = ( is_ssl() ? 'https://' : 'https://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
set_transient( 'pr_' . $_SERVER['REMOTE_ADDR'], $url, 300 );
}
// After any other redirect (i hope)
add_action( 'template_redirect', 'pr_redirect' );
function pr_redirect() {
$url = get_transient( 'pr_' . $_SERVER['REMOTE_ADDR'] );
if ( $url ) {
// Housekeeping
delete_transient( 'pr_' . $_SERVER['REMOTE_ADDR'] );
// Only if login succeeded
if ( is_user_logged_in() ) {
$cur = ( is_ssl() ? 'https://' : 'https://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ( $url != $cur ) {
wp_redirect( $url );
exit();
}
}
}
}
The other changes i made are only to make it more readable and i use function
wp_login_form( array( 'echo' => false, 'value_username' => $user_login ) )
I left the 'redirect' => $any_url
out, because it does not work like it does not work in the original login form.
So, essentially it looks like a wp bug to me…
Just add my additional code.