Make WordPress Core

Opened 3 years ago

Last modified 5 weeks ago

#59667 new enhancement

Edit Category Screen: Improve error message when trying to update a category with an existing slug

Reported by: plari Owned by:
Priority: normal Milestone: Awaiting Review
Component: Taxonomy Version: 6.3.2
Severity: minor Keywords: has-patch
Cc: Focuses:

Description

Request: improve the error message shown on the Category Edit screen when trying to set an already-used slug.

Why:

If I edit a category and try to give it a slug that is already used on another category, I encounter the vague error Category not updated.

This error is not very informative.

By comparison, if I Quick-Edit to make this change, though, I am told: The slug “example-slug” is already in use by another term., which is much clearer and I understand the problem right away.

Attachments (1)

Screen Capture on 2023-10-17 at 16-54-16.mp4​ (453.6 KB ) - added by plari 3 years ago.
Recording of the different error messages

Download all attachments as: .zip

Change History (2)

This ticket was mentioned in ​PR #13963 on ​WordPress/wordpress-develop by ​@wpnomad.


5 weeks ago
#1

  • Keywords has-patch added

On the Edit Term screen, saving a term with a slug already used by another term in the same taxonomy shows only "Category not updated.", while Quick Edit shows the underlying error.

This PR:

  • Redirects with a new message index (7) when wp_update_term() returns duplicate_term_slug. Other errors still use message 5.
  • Adds message 7 to the _item, category and post_tag arrays: "Category not updated. The slug is already in use by another category." etc.
  • Makes the message lookup fall back to the generic _item message when a taxonomy's messages (set via term_updated_messages) don't define the requested index. Without this, taxonomies registering their own message arrays (e.g. WooCommerce product_cat) would show no notice at all for message 7.

Only a fixed message index goes in the URL; no user input is reflected.

Testing instructions

  1. Create two categories, e.g. "News" (news) and "Updates".
  2. Edit "Updates" on the full edit screen and set its slug to news. Click Update.
  3. Before: "Category not updated." After: "Category not updated. The slug is already in use by another category."
  4. Repeat for tags.
  5. Regression checks: a normal save still shows "Category updated."; clearing the name (bypassing required) still shows "Category not updated.".
  6. Optional: register a custom taxonomy with term_updated_messages entries lacking index 7; a duplicate slug shows "Item not updated. The slug is already in use by another term."

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigation, implementation, tests and local verification, under my direction.

---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See ​GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with ​Claude Code

​https://claude.ai/code/session_014nJenDidRzoohF8JCEKbZ9

Note: See TracTickets for help on using tickets.