fix(validation): validate required fields on pending, future, and private saves#518
Open
faisalahammad wants to merge 1 commit into
Open
fix(validation): validate required fields on pending, future, and private saves#518faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
The save_post gate in ACF_Form_Post checked only for the 'publish' status, so a contributor who lacked publish capability could submit a custom post type for review (status 'pending') with required SCF fields empty, or schedule a post (status 'future') without required data. Scheduled and private posts share the same risk class: the post is leaving the author's hands. Extract a should_validate_post() helper that returns true for the statuses where the post leaves the author (publish, pending, future, private) and keep draft / auto-draft / inherit / trash saving as before so authors can keep iterating. Adds two PHPUnit tests covering both the validating and the non-validating status sets. Fixes WordPress#197
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Summary
A contributor who lacks
publish_*capability can submit a custom post type for review (statuspending), schedule it (future), or make it private (private) without required SCF fields being filled. Thesave_postgate inACF_Form_Postonly checked forpublish, so theacf_validate_save_post()call was skipped on every other status that moves the post out of the author's hands.This PR widens the gate to the statuses where the post leaves the author (
publish,pending,future,private) by extracting the check into a smallshould_validate_post()helper. Intermediate statuses (draft,auto-draft,inherit,trash) keep saving without enforcement, matching today's behaviour.Closes #197
Changes
includes/forms/form-post.phpAdds a
should_validate_post()method that returns true for the validating status set:And replaces the inline
if ( 'publish' === $post->post_status )insave_post()with:tests/php/includes/forms/test-form-post.phpTwo new tests on
Test_Form_Post:test_should_validate_post_for_publishing_statuses— assertspublish,pending,future,privateall returntrue.test_should_validate_post_for_drafting_statuses— assertsdraft,auto-draft,inherit,trashreturnfalse.Why this is enough
pending(Submit for Review — the bug),future(scheduled, required fields matter), andprivate(visible only to authors/editors but still exits draft mode).draft,auto-draft) keep saving without enforcement so authors can keep iterating.inherit(revisions) andtrashalready short-circuit earlier inallow_save_post().The frontend validation paths (
assets/src/js/_acf-validation.js) remain unchanged: they already fire AJAX validation on Save/Submit clicks. The classic-editor and GutenberguseValidationflags are a separate UX concern (which transitions trigger JS validation) and are out of scope for this server-side safety net.The other save paths I checked (
includes/Datastore/REST_Save.php,includes/forms/form-front.php,includes/forms/form-gutenberg.php, options page, attachment, comment, blocks, internal post types) do not go through this gate for unrelated reasons and are not affected.How to test
events) and a SCF field group attached to it with one required text field (event_location).read+edit_eventsbut notpublish_events.event_locationempty, click Submit for Review.event_location. Status does not advance topending.event_location, click Submit for Review again.pending.event_locationempty.A manual test plan is included in
TESTING_INSTRUCTIONS.md(in this PR's commit message thread, not committed to the repo).Automated tests
Run with wp-env running:
14 tests pass (2 new + 12 existing), 26 assertions.
Use of AI Tools
AI tooling was used to navigate the codebase, run targeted static analysis and tests, and draft the PR text. The change itself was implemented, reviewed, and validated by the contributor.