Skip to content

Admin: Correct logic flow for nonce and capability checks in post.php#11637

Open
liaisontw wants to merge 1 commit intoWordPress:trunkfrom
liaisontw:fix/65052-nonce-check-order-post-quickdraft-save
Open

Admin: Correct logic flow for nonce and capability checks in post.php#11637
liaisontw wants to merge 1 commit intoWordPress:trunkfrom
liaisontw:fix/65052-nonce-check-order-post-quickdraft-save

Conversation

@liaisontw
Copy link
Copy Markdown

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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props liaison, apermo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@liaisontw liaisontw force-pushed the fix/65052-nonce-check-order-post-quickdraft-save branch 2 times, most recently from 5d73f7a to b33cbca Compare April 24, 2026 03:37
Comment thread src/wp-admin/post.php Outdated
Comment thread tests/phpunit/tests/admin/wpPost.php Outdated
Comment thread tests/phpunit/tests/admin/wpPost.php Outdated
Comment thread tests/phpunit/tests/admin/wpPost.php Outdated
@liaisontw liaisontw force-pushed the fix/65052-nonce-check-order-post-quickdraft-save branch 5 times, most recently from 251716d to efac557 Compare April 27, 2026 05:33
@liaisontw liaisontw force-pushed the fix/65052-nonce-check-order-post-quickdraft-save branch from efac557 to c17aa3e Compare April 27, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants