Skip to content

Fixed: Plugin Token reported as invalid on WPML sites with a directory per language - #335

Merged
Dan0sz merged 1 commit into
developfrom
fix_multilang_home_url_domain
Oct 20, 2026
Merged

Dan0sz merged 1 commit into
developfrom
fix_multilang_home_url_domain

Conversation

@Dan0sz

@Dan0sz Dan0sz commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

A customer using WPML (a directory per language) got "Oops! The Plugin Token you used is invalid" during setup, even with a freshly created token.

Cause

When no Domain Name is saved yet, Helpers::get_domain() falls back to home_url(), stripping only the scheme and www.. WPML filters home_url() to include the current language's directory, e.g. https://www.example.com/fr. The Domain Name field gets pre-filled with example.com/fr and saved like that, so Client::validate_api_token() never matches the token's domain (example.com) and reports the token as invalid.

Fix

The fallback now uses the unfiltered get_option( 'home' ). Multilingual plugins hook into the home_url filter, so their language directory no longer ends up in the domain. Subdirectory installs (e.g. example.com/blog) behave exactly as before.

Sites that already saved example.com/fr aren't fixed automatically; correcting the Domain Name in the settings resolves it there.

Tests

  • New testGetDomainIgnoresLanguageDirectoryInHomeUrl: filters home_url to append /fr and checks the domain doesn't contain it.
  • The rest of the suite is unchanged; the two AssetsTest errors I get locally also occur on a clean develop.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Domain Name detection for multilingual sites using per-language directories.
    • Prevented language directory paths from being incorrectly included in the Domain Name, which could cause the Plugin Token to appear invalid.
  • Documentation

    • Added a changelog entry describing the multilingual Domain Name and Plugin Token fix.

Multilingual plugins like WPML (directory per language) filter home_url() to include the current language's directory (e.g. example.com/fr). That ended up in the pre-filled Domain Name, so the Plugin Token never matched the site's domain and was reported as invalid.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bdb6e154-b768-4200-85cb-7c415a7dedb8
📥 Commits

Reviewing files that changed from the base of the PR and between eb97dbd and 8f138bd.

📒 Files selected for processing: 3
  • readme.txt
  • src/Helpers.php
  • tests/integration/HelpersTest.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Helpers::get_domain() now derives its fallback domain from the WordPress home option. An integration test verifies that a language directory added to home_url() does not appear in the normalized domain. The changelog records this correction.

Changes: Multilingual domain fallback

Layer / File(s) Summary
Fallback behavior and validation
src/Helpers.php, tests/integration/HelpersTest.php, readme.txt
Helpers::get_domain() uses the home option instead of home_url() for its fallback URL. The integration test checks that a /fr directory added by a filter is excluded from the normalized domain. The 2.6.4 changelog describes the correction.

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 8f138

The change is ready to merge; no correctness, security, or availability issue was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and specifically describes the main fix for invalid Plugin Tokens on WPML sites that use language directories.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Dan0sz
Dan0sz merged commit d98a268 into develop Oct 20, 2026
7 checks passed
@Dan0sz
Dan0sz deleted the fix_multilang_home_url_domain branch October 20, 2026 09:26
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.

1 participant