给你:
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\');
我
cribbed some stuff from the Core post login system 我相信我成功了。诀窍是设置cookie,这需要添加以下部分:
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 );