Admin: Correct logic flow for nonce and capability checks in post.php#11637
Admin: Correct logic flow for nonce and capability checks in post.php#11637liaisontw wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
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. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
5d73f7a to
b33cbca
Compare
251716d to
efac557
Compare
efac557 to
c17aa3e
Compare
Description
This PR addresses a logic flaw in wp-admin/post.php during the post-quickdraft-save action. Previously, the code attempted to fetch the post object and require dashboard includes before verifying the nonce or checking user capabilities.
Changes included in this PR:
Reordered Logic: Nonce and parameter validation now occur at the beginning of the switch case, ensuring unauthorized or malformed requests are rejected before any heavy processing (like get_post()) occurs.
PHP 8.2+ Compatibility: Implemented null coalescing operators (??) when accessing $_REQUEST parameters to prevent Undefined array key notices.
Unit Tests: Added PHPUnit test cases in Tests_Admin_Post_QuickDraftSave to verify that invalid nonces or missing parameters are handled correctly without triggering PHP warnings.
Trac ticket: https://core.trac.wordpress.org/ticket/65052
Use of AI Tools
AI assistance: Yes
Tool(s): Gemini
Model(s): Gemini 3 Flash
Used for: Refining the PHPUnit test structure and drafting the technical description for the Pull Request. The final code logic, security implications, and test assertions were reviewed and verified by me to ensure compliance with WordPress Coding Standards.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.