Skip to content

feat: use the modern dashboard API for connect, cache tokens, extra visits and metadata sync - #1143

Draft
selul wants to merge 2 commits into
developmentfrom
feat/modern-dashboard-api
Draft

feat: use the modern dashboard API for connect, cache tokens, extra visits and metadata sync#1143
selul wants to merge 2 commits into
developmentfrom
feat/modern-dashboard-api

Conversation

@selul

@selul selul commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The plugin talks to the dashboard through legacy optml/v2 and optml/v1 routes that Optimole is retiring. This PR moves five of its calls to the modern /api/* endpoints added in optimole-service #1789 and removes a dead client method.

Note

Depends on optimole-service #1789 being deployed to production first. Until then the five modern calls below return 404 against production, so this PR stays a draft. Set OPTIML_API_ROOT to the staging dashboard to test it before that deploy. Installed plugin versions are not affected either way: #1789 also serves the legacy paths from the same actions, so the switch here is about calling the modern contract directly, not about keeping old installs working.

What changed

  • ConnectOptml_Api::connect() posts to POST /api/integrations/wordpress/connections with the site URL and the sample image, then shapes the answer into the app_count, extra_visits and available_apps payload the connect screen already consumes. The domain_not_accessible error keeps the plugin's own translated message with the docs link.

  • Clear cacheget_cache_token() posts to POST /api/cache-tokens. The 5-minute local throttle is unchanged; the legacy route ignored the token and type parameters the plugin sent, so nothing is lost by dropping them.

  • Banner extra visitsupdate_extra_visits() sends PUT /api/application/extra-visits with {"enabled": bool}.

  • Alt and title synccall_data_enrich_api() sends PATCH /api/assets with one entry per image URL, in chunks of 100, and trims values to the 255 characters the endpoint accepts. Images that were never offloaded are ignored by the dashboard, so a full media library sync no longer needs the server-side URL lookup the legacy route did.

  • Account contextget_user_data() posts to POST /api/integrations/wordpress/context with the site URL and receives the same flat payload the plugin already stores as service_data. A refused key (401/403) or a whitelist_limit_reached error still yields the disconnect signal the admin screen acts on.

  • API client — new private modern_request() handles the modern envelope: the resource comes back directly, failures arrive as HTTP errors with a message and an optional code, which becomes the WP_Error code. The legacy request() stays for complete_register_remote, v1/stats/images and logs.

  • Removedget_cloud_images() had no caller since the DAM replaced the cloud images modal. Its PHPStan baseline entries go with it.

Calls after this PR

Plugin method Endpoint Layer
connect() POST /api/integrations/wordpress/connections modern
get_cache_token() POST /api/cache-tokens modern
update_extra_visits() PUT /api/application/extra-visits modern
call_data_enrich_api() PATCH /api/assets modern
get_user_data() POST /api/integrations/wordpress/context modern
create_account() POST /api/optml/v2/account/complete_register_remote legacy
get_optimized_images() GET /api/optml/v1/stats/images legacy
send_log() POST /api/optml/v2/logs legacy

QA

Run these on a site whose wp-config.php defines OPTIML_API_ROOT as https://staging-dashboard.optimole.com/api/, with an API key from a staging account.

  1. Go to WP Admin → Media → Optimole, paste the API key and click Connect to Optimole.

    Expect: the dashboard widget loads with plan and quota, and the site appears under Whitelist in the staging dashboard. On an account with two active custom domains, the domain picker appears first.

  2. Connect with a key from a free staging account for a domain that sits on a trashed application of another free account.

    Expect: the connect screen shows the "previously connected to an Optimole account that is now disabled" message and no key is stored.

  3. Go to WP Admin → Media → Optimole → Settings → General and click Clear cached images.

    Expect: a success notice, and a second click within five minutes shows the "once per 5 minutes" throttle message.

  4. Go to WP Admin → Media → Optimole → Settings → General, turn on the Badge settings toggle (the Optimole badge that grants extra visits), save, then reload the settings page.

    Expect: the toggle stays on, and POST /api/optml/v2/account/details for that key returns "extra_visits":true right away.

  5. Offload one image, set its alt text in Media → Library, and wait for the next metadata sync cron run (or trigger wp cron event run optml_pull_image_data).

    Expect: the image in the staging dashboard library shows the new alt text.

🤖 Generated with Claude Code

…isits and metadata sync

The dashboard is retiring its legacy optml/v2 and optml/v1 routes. Four of
the plugin's calls now use the modern /api endpoints added in
optimole-service #1789:

- connect() posts to /api/integrations/wordpress/connections and shapes the
  answer into the app_count/extra_visits/available_apps payload the connect
  screen consumes; the domain_not_accessible error keeps the plugin's own
  translated message.
- get_cache_token() posts to /api/cache-tokens. The legacy route ignored the
  token and type parameters, so nothing is lost.
- update_extra_visits() sends PUT /api/application/extra-visits.
- call_data_enrich_api() sends PATCH /api/assets in chunks of 100, trimming
  values to the 255 characters the endpoint accepts.

A private modern_request() handles the modern envelope: resources come back
directly and failures are HTTP errors carrying a message and an optional code,
which becomes the WP_Error code. The legacy request() stays for the routes
that have no modern equivalent yet.

get_cloud_images() is removed; nothing has called it since the DAM replaced
the cloud images modal.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@pirate-bot

pirate-bot commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

🌍 i18n String Review Report

📊 Summary

Category Count
➕ Added 1
➖ Removed 0
🔄 Changed 0
Total 1
➕ Added Strings (1) - Click to expand
String Location Words Suggested Match
Unexpected response from the Optimole service ... inc/api.php:387 8 Something went wrong. Please refresh the page and try again.
Total 8

get_user_data() posts to /api/integrations/wordpress/context, which returns
the same flat payload the plugin stores as service_data. A refused key or a
whitelist_limit_reached error still yields the "disconnect" signal the admin
screen acts on; the CLI and REST callers now treat that signal as a failed
connection instead of storing it as service data.

modern_request() carries the HTTP status in the WP_Error data so callers
can tell a refused key from a validation problem.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

2 participants