fix(figma): reach the WordPress REST API on plain-permalink sites - #25
Open
DavidBabinec wants to merge 1 commit into
Open
fix(figma): reach the WordPress REST API on plain-permalink sites#25DavidBabinec wants to merge 1 commit into
DavidBabinec wants to merge 1 commit into
Conversation
The plugin only called the /wp-json/ REST path, which WordPress does not route until pretty permalinks are enabled. On the default Plain setting the request 301-redirected away before it reached the plugin, so connecting a project failed with "Invalid WordPress connection key" or "Failed to import project". All plugin REST calls now fall back to the permalink-independent ?rest_route= form, and connect errors report whether the site was unreachable, rejected the key, or returned an error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12
Fixes #18
The bug
Connecting a WordPress project from the Figma plugin failed with "Invalid WordPress connection key" or "Failed to import project" on sites left on the default "Plain" permalink setting, which is what fresh WordPress and instant test sites (TasteWP and similar) use.
The fix
The plugin only ever called the
/wp-json/REST path, which WordPress does not route until pretty permalinks are enabled, so the request 301-redirected away before it reached the plugin. Every plugin REST call (connect and push) now tries/wp-json/and falls back to the permalink-independent?rest_route=form, which WordPress serves on any setting. Connect failures now report whether the site was unreachable, rejected the key, or returned an error, instead of one generic message. The request allowlist is unchanged in effect: it matches the REST route regardless of URL form.Verification
Ran the real
fetchWordPressRestagainst a live dockerized WordPress: Plain permalinks now connect (200), Pretty still connect (200), a wrong key is still rejected (401). The new tests fail without the fallback.