3 * Handles Comment Post to WordPress and prevents duplicate comment posting. |
3 * Handles Comment Post to WordPress and prevents duplicate comment posting. |
4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 */ |
6 */ |
7 |
7 |
8 if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) { |
8 if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
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' ), true ) ) { |
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 __DIR__ . '/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 ) ) { |
48 * @since 3.4.0 |
48 * @since 3.4.0 |
49 * @since 4.9.6 The `$cookies_consent` parameter was added. |
49 * @since 4.9.6 The `$cookies_consent` parameter was added. |
50 * |
50 * |
51 * @param WP_Comment $comment Comment object. |
51 * @param WP_Comment $comment Comment object. |
52 * @param WP_User $user Comment author's user object. The user may not exist. |
52 * @param WP_User $user Comment author's user object. The user may not exist. |
53 * @param boolean $cookies_consent Comment author's consent to store cookies. |
53 * @param bool $cookies_consent Comment author's consent to store cookies. |
54 */ |
54 */ |
55 do_action( 'set_comment_cookies', $comment, $user, $cookies_consent ); |
55 do_action( 'set_comment_cookies', $comment, $user, $cookies_consent ); |
56 |
56 |
57 $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; |
58 |
58 |
59 // Add specific query arguments to display the awaiting moderation message. |
59 // If user didn't consent to cookies, add specific query arguments to display the awaiting moderation message. |
60 if ( 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) { |
60 if ( ! $cookies_consent && 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) { |
61 $location = add_query_arg( |
61 $location = add_query_arg( |
62 array( |
62 array( |
63 'unapproved' => $comment->comment_ID, |
63 'unapproved' => $comment->comment_ID, |
64 'moderation-hash' => wp_hash( $comment->comment_date_gmt ), |
64 'moderation-hash' => wp_hash( $comment->comment_date_gmt ), |
65 ), |
65 ), |