Repository navigation
🐛 fix(routing): pages check their capability; public REST routes say so - #123
Merged
Merged
Conversation
The pages of config/routes.php and of pages/ are written straight into $_registered_pages, with no menu entry, and WordPress lets any logged-in user open a page registered that way: a subscriber opened a route declared manage_options. The capability key the docs describe was never read. Both providers now refuse the page with a 403 to a user without the capability, on load before any other load callback and again on render. A route reads its capability key; a Page class says it with capability(). The default is read, so a page that declares nothing behaves as before.
… public Route merged permission_callback => __return_true into every route that did not set one, so a Route::post() with no options was a public write endpoint and WordPress's own notice about the missing argument never fired. The route stays public, as it was, and _doing_it_wrong() names it and says how to make that choice explicit. WP Bones 3.0 will refuse such a route.
A page with no menu entry has no title for get_admin_page_title(), so admin-header.php passed null to strip_tags(): a deprecation in debug.log on every visit, on PHP 8.1 and later. The load callback now sets the title global, as WordPress expects from a page it does not know.
- capability() is optional and not declared by Page: a subclass may already have one with another signature (a declaration fatal in every wp-admin request), and a class in pages/ never had to extend Page. - A capability that is not a string (an array, true, 1) asks for read with a notice, instead of being cast to 'Array' or to a user level. - admin_page_access_denied fires before the refusal, as in core: multisite hangs its splash on it. - The REST notice carries no version: WordPress prints it as its own.
is_callable() is true through __call() as well, and for a method that needs arguments (Codex, round 2 on #123). The method must be declared, public and callable with no arguments; otherwise the page asks for read.
This was referenced Oct 6, 2026
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.
Three fixes in
src/Routing, for 2.1.2. A page or a route that declares nothing behaves as before, with one exception, listed below.Route and
pages/pages check the capability they ask forThe pages of
config/routes.phpand ofpages/are written straight into$_registered_pages, with no menu entry, and WordPress lets any logged-in user open a page registered that way. Thecapabilitykey the docs and the Routes boilerplate declare was never read, so a route declaredmanage_optionsopened for a subscriber.wp-admin/includes/menu.phprefuses a page:admin_page_access_denied, then WordPress's own 403. The check runs onload-{hook}atPHP_INT_MIN, before anyloadcallback, and again when the page renders (Support\Traits\AuthorizesAdminPages).capabilitykey. Apages/class says it with an optional publiccapability()method. It is not declared onPage: a subclass may already have one with another signature, and a class inpages/never had to extendPage.read. A capability that is not a string (an array,true,1) raises a notice and asks forread, instead of being cast toArrayor to a user level.read, so they are now refused.A REST route without a
permission_callbacksays it is publicRoutemerged'permission_callback' => '__return_true'into every route that did not set one, so aRoute::post()with no options was a public write endpoint, and WordPress's own notice about the missing argument never fired._doing_it_wrong()names it atrest_api_initand says how to make the choice explicit.nullcallback counts as missing, as in core'sisset().X-WP-DoingItWrongheader, as it does for its own notices.The same pages give WordPress their title
A page with no menu entry has no title for
get_admin_page_title(), soadmin-header.phppassednulltostrip_tags(): a deprecation indebug.logon every visit, on PHP 8.1 and later. Theloadcallback now sets the$titleglobal. The<title>is unchanged, because the framework'sadmin_titlefilter still sets it.Tests
composer test: 200 tests and 521 assertions, against 175 and 472 on master. The 25 new tests are inAdminRouteProviderTest,PageProviderTestandRestRouteTest.route-capability-live-smoke.sh:pages/classes and three REST routes.debug.logis read from its size at the start.manage_optionsroute by GET and by POST, and from themanage_optionspage.Review
Copilot could not review: the account's quota is exhausted.
Codex (gpt-6-sol, high):
is_callable()is true through__call(), and for acapability()that needs arguments. Fixed in the last commit: the method must be declared, public and argument-free.An independent review found the points fixed in 51bac68:
capability();admin_page_access_denied;It also tried breaking the fix on a scratch copy, and the tests caught each break.