You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add generic entry storage and field protection APIs - #3665
Integrations need to prevent entry storage and protect required fields at the model layer, including direct calls and XML imports. Add generic storage and field protection APIs, and provide the form object to the final rendering filter so integrations can customize output for that form.
Add FrmEntry::allows_save() and frm_allow_entry_save. Honor the prevent_entry_storage form option for both the form and its parent. Reject blocked standard and XML creates and updates before persistence and associated actions. Updates also check the existing entry's form when the caller omits or changes the form ID.
Add frm_field_values_before_update so integrations can preserve field requirements before saving.
Add FrmField::can_destroy() and frm_can_destroy_field, enforced before deleting a field.
Pass the form object as the second argument to frm_filter_final_form. Existing callbacks accepting only HTML remain compatible.
Testing
Full Lite suite: 1,006 tests and 5,252 assertions, with no failures or errors. The run reports 99 PHPUnit notices, three skips, and three incomplete tests.
Registration account form regression suite with Pro active: 19 tests and 264 assertions pass. Bootstrap emits the Lite translation-loading notice.
New regression tests cover standard and XML write blocking, parent form storage policy, updates without a form ID, denied field deletion, field update values, and form context through the real shortcode.
Scoped PHP syntax, PHPCS, PHP-CS-Fixer, Rector, Mago lint, and typos checks pass. PHPCS uses the shared Formidable sniffs via a runtime path setting.
Plugin-wide Mago analysis exits successfully with two warnings in unchanged files. Psalm reports four errors in unchanged FrmAppHelper, FrmAddon, and FrmShowForm code.
We reviewed changes in ab4ee48...26f4b3b on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.
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.
$this->assertSame( 'Protected ' . $field_id, FrmField::getOne( $field_id )->name, 'The filtered values and field ID should be used before persistence.' );
$this->assertSame( 'Protected ' . $field_id, FrmField::getOne( $field_id )->name, 'The filtered values and field ID should be used before persistence.' );
$this->assertSame( 'Protected ' . $field_id, FrmField::getOne( $field_id )->name, 'The filtered values and field ID should be used before persistence.' );
$this->assertSame( 'Protected ' . $field_id, FrmField::getOne( $field_id )->name, 'The filtered values and field ID should be used before persistence.' );
Read the whole diff against current master. The model-layer guards are placed correctly: allows_save() runs before before_insert_entry_in_database() on create and before before_update_entry() on update, so a blocked write never reaches persistence or the after-create/update actions. The parent_form_id key matches what Pro actually passes for repeater child entries (FrmProEntry.php:193). frm_filter_final_form still works for one-argument callbacks, and $form_object is the same object get_form() is given.
Not run: CI skipped PHPUnit, PHPStan and PHPCS on this head, and there is no PHPUnit binary on my machine, so I did not run the 6 new tests. I read them, and php -l passes on the changed classes. I did not exercise any of it in a browser. The 1,006-test result is the author's own report.
Non-blocking notes:
frm_allow_entry_save gets a different $values shape on update. The docblock says "including the form ID", but a bare FrmEntry::update( $id, array( 'name' => ... ) ) passes no form_id. Then a second call passes only array( 'form_id' => $entry->form_id ). The filter never receives the entry ID, so an integration cannot tell which entry is being updated. Consider passing $id as a third argument, or documenting the two shapes.
FrmField::destroy() can now return false, but its callers ignore that. FrmFieldsController::destroy() (the AJAX delete) ends in wp_die() either way, so the builder will drop the field from the UI while the server kept it until reload. FrmFormsController.php:381 and FrmXMLHelper::delete_removed_fields() also carry on after a denied delete. This is fine for the registration use case, but it is worth a follow-up so a denied delete shows an error.
allows_save() runs before the frm_pre_create_entry filter, so a callback on that filter that changes form_id is not re-checked. This is an edge case, and only worth a comment.
Tests: there is no case where the filter is allowed and the entry is saved with an extra arg. There is also no test that a repeater child entry carrying parent_form_id from Pro is blocked. The parent case is covered only with a hand-built $values.
…etes
frm_allow_entry_save now receives the entry ID as a third argument, 0
for new entries. Updates check one set of values that always includes
the form ID, and check the entry's original form too when it moves.
A field delete denied by frm_can_destroy_field now returns a 403 JSON
error from the AJAX handler, and the builder shows the message and
keeps the field instead of removing it from the page.
Adds tests for an allowing three argument filter, a repeater child
entry in the shape Pro builds, and the denied AJAX delete.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frm_allow_entry_save values shape: the filter now gets the entry ID as a third argument (0 for new entries). Updates go through a new allows_update() check that always adds the entry's form ID when the values have none, so callbacks see one shape. The entry's original form is also checked when an update moves the entry to another form. The docblocks list both shapes.
Denied field deletes: FrmFieldsController::destroy() now returns a 403 wp_send_json_error() with a message when frm_can_destroy_field denies the delete. The builder's deleteField() shows that message in the info modal and leaves the field in place. js/formidable_admin.js has the same change. The GDPR toggle in FrmFormsController and FrmXMLHelper::delete_removed_fields() still keep the field without a message. In both cases keeping the field is what the integration asked for, and neither flow has a place to show a per-field error, so I left them alone.
frm_pre_create_entry not checked again: documented on allows_save(), as suggested.
Tests: added test_allowing_filter_receives_entry_id_and_saves (a three-argument filter that allows the save, checks the entry ID and the added form ID on update), test_storage_option_blocks_repeater_child_entry_values (values in the exact shape FrmProEntry builds for a repeater child), and test_denied_delete_returns_error for the AJAX handler.
Tests: test_FrmFieldsAjax|test_FrmIntegrationGuards|test_FrmEntry OK (36 tests, 246 assertions). phpcs, php-cs-fixer, rector and mago are clean on the changed files. phpstan shows only the existing line 300 notice. ESLint has no new warnings.
Note on the bundle: a local webpack build reorders hundreds of unrelated modules even on unchanged source, so it does not reproduce the committed bundle. So I added the one error callback to js/formidable_admin.js by hand, matching what the build emits, and checked that the bundle parses and that the minified infoModal is in scope. The next full build will produce the same code.
I read the whole diff again against current master, not just the new commit. Both notes from my last review are addressed: frm_allow_entry_save now receives the entry ID, and a denied field delete now returns an error that the builder shows. I found no blocking problem.
Tests run (head 6b901b5, local WordPress PHPUnit harness, PR checked out in place of the plugin)
test_FrmFieldsAjax.php (including the new denied-delete test) → OK, 10 tests, 122 assertions.
Entry, field, XML and form test classes (--exclude-group ajax) → OK, 249 tests, 1,430 assertions.
Not run: a clean full-suite result. In my environment the full run reports 108 errors, the first one in test_FrmAddon (a PHPUnit SERIALIZATION_FORMAT_USE_UNSER… syntax error), and PHPUnit stops printing after it. None of them touch files this PR changes, but I can't call the full suite green. CI skipped PHPUnit, PHPCS and PHPStan on this head, and I could not run PHPCS (the Formidable sniff standard isn't installed here).
Live check (Playground preview env on this PR, form builder)
A test mu-plugin denied deletion of one field through frm_can_destroy_field. Deleting that field shows the modal below and the field stays in the builder. Deleting a different field still removes it.
Not exercised in a browser: frm_filter_final_form with the form object, XML import blocking, frm_field_values_before_update. These are covered only by the PHPUnit tests above.
Non-blocking notes
FrmFormsController.php (the line that deletes fields on form save) and FrmXMLHelper::delete_removed_fields() still ignore a false return from FrmField::destroy(), so a denied delete there is silent. Fine for the registration use case; worth a follow-up if another integration relies on it.
frm_can_destroy_field now runs twice for one builder delete: once in FrmFieldsController::destroy() and again inside FrmField::destroy(). A filter callback with side effects fires twice. Using the false return of FrmField::destroy() for the error response would run it once.
The new frm_allow_entry_save docblock in FrmEntry::allows_save() aligns @param types inconsistently. The repo's PHPCS may flag it; I could not run PHPCS here.
I read the whole PR against current master again, not just the new commit. The last notes are addressed: frm_can_destroy_field now runs once on an allowed delete, and denied deletes in the settings save and XML import report a warning instead of failing silently. No blocking problem.
Tests run (head f207a0d, local WordPress PHPUnit harness, PR checked out in place of the plugin, vendor copied in)
Entries, fields, XML and form test files (--exclude-group ajax, one file at a time) → 43 files OK, 311 tests, 1,573 assertions; the one other file, test_FrmCaptchaSpam.php, ran 15 tests with 1 skipped and no failure.
Not run: a clean full-suite result (the full run has environmental errors here, first in test_FrmAddon), PHPCS (the Formidable sniff standard isn't installed here), PHPStan. CI skipped PHPUnit, PHPCS and PHPStan on this head.
Checked with throwaway tests (removed afterwards)
An allowed AJAX delete runs frm_can_destroy_field 1 time on the PR and 2 times with the old can_destroy() + destroy() code, so the double evaluation is fixed.
FrmFormsController::update_settings() with the captcha box unticked: with a deny filter the field stays and the page shows "Some fields could not be added or deleted." beside "Settings Successfully Updated"; without it the field is deleted and no warning shows.
The builder's denied-delete modal was checked live at the previous head (6b901b5); the JS in this head is unchanged from that, so I did not repeat the browser pass.
Non-blocking notes (details inline)
The new "evaluate the policy once" assertion cannot fail on the old code (it only runs the denied path).
A delete of a field that no longer exists now returns the 403 "This field cannot be deleted." error instead of succeeding quietly.
The new settings/import test was inserted between test_entry_filter_blocks_standard_and_xml_writes and its docblock.
The reason will be displayed to describe this comment to others. Learn more.
This assertion does not prove the "checks once" fix. The test denies the delete, and on the old code (! FrmField::can_destroy() then FrmField::destroy()) a denied delete already stopped after one evaluation. I swapped the old controller code in and this test still passed 10/10. The double evaluation only happened on an allowed delete (I measured 2 runs on the old code, 1 on this PR).
Suggested fix: add a second test that allows the delete, counts did_filter( 'frm_can_destroy_field' ) before and after, and asserts the difference is 1 and that FrmField::getOne( $field_id ) is false. That test fails on the old code.
The reason will be displayed to describe this comment to others. Learn more.
FrmField::destroy() also returns false when the field row is already gone (if ( ! $field ) { return false; }). So deleting a field that no longer exists (a second tab, or a double click on the delete icon) now returns the 403 "This field cannot be deleted." modal, where before it returned quietly. I ran the handler with a nonexistent field ID: new code returns {"success":false,"data":{"message":"This field cannot be deleted."}}, old code returned an empty success.
This is minor and the message is wrong for that case. If you want to keep the old behaviour, check FrmField::getOne( $field_id ) first and only send the error when the field exists and can_destroy() is false. Otherwise it is fine to leave.
The reason will be displayed to describe this comment to others. Learn more.
test_denied_settings_and_import_deletes_report_failure() was added between the existing @return void docblock and test_entry_filter_blocks_standard_and_xml_writes(), so the new test took the docblock and this one has none. Move the new method above that docblock (and give it its own /** @return void */), or add the docblock back here. PHPCS may flag the missing one; I could not run PHPCS here.
The reason will be displayed to describe this comment to others. Learn more.
Access to an undefined property test_FrmFieldsAjax::$_last_response
This issue is raised when an attempt is made to access an undefined property.
This may not have been intended, and it is advisable to give the code another look to make sure the property is defined in the scope it is used in.
The reason will be displayed to describe this comment to others. Learn more.
Approve. The new commit f3d52639c (my Approve was at f207a0de2) fixes all three of my notes, and I found nothing new.
Note 2 (deleting a missing field returned 403): fixed.FrmFieldsController::destroy() now only reports "This field cannot be deleted." when the field exists and FrmField::destroy() returns false. A second delete of the same field gets a quiet wp_die().
Note 1 (the "policy runs once" assertion could not fail on the old code): fixed.test_allowed_delete_checks_policy_once_and_missing_delete_succeeds deletes an allowed field and asserts did_filter( 'frm_can_destroy_field' ) went up by exactly 1, then deletes it again and asserts an empty response. With FrmField::can_destroy() called ahead of destroy() it fails ("Failed asserting that 2 is identical to 1"). With the new getOne() guard removed it errors on the second delete.
Note 3 (docblock separated from its test): fixed.test_entry_filter_blocks_standard_and_xml_writes has its @return void docblock back.
Tests run at f3d52639c (wordpress-develop harness, PHP 8.4, PR copied in place of the plugin):
test_FrmFieldsAjax.php --group ajax → OK (11 tests, 128 assertions).
test_FrmIntegrationGuards.php → OK (9 tests, 35 assertions).
--filter '/^test_(FrmFieldsAjax|FrmIntegrationGuards|FrmField|FrmXML|FrmFormsController)::/' → OK (37 tests, 327 assertions).
php -l clean on the three changed files.
Not run: PHPCS (the Formidable ruleset won't load in this harness) and PHPStan; CI skipped PHPUnit, PHPCS and PHPStan on this head. The files not touched by this commit were not re-read this round, and code-review/security-review/simplify were not run on this 2-line source change. The builder's delete flow was not re-checked in a UI; the earlier live pass at 6b901b5a4 stands, with no JS change since.
The reason will be displayed to describe this comment to others. Learn more.
Approve at d69c425. My Approve was at f3d5263; the head has since moved by master merges only, so this is a fresh verdict at the new head.
PR's own change is unchanged: the PR diff against master is the same 9 files, 461 changed lines in the 8 source and test files, line-for-line identical to the one at f3d5263. Two of the four "Merge master" commits (fad0eaa, 2f43596) had a conflict in the built js/formidable_admin.js; the other two (fe661c9, d69c425) are clean.
Built bundle checked: I rebuilt js/formidable_admin.js from js/src/admin/admin.js at this head with NODE_ENV=production npx webpack. The committed file matches the rebuild except for webpack's numeric module ids (they change with the build path), and the new error( xhr ) handler is present in both. Nothing else differs.
Nothing new found.
Tests run at d69c425 (wordpress-develop harness, PHP 8.4, PR copied in place of the plugin):
test_FrmFieldsAjax.php --group ajax → OK (11 tests, 128 assertions).
test_FrmIntegrationGuards.php → OK (9 tests, 35 assertions).
--filter '/^test_(FrmFieldsAjax|FrmIntegrationGuards|FrmField|FrmXML|FrmFormsController)::/' → OK (37 tests, 327 assertions).
php -l clean on the five changed PHP classes.
CI skipped PHPUnit, PHPCS and PHPStan on this head, so these local runs are the only execution.
Not exercised: PHPCS and PHPStan at this head, the builder's delete flow in a UI (the earlier live pass at 6b901b5a4 stands; the only JS source change since is master's), and the three review skills.
…orage-guards
Co-Authored-By: Claude Opus 5.5 <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
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.
Integrations need to prevent entry storage and protect required fields at the model layer, including direct calls and XML imports. Add generic storage and field protection APIs, and provide the form object to the final rendering filter so integrations can customize output for that form.
Supports https://github.com/Strategy11/formidable-registration/pull/409. This PR contains the three required Lite source changes plus six regression tests. It contains no registration-specific logic and requires no Pro changes.
Changes
FrmEntry::allows_save()andfrm_allow_entry_save. Honor theprevent_entry_storageform option for both the form and its parent. Reject blocked standard and XML creates and updates before persistence and associated actions. Updates also check the existing entry's form when the caller omits or changes the form ID.frm_field_values_before_updateso integrations can preserve field requirements before saving.FrmField::can_destroy()andfrm_can_destroy_field, enforced before deleting a field.frm_filter_final_form. Existing callbacks accepting only HTML remain compatible.Testing
FrmAppHelper,FrmAddon, andFrmShowFormcode.