Skip to content

Added notice for max number of active session. - #21

Open
navidabdi wants to merge 6 commits into
joel-james:improve-logout-oldestfrom
makers99:feature/warning-message-when-login-terminates-oldest-message
Open

Added notice for max number of active session.#21
navidabdi wants to merge 6 commits into
joel-james:improve-logout-oldestfrom
makers99:feature/warning-message-when-login-terminates-oldest-message

Conversation

@navidabdi

Copy link
Copy Markdown

No description provided.

@joel-james

Copy link
Copy Markdown
Owner

Thanks @navidabdi @NotARobit @sun :) I will merge this to upcoming release v2.0.

@joel-james joel-james added this to the Version 2.0.0 milestone Aug 7, 2025
@joel-james joel-james self-assigned this Aug 7, 2025
@sun

sun commented Aug 8, 2025

Copy link
Copy Markdown

Sorry! This was actually meant as a PR against the feature branch in @NotARobit's fork, so that it would become part of the main PR #19 – we absolutely did not intend to replace that PR or ignore his excellent work! 👌

And I'm sure @navidabdi also meant to add a description explaining the intention here 😅

Sorry for the mess. 😬 But if this is okay for you, then we would leave it like that now.

Comment thread includes/class-loggedin.php Outdated
unset( $sessions[ $oldest_token ] );
update_user_meta( $user_id, 'session_tokens', $sessions );

$this->add_notice_oldest_terminated = true;

@sun sun Aug 8, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that the workaround with the class property probably is not required anymore.

The missing part was to set the session cookie at the end of the POST login request with WC()->session->set_customer_session_cookie( true ) before the redirect response is issued. This is normally only happening in the woocommerce_init event at the beginning of the request.

Without setting the cookie, the shutdown handler calls WC_Session_Handler::save_data(), which saves the notice for the session into the database, but the HTTP response does not actually contain a session cookie. Therefore, the message is never displayed to the user.

So we can probably significantly simplify the changes for adding the notice to just these lines without the class property and the separate hook:
https://github.com/Joel-James/loggedin/blob/c8dc03d18f683b388aed96e19a12f148b6fc5628/includes/class-loggedin.php#L262-L268

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sun @joel-james - I tested the feature once more, and we didn't need the extra hook to wp_login and also setting the extra argument $add_notice_oldest_terminated, so I removed them.

@joel-james
joel-james changed the base branch from master to improve-logout-oldest August 11, 2025 18:17
@joel-james joel-james modified the milestones: Version 2.0.0, v2.0.1 Aug 13, 2025

@sun sun left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 👌

@sun

sun commented Jan 20, 2026

Copy link
Copy Markdown

@joel-james Is there anything we can do to get this small addition over the finish line? 🙂

@joel-james

Copy link
Copy Markdown
Owner

@sun Sure. I’ll include this in the next release. Sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants