feat: use the modern dashboard API for connect, cache tokens, extra visits and metadata sync - #1143
Draft
selul wants to merge 2 commits into
Draft
feat: use the modern dashboard API for connect, cache tokens, extra visits and metadata sync#1143selul wants to merge 2 commits into
selul wants to merge 2 commits into
Conversation
…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>
Collaborator
🌍 i18n String Review Report📊 Summary
➕ Added Strings (1) - Click to expand
|
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>
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.
The plugin talks to the dashboard through legacy
optml/v2andoptml/v1routes 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_ROOTto 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
Connect —
Optml_Api::connect()posts toPOST /api/integrations/wordpress/connectionswith the site URL and the sample image, then shapes the answer into theapp_count,extra_visitsandavailable_appspayload the connect screen already consumes. Thedomain_not_accessibleerror keeps the plugin's own translated message with the docs link.Clear cache —
get_cache_token()posts toPOST /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 visits —
update_extra_visits()sendsPUT /api/application/extra-visitswith{"enabled": bool}.Alt and title sync —
call_data_enrich_api()sendsPATCH /api/assetswith 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 context —
get_user_data()posts toPOST /api/integrations/wordpress/contextwith the site URL and receives the same flat payload the plugin already stores asservice_data. A refused key (401/403) or awhitelist_limit_reachederror still yields thedisconnectsignal 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 amessageand an optionalcode, which becomes theWP_Errorcode. The legacyrequest()stays forcomplete_register_remote,v1/stats/imagesandlogs.Removed —
get_cloud_images()had no caller since the DAM replaced the cloud images modal. Its PHPStan baseline entries go with it.Calls after this PR
connect()POST /api/integrations/wordpress/connectionsget_cache_token()POST /api/cache-tokensupdate_extra_visits()PUT /api/application/extra-visitscall_data_enrich_api()PATCH /api/assetsget_user_data()POST /api/integrations/wordpress/contextcreate_account()POST /api/optml/v2/account/complete_register_remoteget_optimized_images()GET /api/optml/v1/stats/imagessend_log()POST /api/optml/v2/logsQA
Run these on a site whose
wp-config.phpdefinesOPTIML_API_ROOTashttps://staging-dashboard.optimole.com/api/, with an API key from a staging account.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
Whitelistin the staging dashboard. On an account with two active custom domains, the domain picker appears first.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.
Go to
WP Admin → Media → Optimole → Settings → Generaland click Clear cached images.Expect: a success notice, and a second click within five minutes shows the "once per 5 minutes" throttle message.
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/detailsfor that key returns"extra_visits":trueright away.Offload one image, set its alt text in
Media → Library, and wait for the next metadata sync cron run (or triggerwp cron event run optml_pull_image_data).Expect: the image in the staging dashboard library shows the new alt text.
🤖 Generated with Claude Code