Skip to content

fix(figma): reach the WordPress REST API on plain-permalink sites - #25

Open
DavidBabinec wants to merge 1 commit into
mainfrom
fix/figma-plain-permalinks
Open

fix(figma): reach the WordPress REST API on plain-permalink sites#25
DavidBabinec wants to merge 1 commit into
mainfrom
fix/figma-plain-permalinks

Conversation

@DavidBabinec

Copy link
Copy Markdown
Contributor

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

bun run --filter './packages/figma' test   # 18 pass (11 new), 0 fail
bun run build:figma                         # clean (tsc typecheck)

Ran the real fetchWordPressRest against 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.

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

[Bug]: Figma Plugin : Failed to import project [Bug]: Figma Plugin: Invalid WordPress connection key

1 participant