Repository navigation
Experiment: Add reserved slugs checks in content types - #78192
ntsekouras wants to merge 3 commits into
Conversation
|
Size Change: +508 B (+0.01%) Total Size: 7.93 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 23d1296. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25723402662
|
|
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. |
23d1296 to
418bc43
Compare
418bc43 to
a97cc6e
Compare
|
It would be hard to have definitive list here. Maybe we should just match what's documented - https://developer.wordpress.org/reference/functions/register_post_type/#reserved-post-types. |
Sounds good. I split into two constants for post types and taxonomies. |
|
I think we can land this now, no? |
|
I am unsure about the extent to which rules should be formalized, as I have not encountered any precedents in Gutenberg where client-side validation is performed based on hardcoded rules, in addition to server-side validation. With the current client-side rules, for example, a validation error occurs the moment a single character like "m" or "p" is entered. This might confuse users. @Mamaduka, do you think the client-side rules should be simplified? |
I think that's fine since even if we did server side, it would result in an invalid slug. |
What?
Part of: #77600
Registering a taxonomy or post type with a name that's also a WP query var (
cat, author, name, s, feed, …) creates rewrite rules that silently hijack built-in archive URLs —?cat=5stops routing to the category archive, etc. The existingtaxonomy_exists() / post_type_exists()check doesn't catch these because the offending names aren't themselves registered as taxonomies or post types — they're just WP-reserved query vars.This PR adds a dedicated rejection branch in both layers of the create flow:
validate_slugin both REST controllers) — the contract. Consults$wp->public_query_vars + $wp->private_query_varsat runtime, so the list stays in sync with whatever core declares.RESERVED_KEYSconstant) — the UX. A curated set of the ~30 highest-risk names, used by the slug field's inline custom validator. With it, they get inline feedback while typing.The JS list is intentionally a static mirror of the high-risk subset rather than a live snapshot — it covers what breaks in practice and doesn't need a round-trip to fetch. The PHP check is what guarantees correctness; if the JS list ever drifts, the server still rejects.
Testing instructions
Content typesexperiment.Settings → Content typesand in taxonomies tab create or edit one to have a reserved slug (e.g.cat)Use of AI Tools
Opus 4.7 with direction, changes and review