Skip to content

Instantly share code, notes, and snippets.

@tott
Created September 4, 2012 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tott/3619324 to your computer and use it in GitHub Desktop.
Save tott/3619324 to your computer and use it in GitHub Desktop.
wp-pass.php replacement for wp > 3.4
<?php
add_action( 'plugins_loaded', 'bypass_wp_login_for_pw_protected_posts' );
function bypass_wp_login_for_pw_protected_posts() {
// this functionality is a fork of http://core.trac.wordpress.org/browser/trunk/wp-login.php#L385
// keep this in sync with Core
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'login';
if ( 'postpass' <> $action )
return;
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['post_password'] ) ), time() + 864000, COOKIEPATH );
wp_safe_redirect( wp_get_referer() );
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment