Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does anyone know the logic on how to do the following:

I have a login section with a password field only on the index, so the user enter the password and submit. Upon submission, I was hoping if the password entered can match with the passwords of the existing protected pages. Once there's a single match, the user will be redirected to that password protected page as login successful.

Do u think it's possible..? I need some hope here, thanks!

share|improve this question
    
I voted to close this as it is too localized. It looks utterly complicated to me to do something like that because it's against anything Wordpress ships with. There is more or less no API at all to dig up/set proceted pages to users. –  hakre Feb 6 '11 at 16:43
add comment

1 Answer

This answer assumes you are talking about the regular login page, /wp-login.php, and that each user exists as a user in the WordPress database. After reading your question again I'm not so sure that is what you want to do.

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;
}
share|improve this answer
    
Basically, I dont need the wp_login which require users. I will need to play with the password from password-protected pages only. I've managed to prompt user to enter the password required for their protected pages using the direct link of that page. However, I will need to allow user to enter the password on the index (or any other un-protected pages/post) and if the password match with any of the protected pages, it will redirect the user that protected page and classify them as login to the protected page. –  hahahalif Dec 30 '10 at 3:10
    
Let's assume that the admin will not generate the same password for any of the protected pages. –  hahahalif Dec 30 '10 at 3:11
    
I was hoping if you could help me and show me the light.. –  hahahalif Dec 30 '10 at 10:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.