Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Created February 10, 2023 19:06
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 stefanpejcic/4e74c881099792d5afe3753f402f3ab1 to your computer and use it in GitHub Desktop.
Save stefanpejcic/4e74c881099792d5afe3753f402f3ab1 to your computer and use it in GitHub Desktop.
Added a settings field for the plugin https://wordpress.org/plugins/wp-keep-me-logged-in/
<?php
/*
Plugin Name: WP Keep Me Logged In
Plugin URI: http://www.ruudkok.nl/wordpress/keep-me-logged-in/
Description: This plugin will increase the session time of your WordPress login cookie to 1 year. That way you won't have to login over and over again. I was inspired to write this plugin after reading <a href="http://wpengineer.com/2064/stop-wordpress-from-ever-logging-out/">Frank Bültge</a>'s blogpost.
Author: Ruud Kok
Author URI: http://www.ruudkok.nl/
Version: 1.1
*/
add_action( 'admin_init', 'rk_add_keep_me_logged_in_setting' );
function rk_add_keep_me_logged_in_setting() {
add_settings_field(
'rk_keep_me_logged_in_setting',
'Keep me logged in for (days)',
'rk_keep_me_logged_in_setting_callback',
'general'
);
register_setting( 'general', 'rk_keep_me_logged_in_setting' );
}
function rk_keep_me_logged_in_setting_callback() {
$value = get_option( 'rk_keep_me_logged_in_setting', 365 );
echo '<input type="number" name="rk_keep_me_logged_in_setting" value="' . esc_attr( $value ) . '">';
}
function rk_keep_me_logged_in( $expiration ) {
$days = get_option( 'rk_keep_me_logged_in_setting', 365 );
return $days * DAY_IN_SECONDS;
}
add_filter( 'auth_cookie_expiration', 'rk_keep_me_logged_in' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment