3 * Handles Comment Post to WordPress and prevents duplicate comment posting.
8 if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
10 header('HTTP/1.1 405 Method Not Allowed');
11 header('Content-Type: text/plain');
15 /** Sets up the WordPress Environment. */
16 require( dirname(__FILE__) . '/wp-load.php' );
20 $comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
21 if ( is_wp_error( $comment ) ) {
22 $data = $comment->get_error_data();
23 if ( ! empty( $data ) ) {
24 wp_die( $comment->get_error_message(), $data );
30 $user = wp_get_current_user();
33 * Perform other actions when comment cookies are set.
37 * @param WP_Comment $comment Comment object.
38 * @param WP_User $user User object. The user may not exist.
40 do_action( 'set_comment_cookies', $comment, $user );
42 $location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
45 * Filter the location URI to send the commenter after posting.
49 * @param string $location The 'redirect_to' URI sent via $_POST.
50 * @param WP_Comment $comment Comment object.
52 $location = apply_filters( 'comment_post_redirect', $location, $comment );
54 wp_safe_redirect( $location );