Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Password redirect WordPress

  • SOLVED

Hello, I am looking to have a page called 'client login' on my site.

Upon this page I would like the client to enter just a password, depending on what password is entered I would like the client to be redirected to a password protected page.

So 'client1' enters 'password1' redirects to 'clientpage1'

'client2' enters 'password2' redirects to 'clientpage2'


Can this be done?

Answers (6)

2014-01-27

Bob answers:

here is script that can help you.

::Put below code in your theme's functions.php file::

// create shortcode to display login form
function func_loginpassword( $atts, $content = null ) {
return '<form name="login-password" method="post">Please enter password:<input name="passwordfield" type="password"><input type="submit" name="submitpwd" value="Submit"></form>';
}
add_shortcode( 'loginpassword', 'func_loginpassword' );
//find post and redirect user to that post.
function dopasswordstuff(){
if(isset($_POST['submitpwd'])){
global $wpdb;
$post_password = trim($_POST['passwordfield']);
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_password = %s", $post_password) );
if (!empty($post_id)) {
wp_redirect(get_permalink($post_id));
exit;
}

}
}
add_action('template_redirect','dopasswordstuff');

then create one page for user to log in.
add shortcode [loginpassword] there. this code will generate form for user to enter password that will be login page for user.


Note that user have to enter password twice. first time for general login page and another after redirection to that particular page.


Bob comments:

Oh I forget to mention that you have to set password for each page that you want to protect and user need to redirected.