Fix paypal commerce test mode checkbox not working when paypal addon is active#3156
Conversation
📝 WalkthroughWalkthroughFixes PayPal ChangesPayPal test_mode preservation fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| PHP | Jun 18, 2026 1:52p.m. | Review ↗ | |
| JavaScript | Jun 18, 2026 1:52p.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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@paypal/controllers/FrmPayPalLiteSettingsController.php`:
- Around line 68-78: The preserve_test_mode_on_update function is currently
hooked to the update_option_frm_paypal_options action and calls update_option
inside the callback, which causes the hook to fire again and creates duplicate
writes. Move this logic to use the pre_update_option_frm_paypal_options filter
instead, which executes before the option is written. Remove the update_option
call since the filter can directly modify and return the new_value parameter,
allowing the preservation to happen in a single update operation without
re-triggering the hook.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7b106f8d-5138-4b32-979b-cdef354e51fd
📒 Files selected for processing (4)
paypal/controllers/FrmPayPalLiteHooksController.phppaypal/controllers/FrmPayPalLiteSettingsController.phppaypal/models/FrmPayPalLiteSettings.phppaypal/views/settings/connect-settings-container.php
| public static function preserve_test_mode_on_update( $old_value, $new_value ) { | ||
| if ( ! is_object( $old_value ) || ! is_object( $new_value ) ) { | ||
| return; | ||
| } | ||
|
|
||
| // If old value had test_mode but new value doesn't, preserve it | ||
| if ( isset( $old_value->test_mode ) && ! isset( $new_value->test_mode ) ) { | ||
| $new_value->test_mode = $old_value->test_mode; | ||
| // Update the option with the preserved test_mode | ||
| update_option( 'frm_paypal_options', $new_value ); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify current re-entrant pattern:
# 1) Callback is attached to update_option_frm_paypal_options
# 2) Callback itself calls update_option('frm_paypal_options', ...)
rg -n --type=php -C3 "update_option_frm_paypal_options|preserve_test_mode_on_update|update_option\s*\(\s*'frm_paypal_options'" paypal/controllersRepository: Strategy11/formidable-forms
Length of output: 1961
Avoid re-writing the same option inside its update_option_* callback.
Line 80 triggers a second update_option() from inside the update_option_frm_paypal_options action. This causes an extra write and re-fires option-update hooks, which can duplicate downstream side effects.
🔧 Suggested fix (move preservation to pre-update filter)
diff --git a/paypal/controllers/FrmPayPalLiteSettingsController.php b/paypal/controllers/FrmPayPalLiteSettingsController.php
@@
- /**
- * Preserve test_mode when the PayPal add-on updates frm_paypal_options.
- * This hooks into update_option to ensure test_mode isn't lost.
- *
- * `@param` mixed $old_value The old option value.
- * `@param` mixed $new_value The new option value.
- *
- * `@return` void
- */
- public static function preserve_test_mode_on_update( $old_value, $new_value ) {
- if ( ! is_object( $old_value ) || ! is_object( $new_value ) ) {
- return;
- }
-
- // If old value had test_mode but new value doesn't, preserve it
- if ( isset( $old_value->test_mode ) && ! isset( $new_value->test_mode ) ) {
- $new_value->test_mode = $old_value->test_mode;
- // Update the option with the preserved test_mode
- update_option( 'frm_paypal_options', $new_value );
- }
- }
+ /**
+ * Preserve test_mode before frm_paypal_options is persisted.
+ *
+ * `@param` mixed $new_value The incoming option value.
+ * `@param` mixed $old_value The currently stored option value.
+ *
+ * `@return` mixed
+ */
+ public static function preserve_test_mode_on_update( $new_value, $old_value ) {
+ if ( is_object( $old_value ) && is_object( $new_value ) && isset( $old_value->test_mode ) && ! isset( $new_value->test_mode ) ) {
+ $new_value->test_mode = $old_value->test_mode;
+ }
+
+ return $new_value;
+ }
diff --git a/paypal/controllers/FrmPayPalLiteHooksController.php b/paypal/controllers/FrmPayPalLiteHooksController.php
@@
- add_action( 'update_option_frm_paypal_options', 'FrmPayPalLiteSettingsController::preserve_test_mode_on_update', 10, 2 );
+ add_filter( 'pre_update_option_frm_paypal_options', 'FrmPayPalLiteSettingsController::preserve_test_mode_on_update', 10, 2 );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@paypal/controllers/FrmPayPalLiteSettingsController.php` around lines 68 - 78,
The preserve_test_mode_on_update function is currently hooked to the
update_option_frm_paypal_options action and calls update_option inside the
callback, which causes the hook to fire again and creates duplicate writes. Move
this logic to use the pre_update_option_frm_paypal_options filter instead, which
executes before the option is written. Remove the update_option call since the
filter can directly modify and return the new_value parameter, allowing the
preservation to happen in a single update operation without re-triggering the
hook.
Related ticket https://secure.helpscout.net/conversation/3359590190/253804
Pre-release
formidable-6.32.1b.zip
Summary by CodeRabbit