Make WordPress Core

Opened 17 months ago

Last modified 17 months ago

#57106 new enhancement

Allowing comment form error pages

Reported by: apermo's profile apermo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch
Focuses: Cc:

Description

Current status quo:

As of now, it is not possible to have customized a customized validation for forms (covered in #57105 )

And every single error will either end in a wp_die() or an exit.

Proposal:

Instead of always ending in wp_die() we could forward to the referer page, including the error_message and the $_POST data, to prefill the form (especially with the comment, since these would be really painful if lost).

comment_form() would require an enhancement to show errors.

This idea is still in progress, I'll provide a working proof of concept later, but I wanted to open this for discussion.

Note: Will also need some kind of representation for the Rest API.

Attachments (1)

wp_comments_post.patch (878 bytes) - added by apermo 17 months ago.

Download all attachments as: .zip

Change History (3)

#1 @apermo
17 months ago

  • Type changed from defect (bug) to enhancement

#2 @apermo
17 months ago

  • Keywords has-patch added

The Patch above adds the following lines to wp-comments-posts.php.

<?php
/**
 * Fires after an comment submission ended in a WP_Error.
 *
 * Use this for logging purposes, or for forwarding to alternative direction rather than showing a wp_die.
 *
 * @since TBD
 *
 * @param WP_Error $comment The error object thrown by wp_handle_comment_submission
 */
do_action( 'comment_submission_is_error', $comment );

This would be everything needed for a theme developer (or the WordPress core itself) to provide a different mean for handling comment submission errors.
Optionally we could add a second and maybe third parameter, but that would just be $_POST and $_SERVERHTTP_REFERER? in the end, but those might provide benefits for automated testings.

By hooking a redirect to the referrer URL including an anchor and a parameter onto that action, I could perfectly display anything I want.

Note: See TracTickets for help on using tickets.