WordPress.org

Make WordPress Core

Opened 6 weeks ago

Last modified 5 weeks ago

#50546 new enhancement

Add better error notices when deleting things fail

Reported by: dingo_d Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: 2nd-opinion has-patch
Focuses: ui, administration Cc:

Description

I've stumbled upon this when working with foreign key restraints and post deletion. Working on a project I've added some data to the custom DB table row that has a foreign key association with custom post type post.

So, when I try to delete the post it will fail, as it should 🎉.

But the error I got was: Error in deleting.

Hmmm, ok. Not a big deal. WordPress is pretty flexible in most cases, so there's bound to be a filter for that.

When searching for it, upon checking the above string I've found 5 matches in 3 files. So if some error happens when deleting a post, you'll get that message in wp_die. If it happens on attachment delete, the same message.

How are you supposed to know where that error came from, just from the message? You need to check the error log, etc. Which is ok when you're a developer, but what if you're not? A user could get this message on the screen from some plugin and then they'll open up a support question with this message.

Not really helping the debugging process.

I'm not saying the entire stack trace should be visible (that is advanced debugging), but even just adding Error in deleting a post, or Error in deleting an attachment would be an improvement IMO.

Having some extra details would be even better, but small steps first.

Attachments (1)

50546.diff (3.0 KB) - added by SergeyBiryukov 6 weeks ago.

Download all attachments as: .zip

Change History (8)

@SergeyBiryukov
6 weeks ago

#1 @SergeyBiryukov
6 weeks ago

  • Component changed from Administration to Posts, Post Types
  • Focuses ui administration added
  • Keywords has-patch added; needs-patch removed

Thanks for the ticket!

Yes, it would be a good idea to disambiguate these strings.

For reference, it's currently a series of related strings:

  • Sorry, you are not allowed to move this item to the Trash.
  • Error in moving to Trash.
  • Sorry, you are not allowed to restore this item from the Trash.
  • Error in restoring from Trash.
  • Sorry, you are not allowed to delete this item.
  • Error in deleting.

They use "this item" instead of "post" to account for custom post types, see [12728] / #9674. We should be able to explicitly mention "attachment" though.

50546.diff attempts to bring some consistency:

  • Sorry, you are not allowed to move this item to the Trash.
  • Error in moving the item to Trash.
  • Sorry, you are not allowed to restore this item from the Trash.
  • Error in restoring the item from Trash.
  • Sorry, you are not allowed to delete this item.
  • Error in deleting the attachment.
  • Error in deleting the item.

If we want further clarify what "the item" refers to, these strings should be added to get_post_type_labels().

#2 follow-up: @dingo_d
6 weeks ago

Since we have a post ID, we could add get_post_type to identify the post type? And fall back to item as a default?

Or would that be a bit much?

#3 in reply to: ↑ 2 @SergeyBiryukov
6 weeks ago

Replying to dingo_d:

Since we have a post ID, we could add get_post_type to identify the post type? And fall back to item as a default?

A general best practice in WordPress is to avoid post type and taxonomy names in generic strings due to i18n concerns and structural differences in languages. For reference, see:

#4 @dingo_d
6 weeks ago

Oh, that makes sense. Thanks for the explanation 👍🏻

#5 @SergeyBiryukov
6 weeks ago

  • Milestone changed from Awaiting Review to 5.5

#6 @SergeyBiryukov
6 weeks ago

In 48312:

Posts, Post Types: Clarify some "Error in deleting" messages, use more specific strings for attachments.

Props dingo_d.
See #50546.

#7 @SergeyBiryukov
5 weeks ago

  • Milestone changed from 5.5 to Future Release
Note: See TracTickets for help on using tickets.