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
* Plugin URI: http://wordpress.stackexchange.com/a/11991/1685
* Version: 0.1
* Description: Set the expire time for cookies in your <a href="https://wordpress.stackexchange.com/questions/11979/options-general.php">general settings</a>.
* Author: WordPress Development Stack Exchange
* Author URI: http://wordpress.stackexchange.com/a/11991/1685
*/
/**
* Set our user-specified expire times.
*
* @param int $default
* @param int $user_id
* @param bool $remember
* @return int
*/
function wpse_11979_set_cookie_expire( $default, $user_id, $remember ) {
$days = get_option( $remember ? 'remember_cookie_expire' : 'normal_cookie_expire' );
if ( $days === false )
$days = $remember ? 14 : 2;
else
$days = ( int ) $days;
return $days * DAY_IN_SECONDS;
}
add_filter( 'auth_cookie_expiration', 'wpse_11979_set_cookie_expire', 10, 3 );
/**
* Register settings.
*/
function wpse_11979_set_cookie_expire_settings() {
$settings = array(
'normal_cookie_expire' => 'Normal Cookie Expire',
'remember_cookie_expire' => 'Remember Cookie Expire',
);
foreach ( $settings as $id => $label ) {
add_settings_field(
$id,
$label,
'wpse_11979_set_cookie_expire_field',
'general',
'default',
array(
'label_for' => $id,
)
);
register_setting( 'general', $id, 'absint' );
}
}
add_action( 'admin_init', 'wpse_11979_set_cookie_expire_settings' );
/**
* Render settings field.
*
* @param array $args
*/
function wpse_11979_set_cookie_expire_field( $args ) {
$id = $args['label_for'];
printf(
'<input id="%2$s" type="text" name="%2$s" value="%1$d" class="small-text" /> days',
( int ) get_option( $id, $id === 'normal_cookie_expire' ? 2 : 14 ),
$id
);
}