Skip to content

Commit

Permalink
Version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
boogah authored May 30, 2023
1 parent 384a801 commit d64ddac
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 8 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,57 @@ After updating this setting, you *will* need to log out and back into WordPress

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

### 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.
Expand Down
65 changes: 62 additions & 3 deletions biscotti.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
* Plugin Name: Biscotti
* Plugin URI: https://github.com/boogah/biscotti
* Description: Biscotti makes your user's login cookie a little bit longer.
* Version: 2.0.3
* Version: 2.1.0
* Requires at least: 6.0
* Requires PHP: 7.4
* Requires PHP: 8.0
* Author: Jason Cosper
* Author URI: https://jasoncosper.com/
* License: GPL-2.0+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
* GitHub Plugin URI: boogah/biscotti
*/

// If this file is called directly, abort.
Expand All @@ -35,7 +36,7 @@ function biscotti_login_cookie_expiration_form_fields( $user )
$expiration_options = array(
'3 months' => '3 months',
'6 months' => '6 months',
'1 year' => '1 year',
'1 year' => '1 year',
);
$selected_expiration = get_the_author_meta('biscotti_login_cookie_expiration', $user->ID);
?>
Expand All @@ -57,6 +58,64 @@ function biscotti_login_cookie_expiration_form_fields( $user )
<?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_action('show_user_profile', 'biscotti_login_cookie_expiration_form_fields');
add_action('edit_user_profile', 'biscotti_login_cookie_expiration_form_fields');
Expand Down
41 changes: 36 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
=== Biscotti ===
Contributors: boogah, webaware
Donate link: http://paypal.me/boogah
Tags: login, cookies, profile
Tags: login, cookies, profile, login
Requires at least: 6.0
Tested up to: 6.2
Stable tag: 2.0.3
Requires PHP: 7.4
Stable tag: 2.1.0
Requires PHP: 8.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.txt

Expand All @@ -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.

== 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 ==

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 ==

Expand All @@ -31,7 +58,11 @@ Enjoy your long cookie!

== Changelog ==

= 2.0.2 =
= 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.

Expand Down

0 comments on commit d64ddac

Please sign in to comment.