Compare commits

..

16 Commits
v2.0.0 ... main

Author SHA1 Message Date
Jason Cosper
d64ddac2e9
Version 2.1.0 2023-05-30 13:51:21 -07:00
Jason Cosper
384a801cc8
Updating "Tested up to" to 6.2 2023-03-23 10:44:38 -07:00
Jason Cosper
5bcef8e32d
Bump to version 2.0.3 2023-01-13 09:50:14 -08:00
Jason Cosper
07011b0e6a
Bump to version 2.0.3 2023-01-13 09:49:22 -08:00
Jason Cosper
311e55b561
Bump version to 2.0.3 2023-01-13 09:47:28 -08:00
Jason Cosper
015ba8cdda
Merge pull request #3 from webaware/auth-cookie-hook
use the arguments passed to the `auth_cookie_expiration` hook
2023-01-13 09:39:47 -08:00
Ross McKay
c9be806e33 remove strict typing, for older PHP versions 2023-01-13 16:31:27 +11:00
Ross McKay
5611bdb72f use the arguments passed to the auth_cookie_expiration hook
see [the filter hook doco](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/) for details on this hook
fixes #2
2023-01-13 16:28:05 +11:00
Jason Cosper
7d3860747d v2.0.2 2023-01-05 17:41:03 -08:00
Jason Cosper
727ce912ef v2.0.2 2023-01-05 17:37:10 -08:00
Jason Cosper
009419a826 Sanitize, not escape. 2023-01-05 17:35:16 -08:00
Jason Cosper
b76c6cafe7
v2.0.1 2023-01-05 13:49:37 -08:00
Jason Cosper
f3e0af19fa
v2.0.1 2023-01-05 13:49:08 -08:00
Jason Cosper
c1df116b37
Escaping $_POST
Implementing feedback from the WordPress Plugin Review Team, because I was sloppy. 🤦‍♂️
2023-01-05 13:43:46 -08:00
Jason Cosper
d157b1fb26 Implementing @afragen's feedback
Andy's feedback comes from his response to this Mastodon post:

https://simian.rodeo/@boogah/109626685435588163
2023-01-03 11:16:41 -08:00
Jason Cosper
88db9c346b Create .gitignore 2023-01-03 10:14:18 -08:00
4 changed files with 189 additions and 18 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.DS_Store

View File

@ -16,8 +16,69 @@ After updating this setting, you *will* need to log out and back into WordPress
Enjoy your long cookie! Enjoy your long cookie!
## WP-CLI Command
As of version 2.1.0, Biscotti includes WP-CLI commands for managing a user's logged in session cookie expiration.
### `biscotti get`
This command returns the previously defined cookie expiration of a user.
#### Options
`<user_id>` — The ID of the user.
#### Examples
To get the logged in session cookie expiration of a user with the ID of 123, you would use:
```bash
wp biscotti get 123
```
### `biscotti set`
This command sets the logged in session cookie expiration of a user.
#### Options
`<user_id>` — ID of the user.
`<expiration>` — New expiration duration. It must be one of the following values:
* `'3 months'`
* `'6 months'`
* `'1 year'`
#### Examples
To set a logged in session cookie expiration of the user with ID 123 to '1 year', you would use:
```bash
wp biscotti set 123 '1 year'
```
### Note
Please remember to replace the `user_id` and `expiration` placeholders with the actual user ID and desired expiration duration when running either of these commands.
## Changelog ## Changelog
### 2.1.0
Added WP-CLI command. Bumped required PHP version to 8.0.
### 2.0.3
@webaware has decided to help make this code less awful and submitted a pull request. This release implements their improvements.
### 2.0.2
Sanitize. Not escape. Ack!
### 2.0.1
Forgot to escape the lone `$_POST` in my code. Feel dumb about it. Fixed now tho.
### 2.0.0 ### 2.0.0
Rewrite! Now, instead of forcing *everyone* to use the same login cookie expiration, Biscotti allows users to individually select their login cookie expiration on their profile page. Rewrite! Now, instead of forcing *everyone* to use the same login cookie expiration, Biscotti allows users to individually select their login cookie expiration on their profile page.

View File

@ -15,11 +15,14 @@
* Plugin Name: Biscotti * Plugin Name: Biscotti
* Plugin URI: https://github.com/boogah/biscotti * Plugin URI: https://github.com/boogah/biscotti
* Description: Biscotti makes your user's login cookie a little bit longer. * Description: Biscotti makes your user's login cookie a little bit longer.
* Version: 2.0.0 * Version: 2.1.0
* Requires at least: 6.0
* Requires PHP: 8.0
* Author: Jason Cosper * Author: Jason Cosper
* Author URI: https://jasoncosper.com/ * Author URI: https://jasoncosper.com/
* License: GPL-2.0+ * License: GPL-2.0+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
* GitHub Plugin URI: boogah/biscotti
*/ */
// If this file is called directly, abort. // If this file is called directly, abort.
@ -55,6 +58,64 @@ function biscotti_login_cookie_expiration_form_fields( $user )
<?php <?php
} }
if ( defined( 'WP_CLI' ) && WP_CLI ) {
/**
* Manages a user's logged in session cookie expiration.
*/
class Biscotti_Command {
/**
* Get the logged in session cookie expiration of a user.
*
* ## OPTIONS
*
* <user_id>
* : ID of the user.
*
* ## EXAMPLES
*
* wp biscotti get 123
*
*/
function get( $args ) {
list( $user_id ) = $args;
$expiration = get_user_meta( $user_id, 'biscotti_login_cookie_expiration', true );
WP_CLI::line( 'Cookie expiration: ' . $expiration );
}
/**
* Set the logged in session cookie expiration of a user.
*
* ## OPTIONS
*
* <user_id>
* : ID of the user.
*
* <expiration>
* : New expiration duration.
*
* ## EXAMPLES
*
* wp biscotti set 123 '1 year'
*
*/
function set( $args ) {
list( $user_id, $expiration ) = $args;
update_user_meta( $user_id, 'biscotti_login_cookie_expiration', $expiration );
WP_CLI::success( 'Updated cookie expiration.' );
}
}
if ( class_exists( 'WP_CLI' ) ) {
WP_CLI::add_command( 'biscotti', 'Biscotti_Command' );
}
}
// Add the form fields to the user profile page. // Add the form fields to the user profile page.
add_action('show_user_profile', 'biscotti_login_cookie_expiration_form_fields'); add_action('show_user_profile', 'biscotti_login_cookie_expiration_form_fields');
add_action('edit_user_profile', 'biscotti_login_cookie_expiration_form_fields'); add_action('edit_user_profile', 'biscotti_login_cookie_expiration_form_fields');
@ -65,17 +126,22 @@ function biscotti_login_cookie_expiration_form_fields_update( $user_id )
if (! current_user_can('edit_user', $user_id) ) { if (! current_user_can('edit_user', $user_id) ) {
return; return;
} }
update_user_meta($user_id, 'biscotti_login_cookie_expiration', $_POST['biscotti_login_cookie_expiration']); update_user_meta($user_id, 'biscotti_login_cookie_expiration', sanitize_text_field($_POST['biscotti_login_cookie_expiration']));
} }
// Save the chosen login cookie expiration date when the user profile is updated. // Save the chosen login cookie expiration date when the user profile is updated.
add_action('personal_options_update', 'biscotti_login_cookie_expiration_form_fields_update'); add_action('personal_options_update', 'biscotti_login_cookie_expiration_form_fields_update');
add_action('edit_user_profile_update', 'biscotti_login_cookie_expiration_form_fields_update'); add_action('edit_user_profile_update', 'biscotti_login_cookie_expiration_form_fields_update');
// Modify the expiration of the logged in user cookie. /**
function biscotti_login_cookie_expiration_set_auth_cookie( $auth_cookie_data ) * Modify the expiration of the logged in user cookie.
* @param int $expiration
* @param int $user_id
* @param bool $remember
* @return int
*/
function biscotti_login_cookie_expiration_set_auth_cookie( $expiration, $user_id, $remember )
{ {
$user_id = $auth_cookie_data[0];
$expiration_time = get_user_meta($user_id, 'biscotti_login_cookie_expiration', true); $expiration_time = get_user_meta($user_id, 'biscotti_login_cookie_expiration', true);
if (! empty($expiration_time) ) { if (! empty($expiration_time) ) {
@ -88,9 +154,8 @@ function biscotti_login_cookie_expiration_set_auth_cookie( $auth_cookie_data )
} else { } else {
$expiration = ''; // Use default expiration of 14 days. $expiration = ''; // Use default expiration of 14 days.
} }
$auth_cookie_data[2] = $expiration;
} }
return $auth_cookie_data; return $expiration;
} }
// Modify the expiration of the logged in user cookie when a user logs into the site. // Modify the expiration of the logged in user cookie when a user logs into the site.

View File

@ -1,11 +1,11 @@
=== Biscotti === === Biscotti ===
Contributors: boogah Contributors: boogah, webaware
Donate link: http://paypal.me/boogah Donate link: http://paypal.me/boogah
Tags: login, cookies, profile Tags: login, cookies, profile, login
Requires at least: 6.0 Requires at least: 6.0
Tested up to: 6.1.1 Tested up to: 6.2
Stable tag: 2.0.0 Stable tag: 2.1.0
Requires PHP: 7.4 Requires PHP: 8.0
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.txt License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@ -15,9 +15,36 @@ Biscotti makes your user's login cookie a little bit longer.
Biscotti is a plugin that modifies the expiration of the logged in user cookie in WordPress to three months, six months, or one year. Because some people hate to have to keep entering their passwords. Biscotti is a plugin that modifies the expiration of the logged in user cookie in WordPress to three months, six months, or one year. Because some people hate to have to keep entering their passwords.
== WP-CLI Commands ==
As of version 2.1.0, Biscotti includes WP-CLI commands for managing a user's logged in session cookie expiration.
= biscotti get =
This command returns the previously defined cookie expiration of a user.
== Options ==
`<user_id>` — The ID of the user.
= biscotti set =
This command sets the logged in session cookie expiration of a user.
== Options ==
`<user_id>` — ID of the user.
`<expiration>` — New expiration duration. It must be one of the following values: `'3 months'`, `'6 months'`, `'1 year'`
= Note =
Please remember to replace the `user_id` and `expiration` placeholders with the actual user ID and desired expiration duration when running either of these commands.
== Installation == == Installation ==
To install this plugin, drop `biscotti.php` into your site\'s `wp-content/plugins` directory and activate it. To install this plugin, drop `biscotti.php` into your site's `wp-content/plugins` directory and activate it.
== Frequently Asked Questions == == Frequently Asked Questions ==
@ -31,6 +58,22 @@ Enjoy your long cookie!
== Changelog == == Changelog ==
= 2.1.0 =
Added WP-CLI command. Bumped required PHP version to 8.0.
= 2.0.3 =
@webaware has decided to help make this code less awful and submitted a pull request on GitHub. This release implements their improvements.
= 2.0.2 =
Sanitize. Not escape. Ack!
= 2.0.1 =
Forgot to escape the lone `$_POST` in my code. Feel dumb about it. Fixed now tho.
= 2.0.0 = = 2.0.0 =
Rewrite! Now, instead of forcing *everyone* to use the same login cookie expiration, Biscotti allows users to individually select their login cookie expiration on their profile page. Rewrite! Now, instead of forcing *everyone* to use the same login cookie expiration, Biscotti allows users to individually select their login cookie expiration on their profile page.