Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

[Resolved] Issues after re-signing in

Simple Membership Plugin › Forums › Simple Membership Plugin › Issues after re-signing in

Tagged: Logout; nonce

  • This topic has 5 replies, 2 voices, and was last updated 2 months, 1 week ago by admin.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • September 5, 2026 at 8:11 am #32294
    BracketNights
    Participant

    I’m noticing that when I log in as a member (not admin), log out, then log in again, certain parts of the swpm plugin stop working correctly.
    Namely, it is that logging out stops working entirely, and a snippet I built using a php nonce stops returning any data. Given they have the same prompt (logging out then back in soon after), I guess these two things are related.

    I’m using the logout button on the membership-login page, and I haven’t changed the default code.
    I’m not using a caching plugin at all, though I have noticed a lot of browser caching, so I do use ‘Content No Cache’ to try to prevent this. The problem persists when this plugin is disabled, however.

    Details of the error: When the user logs out, then logs back in, they are then unable to log out for some time. Pressing the logout link (href=’?swpm-logout=true’) redirects them to the homepage, but does not log them out. They also lose access to a custom php/js archive, which usually shows them posts via a filter, but upon this action simply shows them -1.

    Any ideas what might be causing this and how to fix it? Thanks in advance.

    September 5, 2026 at 2:09 pm #32295
    BracketNights
    Participant

    Ah, an update (I kept playing around trying to solve this):
    I noticed my user was registered twice (WP and SMP) whenever they sign up, but they have different user IDs. I deleted the users, synchronised WP and SMP memberships, then signed up as a member again. The problem persists – there are two accounts with two different IDs, the log-out function doesn’t work on the second sign-in, and certain data is missing or persists when it’s not supposed to.
    To test this further, I temporarily added the line onclick=”<?php wp_logout() ?>” to the sign-out link. This solved the initial problems. It now means that I can’t log in though (it signs me in, but immediately signs me back out again when I leave that page), so it’s not a long-term solution.
    This does, however, mean that the problem is identified – my users have two accounts (‘users’ and ‘membership’) which are not synced (even when that option is ticked in settings) and signing in/out of one does not sign in/out of the other, thus certain information persists and certain information doesn’t.

    Any ideas how to rectify this and stop the inability to log out or see all the data via php nonce request? Thanks!

    September 6, 2026 at 6:49 am #32296
    admin
    Keymaster

    A couple of corrections first, because they are pointing you the wrong way.

    1) Having a Simple Membership member record and a corresponding WordPress user record is normal. Their IDs do not need to match. The connection relies on matching usernames and email addresses, so different IDs alone do not indicate a synchronization problem.

    The following documentation explains this:
    https://simple-membership-plugin.com/understanding-the-connection-between-simple-membership-members-and-wordpress-users/

    2) Also, onclick="<?php wp_logout() ?>" runs on the server at render time, not on click, so it was logging you out on every page load. That explains the second symptom you saw. Please remove it.

    The real cause is almost certainly a cached response. /?swpm-logout=true is a plain GET that returns a redirect, and if the browser or a CDN/host cache replays it, the request never reaches PHP, so you land on the homepage still logged in. The -1 is WordPress’s nonce failure output, and nonces are bound to the current WP user and session token, so a cached page carrying a stale nonce will fail the same way. One root cause, two symptoms.

    To confirm:

    1. Run the full login/logout/login/logout cycle in an incognito window.
    2. Check for caching outside WordPress (Cloudflare, LiteSpeed, host-level page cache), which stays active after deactivating a caching plugin.
    3. Add a cache buster to the logout link as a test: home_url(‘?swpm-logout=true&nc=’ . time()). Extra parameters are ignored by the handler.
    4. Exclude the page containing the nonce from caching, or fetch the nonce via AJAX.
    5. Enable Simple Membership > Settings > Advanced Settings > Enable Debug, reproduce once, and send me log-auth-*.txt.
    September 10, 2026 at 8:43 am #32298
    BracketNights
    Participant

    Thank you for your reply and help. I went through some of your suggestions, then found an update on the issue part way through, so I haven’t done the others yet. I don’t know whether they are relevant after the discovery listed below.

    Incognito mode: same issue happening.
    With ‘/?swpm-logout=true&nc=’ . time(): same issue happening.
    Added the ol’ ‘Header set Cache-Control’ etc to htaccess: same issue happening.
    I can’t find an active caching service on WP or my webhosting.

    Referred to issue: logout link is working again (the user seems to be logged out), but once logged out, certain pieces of php/js are being displayed as if the user is still logged in (piece of info from the user’s meta data) on multiple pages.

    However, UPDATE:
    If, in my php snippet, I replace “if ( is_user_logged_in() )” with “if ( SwpmMemberUtils::is_member_logged_in() )”, the issue goes away and the website works as intended.
    This suggests that the logout link (the default one on the profile page, as I have not created any other) is only logging out of the Simple Membership, not WordPress.
    Is this normal? Is this an error that can be fixed?

    September 11, 2026 at 7:34 am #32301
    admin
    Keymaster

    No, this isn’t normal. The logout link is designed to log the user out of both the member session and the WordPress session. There is one exception: if the plugin doesn’t see an active member session when the link is clicked, it exits early and the WordPress session is left untouched. That matches what you’re seeing, so the two sessions are getting out of step somewhere.

    Could you tell me:

    How members log in. Is it only through the Simple Membership login form, or also wp-login.php, another plugin, or custom code?
    Whether any custom code calls wp_signon() or wp_set_auth_cookie().
    Whether Redis or Memcached object caching is active on your host.

    Please also enable Simple Membership -> Settings -> Enable Debug. Reproduce the login, logout, login, logout cycle once and share the log-auth file’s content from those interactions.

    Keep the SwpmMemberUtils::is_member_logged_in() change. It’s the right check for member content.

    September 14, 2026 at 5:18 am #32319
    BracketNights
    Participant

    Well, I found one thing and it fixed one of the problems, but I’m still having a problem with the -1 nonce/cache issue…

    The members are only logging in and out using the Simple Membership forms – no other plugin or custom code.

    I looked further and I still can’t find a caching plugin on WP nor on my host. No Redis or Memcached from what I can find (my webhost service is pretty poor at providing information though).
    I also tried this in different browsers, private mode, and with hard refreshes, all finding the same result, so I really don’t think it’s a browser issue.

    There were no wp_signon() or wp_set_auth_cookie(), but I did find an errant line of wp_set_current_user(0) which I deleted. After deletion, the login and logout seems to work correctly.

    The only remaining issue is that my custom code which requires a nonce works perfectly when not logged in, but often (not always) returns a -1 error when logged in for a short time. If I wait a while, it’ll work normally. Therefore, it has to be a nonce issue with logging in, right?
    Below are my Auth logs and my actions (in case that part is useful too).

    (Note: ‘archive’ here is not the normal archive page, it’s a custom page with php, js, and a wp-nonce)
    1118 Arrive to website, logged out, decline cookies.
    1118 Archive – working, with logged out details.
    1118 Logged in successfully.
    1118 Archive – not working, has -1 error. Console reads: “wp-admin/admin-ajax.php:1 Failed to load resource: the server responded with a status of 403 ()”.
    1119 Homepage shows logged in details correctly.
    1120 Logged out successfully, homepage shows logged out details correctly.
    1120 Archive – working, with logged out details.
    1121 Update meta whilst logged out (should not update logged in meta).
    1122 Logged in successfully.
    1122 Archive – working, with logged in details.
    1123 Logged out successfully.
    1123 Archive – working, with logged out details.
    1123 Logged in successfully.
    1123 Archive – not working, has -1 error.
    1134 Archive – working, with logged in details.

    [2026/09/12 11:18:42] – SUCCESS: Authentication request – Username: teacherpierce
    [2026/09/12 11:18:42] – SUCCESS: SwpmAuth::set_cookie() – Value of ‘remember me’ parameter:
    [2026/09/12 11:18:42] – SUCCESS: The ‘Remember me’ option is unchecked for this request, setting expiry to be a session cookie. The session cookie will expire when the browser is closed.
    [2026/09/12 11:18:42] – SUCCESS: Authentication successful for username: teacherpierce. Triggering swpm_after_login_authentication action hook.
    [2026/09/12 11:18:42] – SUCCESS: Trying wp_signon() with username: teacherpierce
    [2026/09/12 11:18:42] – SUCCESS: wp_authenticate action. Handling login for username: teacherpierce
    [2026/09/12 11:18:42] – SUCCESS: SwpmAuth::login()
    [2026/09/12 11:18:42] – SUCCESS: wp_login hook triggered. Username: teacherPierce
    [2026/09/12 11:18:42] – SUCCESS: Setting current WP user to: teacherPierce
    [2026/09/12 11:18:42] – SUCCESS: Triggering swpm_login_auth_completed_filter hook.
    [2026/09/12 11:18:42] – SUCCESS: Triggering swpm_after_login hook.
    [2026/09/12 11:18:42] – SUCCESS: After triggering the default swpm_after_login_redirect_url hook. Redirect URL: https://www.bracketnights.com/membership-login/
    [2026/09/12 11:20:24] – SUCCESS: SwpmAuth::logout() – Logout request received for username: teacherPierce
    [2026/09/12 11:20:24] – SUCCESS: SwpmAuth::logout() – Logout actions executed successfully.
    [2026/09/12 11:22:36] – SUCCESS: Authentication request – Username: teacherpierce
    [2026/09/12 11:22:36] – SUCCESS: SwpmAuth::set_cookie() – Value of ‘remember me’ parameter:
    [2026/09/12 11:22:36] – SUCCESS: The ‘Remember me’ option is unchecked for this request, setting expiry to be a session cookie. The session cookie will expire when the browser is closed.
    [2026/09/12 11:22:36] – SUCCESS: Authentication successful for username: teacherpierce. Triggering swpm_after_login_authentication action hook.
    [2026/09/12 11:22:36] – SUCCESS: Trying wp_signon() with username: teacherpierce
    [2026/09/12 11:22:36] – SUCCESS: wp_authenticate action. Handling login for username: teacherpierce
    [2026/09/12 11:22:36] – SUCCESS: SwpmAuth::login()
    [2026/09/12 11:22:36] – SUCCESS: wp_login hook triggered. Username: teacherPierce
    [2026/09/12 11:22:36] – SUCCESS: Setting current WP user to: teacherPierce
    [2026/09/12 11:22:36] – SUCCESS: Triggering swpm_login_auth_completed_filter hook.
    [2026/09/12 11:22:36] – SUCCESS: Triggering swpm_after_login hook.
    [2026/09/12 11:22:36] – SUCCESS: After triggering the default swpm_after_login_redirect_url hook. Redirect URL: https://www.bracketnights.com/membership-login/
    [2026/09/12 11:23:29] – SUCCESS: SwpmAuth::logout() – Logout request received for username: teacherPierce
    [2026/09/12 11:23:29] – SUCCESS: SwpmAuth::logout() – Logout actions executed successfully.
    [2026/09/12 11:24:09] – SUCCESS: Authentication request – Username: teacherpierce
    [2026/09/12 11:24:09] – SUCCESS: SwpmAuth::set_cookie() – Value of ‘remember me’ parameter:
    [2026/09/12 11:24:09] – SUCCESS: The ‘Remember me’ option is unchecked for this request, setting expiry to be a session cookie. The session cookie will expire when the browser is closed.
    [2026/09/12 11:24:09] – SUCCESS: Authentication successful for username: teacherpierce. Triggering swpm_after_login_authentication action hook.
    [2026/09/12 11:24:09] – SUCCESS: Trying wp_signon() with username: teacherpierce
    [2026/09/12 11:24:09] – SUCCESS: wp_authenticate action. Handling login for username: teacherpierce
    [2026/09/12 11:24:09] – SUCCESS: SwpmAuth::login()
    [2026/09/12 11:24:09] – SUCCESS: wp_login hook triggered. Username: teacherPierce
    [2026/09/12 11:24:09] – SUCCESS: Setting current WP user to: teacherPierce
    [2026/09/12 11:24:09] – SUCCESS: Triggering swpm_login_auth_completed_filter hook.
    [2026/09/12 11:24:09] – SUCCESS: Triggering swpm_after_login hook.
    [2026/09/12 11:24:09] – SUCCESS: After triggering the default swpm_after_login_redirect_url hook. Redirect URL: https://www.bracketnights.com/membership-login/

    I just noticed that it redirects me back to the homepage, not to /membership-login/. I don’t know if that’s normal or not (I prefer it with the homepage redirect anyway) but I’ll mention it as it seems different from the logs.

    Thanks again for your help. I appreciate it. I can’t figure this one out on my own, haha.

    September 14, 2026 at 5:26 am #32323
    admin
    Keymaster

    Good progress. The wp_set_current_user(0) line explains the logout problem, so that part is sorted.

    The remaining -1 is a nonce failure, not a plugin bug. A -1 with a 403 from admin-ajax.php is WordPress’s response when nonce verification fails. If the action itself were missing you would get 0 instead.

    WordPress nonces are tied to the current user ID and the current session token, not just the action name. So a nonce created while logged out (user ID 0) will fail once it is verified as a logged-in user, and a nonce created before a logout will fail after logging back in, because logout destroys the WordPress session token and the new login creates a different one.

    Most likely cause: the nonce is going out inside a JS file or markup that is being cached in a different login state. Even without a caching plugin, JS minify/combine/optimise features (Autoptimize, LiteSpeed, SiteGround Optimizer, Jetpack Boost, Perfmatters, theme optimisers, CDN asset combining) will bake a stale nonce into a cached file. Turn all JS optimisation off and retest.

    To confirm, log get_current_user_id() and wp_get_session_token() both where you create the nonce and at the start of your AJAX handler, then compare. Also check that your AJAX URL is built with admin_url(‘admin-ajax.php’) so the host and scheme match the page, otherwise the auth cookie is not sent and the request is evaluated as logged out.

    Finally, a nonce is CSRF protection, not authentication. Keep the SwpmMemberUtils::is_member_logged_in() check for deciding what data to return, and register both wp_ajax_ and wp_ajax_nopriv_ handlers for your action.

    The custom archive code is outside what we can support here, but this should be enough to track it down.

    September 17, 2026 at 3:51 am #32324
    BracketNights
    Participant

    Thank you once again for your help. I have finally managed to solve it using your advice on what to look for and log. I’ll summarise it below for anyone else who might have the same issue, then I’ll resolve the topic.

    Problem 1: The logout button did not work. Users would remain logged in.
    Solution 1: Removed an errant wp_set_current_user(0) from the plugin code, which I probably put there during my trying to solve problem 2.

    Problem 2: The user’s data (custom code) was still showing and updatable after logout.
    Solution 2: Needed to identify whether is_user_logged_in() or is_member_logged_in() gives me the data I require to be displayed.

    Problem 3: Ajax code was returning a logged-out nonce after login, returning a -1 403 error.
    Solution 2: It was a caching issue, despite me having no caching software that I could find. Every indication was that my website’s Cache-Control was no-cache, but I had to enforce this anyway with the function.php headers and add an expired expiry date. This, coupled with a deferred strategy and null version number when enqueuing the js file that calls the ajax, seems to have solved the problem.

    Thanks again. Bracketnights will hopefully be up and running soon.

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy