[wp-trac] [WordPress Trac] #64721: menu-header.php uses relative file_exists() causing wrong submenu URL when PHP CWD is not wp-admin/
WordPress Trac
noreply at wordpress.org
Tue Feb 24 23:54:46 UTC 2026
#64721: menu-header.php uses relative file_exists() causing wrong submenu URL when
PHP CWD is not wp-admin/
----------------------------+-----------------------------
Reporter: paoltaia | Owner: (none)
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version: 6.9.1
Severity: normal | Keywords: has-patch
Focuses: |
----------------------------+-----------------------------
== What Happens ==
When a plugin registers a submenu page under a Custom Post Type menu
(e.g. edit.php?post_type=gd_place), clicking that submenu item generates
a broken URL like:
admin.php?page=gd_place-settings
...instead of the correct:
edit.php?post_type=gd_place&page=gd_place-settings
== Why It Happens ==
In wp-admin/menu-header.php, around line 267, WordPress checks:
file_exists( $menu_file )
...where $menu_file is a bare relative path like 'edit.php'.
The file_exists() call resolves against PHP's current working directory
(CWD).
On standard Apache/Nginx servers, PHP's CWD is the wp-admin/ folder, so
file_exists('edit.php') returns TRUE and the correct URL is built.
But in WordPress Studio (and any environment where PHP's CWD is the
WordPress
root instead of wp-admin/), file_exists('edit.php') returns FALSE, so
WordPress falls back to building admin.php?page=... — dropping the
post_type
parameter entirely.
== The Fix ==
The check should use an absolute path:
file_exists( ABSPATH . 'wp-admin/' . $menu_file )
This would work correctly regardless of what the PHP CWD happens to be.
== Steps to Reproduce ==
1. Install WordPress using WordPress Studio (local dev tool)
2. Install a plugin that registers a submenu under a CPT menu
(e.g. GeoDirectory)
3. Click the submenu item in wp-admin
4. Observe the URL: it says admin.php?page=... instead of
edit.php?post_type=...&page=...
== Expected vs Actual ==
- Expected: edit.php?post_type=gd_place&page=gd_place-settings
- Actual: admin.php?page=gd_place-settings
== Environment ==
- WordPress version: 6.9.1
- PHP server: WordPress Studio (bundled server, CWD = WP root)
- Works fine on: Apache/Nginx hosting, Local by WP Engine
- Affected file: wp-admin/menu-header.php ~line 267
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64721>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list