[wp-hackers] Phasing out use of wp_die() for comment errors

John Blackbourn johnbillion+wp at gmail.com
Tue Nov 23 01:33:28 UTC 2010


I'd like to see what people think about replacing wp_die() for comment
errors with something a bit more graceful.

Here are the three potential errors that can occur when a comment is posted:

 * Missing required fields
 * Duplicate comment detected
 * Posting comments too quickly

These are currently handled by wp_die(). This isn't a user friendly
experience as it stops the user dead in their tracks and by default
they have to use browser navigation to return to where they were.

It is possible to override the wp_die_handler function so themes can
make this a little more user friendly, but it's still not great. What
would be ideal would be to return the user to the page they came from
(in most cases the post permalink) and show a helpful error message
within context.

What are people's thoughts on how we could go about phasing out using
wp_die() in this situation? I'm thinking it would be something that a
theme would add support for. For example:

add_theme_support( 'error-handlers');

That might need a better name, but you get the idea. The theme would
then handle displaying errors (at the top of the page in a big yellow
box, for example).

Two ways this could be done:

 1. Redirect the browser back to the post permalink with an error code
query var appended which maps to a list of predefined, filterable
error messages (much like the 'message' query var used in the admin
area).
 2. Instead of using 'wp-comments-post.php' for the comment form
action, we could switch to using the post permalink (the form for
password protected posts uses this). This would allow us to continue
execution and use the $_POST data to repopulate the comment form
fields when required fields were missing.

I had a look through Trac to see if anything to do with wp_die() had
been discussed recently, but didn't spot anything.

Thoughts?

John


More information about the wp-hackers mailing list