Harden custom status migration and the publish-timestamp workaround - #989
Merged
Conversation
The custom-status migration handler reassigned posts to whatever target status was submitted, so a bogus value could strand posts in a status that does not exist; it now validates the target against the full set of core and custom statuses. That set is exposed as a shared method so the WP-CLI migrate command and the web handler agree on what is valid. The publish-timestamp workaround also wrote directly to the posts table on bulk and single publish requests without any verification of its own. It now confirms the relevant edit nonce and the per-post edit capability before writing, bailing quietly when either is missing since it runs on admin_init. Fixes VIPPLUG-22.
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
Two long-standing rough edges in the custom-status module are tightened here.
The web status-migration handler used to reassign every post from one status to whatever target was submitted, without checking that the target was a real status. A typo or a forged value could therefore leave posts stranded in a status that does not exist. The handler now validates the submitted target against the full set of valid statuses — the core statuses plus every registered custom status. That set is exposed as a new public
get_all_valid_statuses()method on the module, and the WP-CLImigratecommand, which previously carried its own private copy of the same logic, now delegates to it so there is a single source of truth.Separately,
check_timestamp_on_publishis a workaround that writespost_statusstraight to the posts table when a post with no GMT timestamp transitions to publish, on both theedit.phpbulk-edit path and thepost.phpsingle-publish path. It did no verification of its own. It now confirms the relevant edit nonce (bulk-posts, orupdate-post_<id>) and the per-postedit_postcapability before writing. Because it runs onadmin_init, it bails quietly rather than callingwp_diewhen a check fails, so legitimate requests are unaffected.Test plan
composer csandparallel-lintpass on the changed files.CustomStatusTest"post name not set" failures are unrelated to this branch and fail identically ondevelop.Fixes VIPPLUG-22.