Repository navigation
Warn when the Stripe connection belongs to a different site URL - #3737
Crabcyborg wants to merge 9 commits into
Conversation
Save the site URL when Stripe is connected and compare it to the current site URL on the Stripe settings page. When they differ, show an error suggesting the user disconnect and reconnect, since this usually means the database was copied from another site. A trailing slash difference is ignored. Connections made before this change save the current URL the first time the settings load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 28 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| PHP | Dec 1, 2026 7:04p.m. | Review ↗ | |
| JavaScript | Dec 1, 2026 7:04p.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
There was a problem hiding this comment.
Approve. The warning works as described, and I found nothing blocking. Two non-blocking notes are inline.
Live check (PR branch loaded in the preview env, head 4cd13f020092e5e2352672a09de8922893025231): I seeded test mode with an account ID and a saved URL of old-site.example.com, and live mode as a pre-upgrade connection with no saved URL.
- Test mode shows the red warning naming both URLs. This holds in both the "Finish Stripe Setup" and "Connected" states:


(The round icon at the right edge of the second image is the Formidable floating widget, not part of this PR.)
- The live-mode connection with no saved URL shows no warning. Its option was filled with
127.0.0.1on that first view, as the code intends. - Both URLs are
esc_html-escaped, and the markup renders as intended.
Read-only, not exercised live: the Disconnect AJAX path (it calls the real connect server). reset_stripe_connect_integration() and the uninstall key list both delete site_url, and I confirmed that from the source. account_id is written in one place only (check_server_for_oauth_account_id), and that is where the URL gets saved. connect.php is included only from render_settings(), so the new view variables are always set. php -l is clean on all three changed files.
CI: PHPUnit, PHPCS, PHPStan and the other test jobs are marked skipped on this head, so none of them ran. I did not run them locally either. Psalm, typos, CodeRabbit and DeepSource pass.
Tests run: none. This PR adds no tests, and the live check above was manual.
| $connected_url = get_option( self::get_site_url_option_name( $mode ) ); | ||
|
|
||
| if ( ! $connected_url || ! is_string( $connected_url ) ) { | ||
| // Connections made before the site URL was tracked have nothing saved yet. |
There was a problem hiding this comment.
Non-blocking: sites that were already connected before this release can't be caught reliably. A connection with no saved URL gets the current URL written the first time an admin opens the Stripe settings tab. If the database was copied before that first view, and the copy's admin opens the settings first, the copy records its own URL as the original and never warns.
Moving the backfill into the plugin's upgrade routine would close most of that gap, because it would run on every site at update time instead of on a rarely visited tab. It would also stop get_mismatched_site_url(), which reads like a getter, from writing to the database during a page render.
If you keep the first-view backfill, say in the docblock that it is best-effort for pre-existing connections.
| * | ||
| * @return false|string The site URL the account was connected on, or false when it matches. A trailing slash (WPML can add one) is ignored. | ||
| */ | ||
| public static function get_mismatched_site_url( $mode ) { |
There was a problem hiding this comment.
Non-blocking: this adds no PHPUnit coverage. The logic is plain option handling, so it is cheap to test. tests/phpunit/stripe/ has no test for FrmStrpLiteConnectHelper yet. Worth covering in get_mismatched_site_url():
- no account ID returns
false; - no saved URL returns
falseand saves the current URL (the backfill); - a matching URL returns
false, including when one side has a trailing slash; - a different URL returns the saved one;
reset_stripe_connect_integration()deletes thesite_urloption;FrmStrpLiteAppController::uninstall()deletesfrm_strp_connect_site_url_testand_live.
Move the backfill for connections made before the site URL was tracked out of get_mismatched_site_url() and into a new db migration (108), so every site records its own URL when it updates instead of the first time an admin opens the Stripe settings. The getter no longer writes to the database during a page render. Add PHPUnit coverage for get_mismatched_site_url(), the backfill, the trailing slash handling, and the site_url cleanup on disconnect and uninstall. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Approve. Re-review at 6a37eea (my Approve was at 4cd13f0). The new commit closes both earlier notes: a migrate_to_108 upgrade routine backfills the site URL for existing connections, and the PR now adds tests. One non-blocking note is inline.
Live check (PR loaded in the preview env, head 6a37eea0f): I seeded test mode with an account ID and no saved URL, live mode with an account ID and saved URL old-site.example.com, and set frm_db_version to 7.1.1-107. Then I ran the real FrmAppController::install() upgrade.
frm_db_versionmoved to7.1.1-108. Test mode gotsite_url = '127.0.0.1'(backfilled). Live mode keptold-site.example.com(not overwritten).- Global Settings > Stripe: test mode shows no warning, live mode shows the mismatch warning naming both URLs:

(The round icon at the right edge is the Formidable floating widget, not part of this PR.)
Tests run: test_FrmStrpLiteConnectHelper.php at 6a37eea0f in the wordpress-develop harness (PHP 8.4) → OK (7 tests, 16 assertions); test_FrmMigrate.php --filter test_migrate_to_108 → OK (1 test, 2 assertions). CI's PHPUnit job is skipped on this head, so these did not run anywhere else. Mutations that each make a test fail: dropping the site_url delete in reset_stripe_connect_integration(), dropping the untrailingslashit() comparison, dropping 108 from the $migrations list, dropping site_url from the uninstall key list.
Not exercised: the Disconnect AJAX path (it calls the real connect server; the delete is covered by the unit test), a real Stripe OAuth connect, multisite upgrade. PHPCS was not run. php -l is clean on the changed files.
|
|
||
| if ( is_object( $data ) && ! empty( $data->account_id ) ) { | ||
| update_option( self::get_account_id_option_name( $mode ), $data->account_id, false ); | ||
| self::save_connected_site_url( $mode ); |
There was a problem hiding this comment.
Non-blocking: this line is the only place a new connection gets its saved URL, and no test covers it. Deleting it leaves all 7 new tests green, so a regression here would silently turn off the warning for every new connection. check_server_for_oauth_account_id() calls post_to_connect_server(), so a test needs that stubbed, for example with a pre_http_request filter returning an oauth_account_status response with an account_id, then asserting frm_strp_connect_site_url_test equals get_site_url_for_connect_server().
Stub the connect server's oauth_account_status response and check that check_server_for_oauth_account_id() saves the current site URL along with the account ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Approve. Re-review at f47ec2b (my last Approve was at 6a37eea). The only new commit adds test_check_server_for_oauth_account_id_saves_site_url, which closes my earlier note that the save_connected_site_url call in check_server_for_oauth_account_id had no test. Source is unchanged since 6a37eea, so the live check from that round still holds.
The new test mocks the connect server's oauth_account_status reply through pre_http_request, then asserts the account ID and the current site URL are both saved for the mode.
Tests run: test_FrmStrpLiteConnectHelper.php at f47ec2bfa in the wordpress-develop harness (PHP 8.4) → OK (8 tests, 19 assertions). Mutation: commenting out the save_connected_site_url( $mode ) call in check_server_for_oauth_account_id makes the new test fail (the only failure). test_migrate_to_108 → OK (1 test, 2 assertions). CI's PHPUnit job is skipped on this head, so these ran nowhere else.
Not exercised: the Disconnect AJAX path and a real Stripe OAuth connect (both call the real connect server). PHPCS was not run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Saves the site URL when Stripe is connected and compares it to the current site URL on the Stripe settings page. When they don't match, an error under that mode's connection status suggests disconnecting and reconnecting. This usually happens when a database is copied from one site to another, so the copy is still using the original site's Stripe connection.
This lives in Lite, so it works with or without the Stripe add-on. The add-on uses Lite's settings view for the connection status.
Details
frm_strp_connect_site_url_{mode}, using the same normalized URL the connect server already gets (no protocol, port, or WPML language suffix). Switching between http and https does not trigger the warning.build_headers_for_post()moved into its own method. The Authorization header it sends is unchanged.Testing
frm_strp_connect_site_url_testto another domain, for examplewp option update frm_strp_connect_site_url_test old-site.com. Reload the settings. An error shows under TEST naming both URLs, and LIVE is unaffected.frm_db_versionback to107(keep the plugin version prefix) and load any admin page. The migration saves the current URL to the option.PHPUnit:
tests/phpunit/stripe/test_FrmStrpLiteConnectHelper.phpandtest_FrmMigrate::test_migrate_to_108.🤖 Generated with Claude Code
Summary by CodeRabbit