Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to make Wordpress' "Remember Me" login checkbox work for a really long time, like a year? Currently I think it only works for a few days or a week max, usually I am not remembered.

share|improve this question

2 Answers 2

up vote 8 down vote accepted

I think I'll wait for such a plugin

Save this code in a file named set-cookie-expire.php and upload it your plugins folder.

The plugin will give you the ability to set a time (in days) that cookies expire within the WordPress Settings admin.

<?php

/**
 * Plugin Name: Set Cookie Expire
 * Version: 0.1
 * Description: Set the expire time for cookies in <a href="options-privacy.php">Settings &raquo; Privacy</a>.
 * Author: WordPress Answers
 * Author URI: http://wordpress.stackexchange.com/questions/11979
 */

if ( is_admin() ) :

/**
 * Register settings.
 */
function __set_cookie_expire_admin()
{
    foreach ( array( 'normal' => 'Normal', 'remember' => 'Remember' ) as $type => $label ) {
        register_setting( 'privacy', "{$type}_cookie_expire", 'absint' );
        add_settings_field( "{$type}_cookie_expire", $label . ' cookie expire', '__set_cookie_expire_option', 'privacy', 'default', $type );
    }
}
add_action( 'admin_init', '__set_cookie_expire_admin' );

/**
 * Setting field callback.
 */
function __set_cookie_expire_option( $type )
{
    if ( !$expires = get_option("{$type}_cookie_expire") )
        $expires = $type === 'normal' ? 2 : 14;
    echo '<input type="text" name="' . $type . '_cookie_expire" value="' . intval( $expires ) . '" class="small-text" /> days';
}

endif;

/**
 * Filter in our user-specified expire times.
 */
function __set_cookie_expire_filter( $default, $user_ID, $remember )
{
    if ( !$expires = get_option( $remember ? 'remember_cookie_expire' : 'normal_cookie_expire' ) )
        $expires = 0;

    if ( $expires = ( intval( $expires ) * 86400 ) ) // get seconds
        $default = $expires;
    return $default;
}
add_filter( 'auth_cookie_expiration', '__set_cookie_expire_filter', 10, 3 );

?>

Also submitted on Pastie.

share|improve this answer
4  
Awesome! +10 for writing a plugin as an answer. –  ripper234 Mar 14 '11 at 16:43

Wordpress versions great than 2.4 store two cookies that set to expire in two weeks according to the Codex. According to this blog post (linked in the Codex), you can edit the wp_set_auth_cookie function in the pluggable.php file in the wp-includes folder of Wordpress. The exact line will depend on which version of Wordpress you are using.

What is probably better is to write or use a plug-in to replace the wp_set_auth_cookie function instead. If you edit the Wordpress core files, they will be replaced if you use the auto-updater or do a manual installation of Wordpress and copy the files without preserving whatever changes you made.

share|improve this answer
    
Thanks for the answer - I think I'll wait for such a plugin, not too thrilled to get into WP code right now. –  ripper234 Mar 14 '11 at 14:10
3  
Good choice. You shouldn't ever edit core files, whether you're thrilled about it or not. ;) –  tnorthcutt Mar 14 '11 at 15:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.