9 $protocol = $_SERVER['SERVER_PROTOCOL']; |
9 $protocol = $_SERVER['SERVER_PROTOCOL']; |
10 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) { |
10 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) { |
11 $protocol = 'HTTP/1.0'; |
11 $protocol = 'HTTP/1.0'; |
12 } |
12 } |
13 |
13 |
14 header('Allow: POST'); |
14 header( 'Allow: POST' ); |
15 header("$protocol 405 Method Not Allowed"); |
15 header( "$protocol 405 Method Not Allowed" ); |
16 header('Content-Type: text/plain'); |
16 header( 'Content-Type: text/plain' ); |
17 exit; |
17 exit; |
18 } |
18 } |
19 |
19 |
20 /** Sets up the WordPress Environment. */ |
20 /** Sets up the WordPress Environment. */ |
21 require( dirname(__FILE__) . '/wp-load.php' ); |
21 require( dirname( __FILE__ ) . '/wp-load.php' ); |
22 |
22 |
23 nocache_headers(); |
23 nocache_headers(); |
24 |
24 |
25 $comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); |
25 $comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); |
26 if ( is_wp_error( $comment ) ) { |
26 if ( is_wp_error( $comment ) ) { |
27 $data = intval( $comment->get_error_data() ); |
27 $data = intval( $comment->get_error_data() ); |
28 if ( ! empty( $data ) ) { |
28 if ( ! empty( $data ) ) { |
29 wp_die( '<p>' . $comment->get_error_message() . '</p>', __( 'Comment Submission Failure' ), array( 'response' => $data, 'back_link' => true ) ); |
29 wp_die( |
|
30 '<p>' . $comment->get_error_message() . '</p>', |
|
31 __( 'Comment Submission Failure' ), |
|
32 array( |
|
33 'response' => $data, |
|
34 'back_link' => true, |
|
35 ) |
|
36 ); |
30 } else { |
37 } else { |
31 exit; |
38 exit; |
32 } |
39 } |
33 } |
40 } |
34 |
41 |
35 $user = wp_get_current_user(); |
42 $user = wp_get_current_user(); |
36 $cookies_consent = ( isset( $_POST['wp-comment-cookies-consent'] ) ); |
43 $cookies_consent = ( isset( $_POST['wp-comment-cookies-consent'] ) ); |
37 |
44 |
38 /** |
45 /** |
39 * Perform other actions when comment cookies are set. |
46 * Perform other actions when comment cookies are set. |
40 * |
47 * |
47 */ |
54 */ |
48 do_action( 'set_comment_cookies', $comment, $user, $cookies_consent ); |
55 do_action( 'set_comment_cookies', $comment, $user, $cookies_consent ); |
49 |
56 |
50 $location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID; |
57 $location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID; |
51 |
58 |
|
59 // Add specific query arguments to display the awaiting moderation message. |
|
60 if ( 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) { |
|
61 $location = add_query_arg( |
|
62 array( |
|
63 'unapproved' => $comment->comment_ID, |
|
64 'moderation-hash' => wp_hash( $comment->comment_date_gmt ), |
|
65 ), |
|
66 $location |
|
67 ); |
|
68 } |
|
69 |
52 /** |
70 /** |
53 * Filters the location URI to send the commenter after posting. |
71 * Filters the location URI to send the commenter after posting. |
54 * |
72 * |
55 * @since 2.0.5 |
73 * @since 2.0.5 |
56 * |
74 * |