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 e690e5a...06c1c13 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.
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.
Duplicating an entry now runs the frm_allow_entry_save filter and returns
false for a missing entry instead of failing. The delete-field ability
reports a delete blocked by frm_can_destroy_field as a 403 before any
repeater child fields are removed. The storage filter result is cast to
bool, and the field update and destroy hooks are documented.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Request Changes at 28d20a7 (re-review of the whole PR; my earlier Approve was at d69c425). One blocker, found by running it, in the new commit 9248ea7. Everything else holds.
Blocking
classes/controllers/FrmAbilitiesFieldsController.php:484: deleting a repeater through the delete-field ability still deletes a child field that frm_can_destroy_field denied, along with its siblings, and returns success. Reproduced, with the fix and test in the inline comment.
What changed since d69c425:9248ea7 (duplicate runs frm_allow_entry_save, the delete-field ability pre-checks can_destroy(), filter result cast to bool, docblocks) plus two clean master merges. The PR's own diff against master is 11 files, +562/-27.
Tests run (CI skips PHPUnit on this PR), at 28d20a705ebbffeb64bd99813b0f01c24b16f8e8, wordpress-develop harness, PHP 8.4, PR copied in place of Lite, Lite's own vendor/bin/phpunit:
Removing the duplicate guard fails test_storage_policy_blocks_duplicating_an_entry. Removing the abilities pre-check fails test_delete_field_reports_a_denied_delete. Removing the update guard fails test_allowing_filter_receives_entry_id_and_saves.
Checked and fine: a whole-form delete uses raw SQL and never reaches can_destroy(), so the docblock claim is right. FrmFieldsController::destroy() sends the 403 JSON that the builder's new error() handler reads (data.message).
Not exercised, so please don't read this as covering it: the builder's delete flow in a browser (the last live pass was at 6b901b5a4; no JS source changed in 9248ea7), a rebuild of js/formidable_admin.js at this head, PHPCS/PHPStan, and the review skills. I read the new commit and the whole PR diff by hand.
Not a blocker, same area: Pro's repeater delete path was not looked at. If Pro removes a repeater's child fields through FrmField::destroy() the same way, a denied child is skipped there too.
The reason will be displayed to describe this comment to others. Learn more.
Blocking: a denied child field is deleted anyway when its repeater is deleted.
This check only asks about the repeater field itself. The next step, destroy_fields_in_repeater(), calls FrmField::destroy() on each field of the repeater's form, and destroy() now quietly returns false for a denied one. The loop ignores that result, so the delete carries on. The comment above says "a denied delete changes nothing", and the commit message says the 403 comes "before any repeater child fields are removed". Both are only true when the repeater itself is denied.
I ran it in the wordpress-develop harness (throwaway test, removed afterwards). Setup: host form, repeater field (divider, repeat = 1, form_select = child form), two text fields in the child form, and a frm_can_destroy_field callback that denies only the first child field:
execute_delete_field( repeater ) -> ok (no error)
repeater exists: no
protected child field exists: yes (orphaned in the child form)
sibling child field exists: no
So a field an integration marked as undeletable survives, but its repeater and its siblings are gone, and the caller gets a success reply.
Fix: ask about every field that would be removed before changing anything. Replace these four lines with:
Suggested change
// Check before a repeater's own fields are deleted, so a denied delete changes nothing.
if ( ! FrmField::can_destroy( $field->id ) ) {
returnnewWP_Error( 'frm_field_delete_denied', __( 'This field cannot be deleted.', 'formidable' ), array( 'status' => 403 ) );
}
// Check the field and a repeater's own fields first, so a denied delete changes nothing.
returnnewWP_Error( 'frm_field_delete_denied', __( 'This field cannot be deleted.', 'formidable' ), array( 'status' => 403 ) );
}
}
I did not run this exact change. Add a test next to test_delete_field_reports_a_denied_delete in tests/phpunit/fields/test_FrmAbilitiesFieldsController.php: build a repeater with two child fields, deny one child by ID, call delete-field on the repeater, then assert a frm_field_delete_denied error and that the repeater and both child fields still exist. The existing test uses __return_false on a plain field, so it cannot catch this.
The reason will be displayed to describe this comment to others. Learn more.
Approve at 1c63d70 (my Request Changes was at 28d20a7). The blocker is fixed.
Blocker fixed:851623914 makes the delete-field ability check frm_can_destroy_field for the repeater and every child field before it deletes anything (FrmAbilitiesFieldsController.php:484-490), the shape I suggested. A protected child now returns the 403 frm_field_delete_denied error and the repeater, the denied child and its sibling all stay. get_repeater_field_ids() replaces destroy_fields_in_repeater(), and nothing else called the old one. The other changes since 28d20a7 are master merges (post-dropdown-labels from #3684 and the built bundle); the PR's own diff against master is the same 11 files plus this commit.
Tests run (CI skips PHPUnit on this PR), at 1c63d7014954d1e6eb3e32601ca2d47f377de5a2, wordpress-develop harness, PHP 8.4, PR copied in place of Lite, Lite's own vendor/bin/phpunit:
test_FrmAbilitiesFieldsController with the loop reduced to the repeater alone fails the new test_delete_repeater_preserves_all_fields_if_a_child_is_protected (returns an array, not a WP_Error), so the test catches the bug.
php -l clean on the controller.
Non-blocking (one note, not in this diff): Pro's builder path for a repeater has the same gap. FrmProField::delete() runs on frm_before_destroy_field and calls FrmForm::destroy() on the child form (formidable-pro/classes/models/FrmProField.php:627-634), which deletes the child fields with raw SQL and never asks frm_can_destroy_field. So FrmField::destroy( $repeater_id ) from the builder allows a repeater whose child is protected. This PR cannot fix it from Lite, so it is a follow-up for Pro, only relevant if the guard is meant to cover repeater children there too.
Not exercised: the builder's delete flow in a browser (last live pass was at 6b901b5a4; the JS source is unchanged since), a rebuild of js/formidable_admin.js at this head, PHPCS/PHPStan, and the three review skills. I read the new commit and re-checked the earlier findings by hand; the rest of the PR is as at my earlier rounds.
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.