Plugins: Distinguish a missing admin page from an access denial (#14060)#12591
Plugins: Distinguish a missing admin page from an access denial (#14060)#12591roshniahuja wants to merge 1 commit into
Conversation
Requesting the URL of a plugin admin page that is no longer registered previously produced the misleading "Sorry, you are not allowed to access this page." message, implying a capability problem where none exists. Introduce `admin_page_exists()`, which reports whether the requested page is registered independently of the current user's capabilities. When the page does not exist, `wp_die()` is now called with a clearer "The requested page does not exist." message and a 404 status, and a new `admin_page_not_found` action fires, mirroring the existing `admin_page_access_denied` action. `user_can_access_admin_page()` reuses the new function so the registration check is no longer duplicated. Fixes #14060.
|
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. |
Description
Accessing the URL of a plugin admin page that is no longer registered previously
showed the misleading "Sorry, you are not allowed to access this page." message,
implying a permissions problem where none exists.
This introduces
admin_page_exists(), which determines whether the requested pageis registered independently of the current user's capabilities. When the page does
not exist,
wp_die()is now called with a clearer "The requested page does notexist." message and a 404 status, and a new
admin_page_not_foundaction fires,mirroring the existing
admin_page_access_deniedaction.user_can_access_admin_page()reuses the new function so the registration check isno longer duplicated.
Testing Instructions
are not allowed to access this page."
Unit tests:
npm run test:php -- --filter admin_page_exists tests/phpunit/tests/admin/includesPlugin.phpTrac ticket: https://core.trac.wordpress.org/ticket/14060