Repository navigation
fix: do not build polled image URLs before the SDK is initialized - #1172
Merged
Merged
Conversation
poll_optimized_images() turned the API's list into image URLs through the Optimole SDK, which is only initialized for a connected site. On a site without a CDN key and secret it threw "Please initialize the Optimole SDK first". It now returns an empty list there, without calling the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
pirate-bot
requested changes
Oct 11, 2026
Collaborator
There was a problem hiding this comment.
🟡 Changes requested
The guard fixes the reported SDK exception, but the new test needs return types on its method and mock closure.
Validation details
- Files reviewed: 2/2 changed files.
- I ran
sandbox-phpunit-ab.sh /repo pr-base --filter 'Test_Poll_Optimized_Images::'on PHP 8.3 with the WP 7.1.3 test library. HEAD passed 7 tests. Withinc/rest.phpfrompr-base, the new test raisedPlease initialize the Optimole SDK first.The harness kept no run record. The log is at/workspace/checks/C4/ab.log. - A source trace showed that
is_connected()matches the condition that initializes the SDK. - The route still requires
manage_options. The guard reads only saved settings.
Untested areas
- I did not check the dashboard empty state in a browser.
- One path is still unverified. It needs
OPTIML_USE_ENVauto-connect in the same request as the poll, andOPTIML_IMAGE_REPLACER=off. The same path exists on the base branch.
🤖 Automated review · run code-review-agent_6acb86a0160da0.99750732.
🤖 Review agent — review posted ✅ on 2ca97714 · changes requested · 1 finding · 18 min
Run code-review-agent_6acb86a0160da0.99750732 · trail
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pirate-bot
approved these changes
Oct 11, 2026
Collaborator
There was a problem hiding this comment.
🟢 Approved
The PR passes. The earlier types finding is fixed, and the new commit changes only test types.
Validation details
- Files reviewed: 2/2 changed files.
- I read the diff since
2ca97714. It adds: void,: arrayand a shape docblock to the new test. cd /repo; sandbox-env-record.sh 2>&1 | tail -20; php -l tests/test-poll-optimized-images.php; sed -n 180,232p tests/test…printedNo syntax errors detected in tests/test-poll-optimized-images.php(run R1)- I ran
sandbox-phpunit-ab.sh /repo pr-base --filter 'Test_Poll_Optimized_Images::'on PHP 8.3. The harness kept no run record. The log is at/workspace/checks/C1/ab2.log. - Security and standards checks on
inc/rest.phpcome from run code-review-agent_6acb86a0160da0.99750732 on2ca97714, not rerun. That file is unchanged since.
Untested areas
- I did not check the dashboard empty state in a browser.
- Auto-connect through
OPTIML_USE_ENVin the same request as the poll is unverified. The same path exists on the base branch.
🤖 Automated review · run code-review-agent_6acb8db97578f1.59981029.
🤖 Review agent — review posted ✅ on dd5dcd13 · approved · 0 findings · 2 min
Run code-review-agent_6acb8db97578f1.59981029 · trail
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.
Related issue: #1162
The "Last optimized images" poll turned the API's list into image URLs through the Optimole SDK, which is only initialized for a connected site. On a site without a CDN key and secret it threw
Please initialize the Optimole SDK first.It now returns an empty list there, without calling the API.What changed
Optml_Rest::poll_optimized_images()— returns an empty list whenOptml_Settings::is_connected()is false, before the API call. Connected sites behave as before.Note
The dashboard already handles an empty list (the same response as an API error or an empty account), so the box shows its empty state.
Tests
tests/test-poll-optimized-images.php: with noservice_data, polling returnssuccesswith an empty list and sends no request, even when the API would return images. The test fails ondevelopment(the SDK exception).QA
On a site where Optimole is not connected (no API key, or disconnected), open
WP Admin → Optimoleand check the browser console and PHP error log while the dashboard loads.Expect: no
Please initialize the Optimole SDK firsterror.On a connected site, open the dashboard.
Expect: the "Last optimized images" box shows images as before.
Verification (head
dd5dcd13)tests/test-poll-optimized-images.phprun alonedevelopmentsourcephpcs,phpstan(build-only include errors excluded locally; CI builds assets first)dd5dcd13(PHPUnit on PHP 8.0–8.3, PHPStan, phpcs, ESLint, Jest, e2e, build)2ca97714and the follow-up ondd5dcd132ca97714): changes requested, return types on the new test and its mock closure (fixed). Round 2 (dd5dcd13): approved🤖 Generated with Claude Code