Skip to content

Connect: get the key back automatically when MonoRanks can't reach the site - #23

Merged
mostafasoufi merged 8 commits into
mainfrom
connect-handoff
Oct 17, 2026
Merged

mostafasoufi merged 8 commits into
mainfrom
connect-handoff

Conversation

@mostafasoufi

@mostafasoufi mostafasoufi commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

What

The Connect button did nothing useful for sites MonoRanks cannot reach (local .test sites, firewalled sites). MonoRanks showed a key to copy, and the plugin stayed "Not connected".

Now the plugin gets the key back by itself:

  • Settings::connect_url() adds &state=<40 hex chars>. The state is stored per user in a transient (monoranks_connect_<user id>, 30 minutes) together with the MonoRanks address the link points at. It is reused while it lives, so two tabs show the same link.
  • New Handoff class, run on admin_init. When MonoRanks → Settings opens with monoranks_code and monoranks_state:
    • It needs manage_options.
    • It checks the state with hash_equals against the user's stored state, then deletes it.
    • It sends wp_remote_post {base}/api/wordpress/claim with {code, site: untrailingslashit(home_url('/'))}.
    • It checks the key with Connection::valid_key.
    • It connects through Actions::use_key(..., 'pairing', site_id), the same steps as a pasted key with via set to pairing: send status, start the first sync, refresh insights.
    • It redirects to the clean settings URL with the existing notice: "connected" on success, or the new "Could not connect. Please try again." on failure.
  • Actions::connect_key now goes through the shared use_key. Its behaviour is unchanged.
  • uninstall.php also clears the connect-state transients.
  • Persian translation added and .pot/.po/.mo rebuilt with bin/i18n.sh.

No version bump, no readme.txt change.

App side: monoranks/monoranks#256.

Tests

vendor/bin/phpunit: 101 tests, all passing. New HandoffTest: good state, bad state, another user's state, failed claim, bad key in the answer, bad code, no manage_options, other admin page. SettingsTest gains a test that the link carries and reuses the state.

Also: a simpler Settings page

Rows are short now, and the details sit behind an (i) tooltip. The tooltip is a new small component (resources/admin/src/components/ui/tip.tsx) that opens on hover and on keyboard focus, and Escape closes it.

Settings, Connection card

  • The Status row is gone. Its sentence is now the tooltip on the Connected (or Key revoked) chip.
  • Connector key: only the key shows; "set when … connected" is in a tooltip.
  • Last sync: shows "20 seconds ago"; the full date is in a tooltip. New last_sent_short and last_sent_date fields, from Admin::ago_short() and Admin::date_of().
  • Fixes written with: "App password", a tooltip and a "Revoke" link.
  • Works with: the chip and a tooltip.
  • Disconnect: its note is now a tooltip on the button.

Rest of the Settings page

  • The page subtitle is gone.
  • "What is sent" is a collapsed section; the rows show after a click.
  • "Use a different key": the long instructions are cut to one tooltip next to the key label.
  • Danger zone: the paragraph is cut to one short tooltip.

Overview

  • The tagline is gone when the site is not connected.
  • The text under step 2 is a tooltip, and the text under step 3 is removed.
  • "Audit results" shows a short status with the details in a tooltip.
  • The "Ready to apply" note and the "Needs review" paragraph are now tooltips.

The .pot, fa_IR .po/.mo and the admin JSON are rebuilt, and the admin bundle is rebuilt. PHPUnit: 102 tests pass. The Playwright spec needs wp-env (Docker), which was not available.

…t reach the site

The connect link now carries a per-user state (30 minutes). When MonoRanks cannot
reach the site, it sends the person back to Settings with a one-time code and that
state; the plugin checks the state and trades the code for the key directly.
Connection card: the status sentence moves to the Connected chip, the key's origin,
the full sync date, the app password and SEO plugin notes and the Disconnect note
move behind (i) tooltips. What is sent is a collapsed section. The page subtitle
is gone. Overview: long step, note and status lines become tooltips.
@mostafasoufi
mostafasoufi merged commit 8ceb95d into main Oct 17, 2026
11 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.

1 participant