Repository navigation
Fix: Misleading Message When Accessing Admin Menu Page - #7613
nirajgiriXD wants to merge 47 commits into
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @nirajgiri9860@googlemail.com. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
Co-authored-by: Christoph Daum <c.daum@me.com>
|
@nirajgiriXD I left some feedback for consideration. Also, could you bring this up to date with the latest trunk branch? |
Co-authored-by: John Parris <public@johnparris.com>
Co-authored-by: John Parris <public@johnparris.com>
|
@mindctrl Thanks for the feedback! I've implemented the suggested changes and updated the branch with the latest from trunk. |
mindctrl
left a comment
There was a problem hiding this comment.
Needs unit tests. Needs discussion about introducing a new action, if it's desired, and what its name should be.
Co-authored-by: Noruzzaman <noruzzamanrubel@gmail.com>
Co-authored-by: Noruzzaman <noruzzamanrubel@gmail.com>
Co-authored-by: Noruzzaman <noruzzamanrubel@gmail.com>
Co-authored-by: Noruzzaman <noruzzamanrubel@gmail.com>
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Co-authored-by: Noruzzaman <noruzzamanrubel@gmail.com>
Co-authored-by: Shail Mehta <shailmehta25@gmail.com>
Co-authored-by: Huzaifa Al Mesbah <huzaifah4m@gmail.com>
`$_wp_menu_nopriv` and `$_wp_submenu_nopriv` were documented as bare `array`, which leaves PHPStan resolving their contents as `mixed` and reporting both a missing iterable value type and an inaccessible offset on every nested lookup. Both shapes are determinable from core. `$_wp_menu_nopriv` is written only in `wp-admin/includes/menu.php`, keyed by top-level menu slug with a value of `true`. `$_wp_submenu_nopriv` is written there and in `add_submenu_page()`, keyed by parent slug then by submenu slug, again with a value of `true`. Every read is an `isset()`, so only key presence is ever consumed. Documents them as `array<string, true>` and `array<string, array<string, true>>` respectively, on the two functions this branch modifies. Docblocks only; no behavior change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Seven of the eight `@global` tags on the function carried a type and a name but no description. Fills them in, reusing the wording already used for the same globals on `wp_admin_page_exists()` so the two functions read consistently. `$menu` and `$submenu` are described for the first time; neither is documented anywhere else in core. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
🤖 Comment by Claude Opus 5 This is a review of the branch diff. The structural claims below were each verified against the current branch. Findings are ordered by severity. The no-privilege registries are emptied after
|
t-hamano
left a comment
There was a problem hiding this comment.
Based on this feedback, I have proposed specific changes.
admin_page_access_deniedno longer fires for unregistered slugs
I think this is worth discussing how to address. Since we now have the new admin_page_not_found action, we could probably cover this change with a dev note. Something like:
In WordPress 7.2, requests for admin pages that don't exist now show "The requested page does not exist." (404) instead of a permission error (403). As a result,
admin_page_access_deniedno longer fires for such requests; it only fires when the page exists but the user lacks permission. Plugins that useadmin_page_access_deniedto redirect old or mistyped?page=URLs should also hook their callback to the newadmin_page_not_foundaction. Hooking to both is safe on older WordPress versions, sinceadmin_page_not_foundsimply won't fire there.
|
@nirajgiriXD You can skip merging from |
Co-Authored-By: Claude <noreply@anthropic.com>
The no-privilege menu registries are reset in menu.php after `_admin_menu` fires, so pages registered earlier were reported as missing. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
peterwilsoncc
left a comment
There was a problem hiding this comment.
I've added some notes inline.
🔢 if the test suite indicates that the note applies to multiple tests.
Co-Authored-By: Claude <noreply@anthropic.com>
The test suite resets the current user during tear down. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
t-hamano
left a comment
There was a problem hiding this comment.
Looks good from my end. The only notable point is the following, though I personally think this can be addressed in the dev notes.
admin_page_access_deniedno longer fires for unregistered slugsI think this is worth discussing how to address. Since we now have the new
admin_page_not_foundaction, we could probably cover this change with a dev note. Something like:In WordPress 7.2, requests for admin pages that don't exist now show "The requested page does not exist." (404) instead of a permission error (403). As a result,
admin_page_access_deniedno longer fires for such requests; it only fires when the page exists but the user lacks permission. Plugins that useadmin_page_access_deniedto redirect old or mistyped?page=URLs should also hook their callback to the newadmin_page_not_foundaction. Hooking to both is safe on older WordPress versions, sinceadmin_page_not_foundsimply won't fire there.
westonruter
left a comment
There was a problem hiding this comment.
Some minor typing improvement suggestions.
| * @global array $menu | ||
| * @global array $_wp_real_parent_file | ||
| * @global bool $_wp_submenu_nopriv | ||
| * @global array $_wp_nopriv_pages |
There was a problem hiding this comment.
Minor: This here is still just array but for wp_admin_page_exists() it is richly typed as array<string, true>. It would be nice to include the richer typing here as well.
| * | ||
| * @since 7.2.0 | ||
| * | ||
| * @global string $plugin_page The plugin page slug being loaded. |
There was a problem hiding this comment.
Technically this could be null, right? The first statement in the function is to check if it is set.
| * @global string $plugin_page The plugin page slug being loaded. | |
| * @global string|null $plugin_page The plugin page slug being loaded. |
| * @global string $pagenow The filename of the current screen. | ||
| * @global array $menu The top-level admin menu items. | ||
| * @global array $submenu The admin submenu items, keyed by parent slug. | ||
| * @global array<string, true> $_wp_menu_nopriv Array of top-level menu slugs the current user cannot access. | ||
| * @global array<string, array<string, true>> $_wp_submenu_nopriv Array of submenu slugs the current user cannot access, keyed by parent slug. | ||
| * @global string $plugin_page The plugin page slug being loaded. | ||
| * @global array $_registered_pages Array of all registered admin page hooks. |
There was a problem hiding this comment.
These can be more richly typed to match the above as well.
Co-Authored-By: Claude <noreply@anthropic.com>
…type correction. Co-Authored-By: Claude <noreply@anthropic.com>


Description
This PR addresses the issue where the misleading message
You do not have sufficient permissions to access this page.was displayed when attempting to access an admin page that doesn't exist. Instead of suggesting a permissions problem, the fix ensures that users are now shown a clearer message:The requested page does not exist.This provides a more accurate and user-friendly explanation when the page is missing or unavailable.Screenshot
Testing Instructions
The requested page does not exist.instead ofYou do not have sufficient permissions to access this page.Trac ticket: https://core.trac.wordpress.org/ticket/14060