Skip to content

fix: use priority 11 for ensure_tokens_still_fresh init hook - #678

Merged
daggerhart merged 3 commits into
oidc-wp:developfrom
thisismyurl:fix/token-refresh-init-hook-priority
Nov 17, 2026
Merged

daggerhart merged 3 commits into
oidc-wp:developfrom
thisismyurl:fix/token-refresh-init-hook-priority

Conversation

@thisismyurl

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

ensure_tokens_still_fresh was registered as an init hook at the default priority 10. The problem is that this registration happens inside the plugin's own init callback, which also runs at priority 10. WordPress doesn't add callbacks to a priority that's currently executing — they're silently dropped. So token refresh was never called, even when enabled.

Changing to priority 11 puts it in the next batch WordPress processes, after the priority-10 queue drains.

One argument added, no other changes.

Closes #675.

How to test the changes in this Pull Request:

  1. Enable Token Refresh in the plugin settings.
  2. Set a short access token lifetime on your IDP (e.g. 60 seconds).
  3. Log in via OIDC.
  4. Wait for the access token to expire.
  5. Enable logging and load any page — the log should show a request_new_tokens entry. Before this fix it would not appear.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable? — No new test added; the existing flow is integration-level and requires a live IDP.
  • Have you successfully run tests with your changes locally? — Confirmed via code inspection and the diagnosis in ensure_tokens_still_fresh never gets called because of init hook priority #675; live IDP testing requires infrastructure I don't have set up.

Changelog entry

Fix token refresh never running when enabled — ensure_tokens_still_fresh hook moved to priority 11 so it isn't dropped while the priority-10 init queue is executing.

(full disclosure, I used AI help with the testing and tweaks - Christopher)

This hook is registered inside the plugin's own init callback, which
runs at priority 10. WordPress does not enqueue callbacks added to a
priority that is currently executing, so ensure_tokens_still_fresh
was silently never called when token refresh was enabled.

Using priority 11 means it lands in the next batch WordPress processes,
after the current priority-10 queue drains.

Fixes oidc-wp#675
Copilot AI review requested due to automatic review settings May 29, 2026 19:44

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adjusts the execution order of token refresh logic during WordPress initialization to run after default init handlers.

Changes:

  • Sets an explicit init hook priority for ensure_tokens_still_fresh (priority 11) when token refresh is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Per Copilot review: the magic number 11 is not obvious without context.
Adds an inline comment clarifying that priority 11 ensures this runs
after default-priority (10) init callbacks so session and auth state
are fully initialised before token freshness is checked.
@carantunes

Copy link
Copy Markdown

@daggerhart would be great if you could merge this! We need token refresh at CERN :)

@daggerhart daggerhart left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great, thanks for the help!

@daggerhart
daggerhart merged commit 49af86b into oidc-wp:develop Nov 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ensure_tokens_still_fresh never gets called because of init hook priority

4 participants