Created
August 4, 2012 20:45
-
-
Save Viper007Bond/3259814 to your computer and use it in GitHub Desktop.
Custom Post Password Cookie Expiry Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /* | |
************************************************************************** | |
Plugin Name: Custom Post Password Cookie Expiry Time | |
Description: WordPress doesn't allow you to customize how long a post password cookie lasts. This plugin allows you to customize that value; | |
Version: 1.0.0 | |
Author: Alex Mills (Viper007Bond) | |
Author URI: http://www.viper007bond.com/ | |
**************************************************************************/ | |
/** | |
* Hook in right before the normal stuff fires in wp-login.php and set the cookie ourself | |
*/ | |
add_action( 'login_form_postpass', 'login_form_postpass_custom_expiry' ); | |
function login_form_postpass_custom_expiry() { | |
global $wp_hasher; | |
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); | |
} | |
setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $_POST['post_password'] ) ), time() + 14400, COOKIEPATH ); | |
wp_safe_redirect( wp_get_referer() ); | |
exit(); | |
} |
er...functions.php of my theme...
Yes, your theme's functions.php
or a plugin. Either will work.
Side note: here's the core ticket I opened about this issue: http://core.trac.wordpress.org/ticket/21466
A plugin would probably be better though -- that's what I wrote this code as (the stuff at the top of the code). You can just paste it into a new .php
file, upload it to your /wp-content/plugins/
folder, and then activate it. Probably better than using your theme for this.
As of http://core.trac.wordpress.org/changeset/25450 this plugin is no longer needed.
Just hook into the new filter and return your own value.
This code is not working in the latest version of wp 4.3.1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Viper, just to confirm - I paste this in the top of wp-login.php? I completely forgot since Sat when we met.