The following php is stored as a template in my Wordpress site:
Code: Select all
<?php /*
function dopasswordstuff(){
if(isset($_POST['homepagepassword'])) {
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)) {
if ( empty( $wp_hasher ) ) {
require_once( ABSPATH . 'wp-includes/class-phpass.php' );
// By default, use the portable hash from phpass
$wp_hasher = new PasswordHash(8, true);
}
// 10 days
setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $post_password ) ), time() + 864000, COOKIEPATH );
wp_redirect(get_permalink($post_id));
}
exit;
}
}
add_action('template_redirect','dopasswordstuff');
?>