wp-build: Add menuSlug and menuSlugAdmin options for admin page URLs#77508
wp-build: Add menuSlug and menuSlugAdmin options for admin page URLs#77508
Conversation
|
Size Change: 0 B Total Size: 7.76 MB ℹ️ View Unchanged
|
|
Flaky tests detected in c240f4a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24777364438
|
|
@jorgefilipecosta @dkotter looks like this change might allow us to go back to using |
|
Sorry, this PR might be a little difficult to understand because both the code and the description have just been vibecoded by AI. 😅 My reason for submitting this PR was to avoid unnecessary redirects when rebuilding the experimental page for the Gutenberg plugin using wp-build. See #77443 (comment) for more details. Would this PR also be useful for the AI plugin? |
If it makes sense from an Information Architecture standpoint, I'd prefer the AI settings page slug to be |
The page-wp-admin.php template previously hardcoded the menu slug to
`{id}-wp-admin`, forcing the admin URL to be tied to the page id. Expose
a `menuSlug` option on `wpPlugin.pages` entries so the URL can be chosen
independently (e.g. `admin.php?page=my-custom-url`) while keeping the
existing id-derived default for backward compatibility.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Document the new `menuSlug` page configuration option introduced in the previous commit, clarifying the split between `id` (used for PHP function names, hooks, and file paths) and `menuSlug` (used for the admin URL).
The initial menuSlug support only customized the WP-Admin mode URL check,
leaving full-page mode (page.php template) hardcoded to the page id. A
single menuSlug now drives both templates, with per-mode fallbacks that
preserve the previous defaults ({id} for full-page, {id}-wp-admin for
WP-Admin). Also adds a CHANGELOG entry.
Replace the separate `{{FULL_PAGE_MENU_SLUG}}` and `{{WP_ADMIN_MENU_SLUG}}`
placeholders with a single `{{MENU_SLUG}}`. The WP-Admin template now
concatenates the `-wp-admin` suffix inline, keeping that convention on the
referencing side and reducing the build-time derivation surface. Default
falls back to the page id for both modes.
A single menuSlug with forced `-wp-admin` suffix prevents preserving
legacy URLs like `?page=gutenberg-experiments` when refactoring existing
admin pages onto wp-build. Add a dedicated menuSlugAdmin option that
defaults to `{menuSlug}-wp-admin` but can be overridden to any value,
and fail the build if it resolves equal to menuSlug (both templates
register `\$_GET['page']` hooks on every request, so equal slugs collide).
The conflict rationale is explained once in the adjacent comment, so the error message only needs the page slug and resolved value. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
b3f24f2 to
ce7bfea
Compare
WordPress passes menu slugs through sanitize_key(), which only permits lowercase alphanumerics, dashes, and underscores. Fail the build early with a clear error rather than letting WordPress silently mangle the slug at runtime and break the page URL. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@youknowriad, Please let me know if you have any feedback on this PR! |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I think one question this raises is whether the menu registration should now be done automatically by wp-build when these things are defined. Previously the menu registration was considered out of scope of wp-build |
|
Thanks for the feedback.
Personally, I don't think menu registration should be automated by wp-build. This is because the locations for injecting menus, menu titles, and permissions can vary. |
|
@t-hamano Yes, but since you're defining the slugs already, we have the labels too, it's not a big stretch to think we could define all of these too. Another possibility is a new folder with json files for the pages |
What?
This PR enables manual setting of menu slugs in wp-build, allowing pages to be exposed at arbitrary URLs in both wp-admin and full-page modes.
Why?
The reason for submitting this PR is #77443. We found that when rebuilding the Gutenberg experimental settings page with wp-build, the URL is forced to change as follows:
We need to implement redirect processing for users who may have bookmarked old URLs. I believe this could be a barrier for many developers when we recommend page development based on wp-build.
How?
Add options
menuSlugandmenuSlugAdminto allow changing the menu slug for each of the two modes. Each menu slug must be unique.Testing Instructions
The following is an example of changing the URL of the Connectors page from
?page=options-connectors-wp-adminto?page=options-connectors.Screenshots or screencast
Not applicable.
Use of AI Tools
Claude Code was used to investigate the existing template code paths (plugin vs. Core build modes from #75844), work through the design tradeoffs, draft the implementation, and author the documentation and commit messages. All changes were reviewed by the author before committing.