Skip to main content
1 of 2
Jan Fabry
  • 30.5k
  • 4
  • 90
  • 136

This is a first attempt, but it is not complete because it asks for your password again on the protected post, and because it does not know when you want to visit /wp-admin/ or another restricted area.

add_filter( 'login_redirect', 'wpse6072_login_redirect', 10, 2 );
function wpse6072_login_redirect( $redirect_to, $requested_redirect )
{
    // You somehow need to figure out how to make a difference between an admin login and a regular login
    if ( /*! array_key_exists( 'redirect_to', $_REQUEST ) &&*/ array_key_exists( 'pwd', $_POST ) ) {
        global $wpdb;
        $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_password = %s", $_POST['pwd'] ) );
        $post_permalink = get_permalink( $post_id );
        if ( $post_permalink ) {
            // TODO: Set the post password in a way that satisfied WordPress
            $redirect_to = $post_permalink;
        }
    }
    return $redirect_to;
}
Jan Fabry
  • 30.5k
  • 4
  • 90
  • 136