From c816b422ac718c8d53241314869256e3f8bdbc84 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Thu, 25 Jul 2024 16:19:39 -0700 Subject: [PATCH 1/5] Fix: jetpack comments from Chrome --- .../jetpack/modules/comments/comments.php | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/modules/comments/comments.php b/projects/plugins/jetpack/modules/comments/comments.php index 8dcbdd453f1e1..8e72b523a42e1 100644 --- a/projects/plugins/jetpack/modules/comments/comments.php +++ b/projects/plugins/jetpack/modules/comments/comments.php @@ -620,12 +620,14 @@ public function pre_comment_on_post() { // Bail if missing the Jetpack token. if ( ! isset( $post_array['sig'] ) || ! isset( $post_array['token_key'] ) ) { unset( $_POST['hc_post_as'] ); - return; } if ( empty( $post_array['jetpack_comments_nonce'] ) || ! wp_verify_nonce( $post_array['jetpack_comments_nonce'], "jetpack_comments_nonce-{$post_array['comment_post_ID']}" ) ) { - wp_die( esc_html__( 'Nonce verification failed.', 'jetpack' ), 400 ); + if ( ! isset( $_GET['only_once'] ) ) { + self::retry_submit_comment_form_locally(); + } + wp_die( esc_html__( 'Nonce verification failed.', 'jetpack' ), 400 ); } if ( str_contains( $post_array['hc_avatar'], '.gravatar.com' ) ) { @@ -655,6 +657,54 @@ public function pre_comment_on_post() { } } + /** + * Handle Jetpack Comments POST requests: process the comment form, then client-side POST the results to the self-hosted blog + * + * This function exists because when we submit the form via the jetpack.wordpress.com iframe + * in Chrome the request comes in to jetpack but for some reason the request doesn't hace access to cookies yet. + * By submitting the form again locally with the same data the process works as expected. + */ + public function retry_submit_comment_form_locally() { + // We are not doing any valiodation here since all the validation will be done again by pre_comment_on_post(). + // if the comment has been posted, this is where we do our service verification checks + $comment_data = stripslashes_deep( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing + ?> + + + + + + <?php echo esc_html__( 'Submitting Comment', 'jetpack' ); ?> + + + + +
+ $val ) : ?> + + +
+ + + + + Date: Thu, 25 Jul 2024 16:27:41 -0700 Subject: [PATCH 2/5] changelog --- .../plugins/jetpack/changelog/fix-jetpack-comments-chrome | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/fix-jetpack-comments-chrome diff --git a/projects/plugins/jetpack/changelog/fix-jetpack-comments-chrome b/projects/plugins/jetpack/changelog/fix-jetpack-comments-chrome new file mode 100644 index 0000000000000..8ab62fae2aafa --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-jetpack-comments-chrome @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Jetpack Comments: fix replying to comments in chrome when logged in to both wordpress.com and the jetpack site From 8655b69c52e31a41eed70407e149adf25c6474e2 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Fri, 26 Jul 2024 11:30:16 -0700 Subject: [PATCH 3/5] Add never return type --- projects/plugins/jetpack/modules/comments/comments.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/plugins/jetpack/modules/comments/comments.php b/projects/plugins/jetpack/modules/comments/comments.php index 8e72b523a42e1..8e66ac9b2d1f5 100644 --- a/projects/plugins/jetpack/modules/comments/comments.php +++ b/projects/plugins/jetpack/modules/comments/comments.php @@ -663,6 +663,8 @@ public function pre_comment_on_post() { * This function exists because when we submit the form via the jetpack.wordpress.com iframe * in Chrome the request comes in to jetpack but for some reason the request doesn't hace access to cookies yet. * By submitting the form again locally with the same data the process works as expected. + * + * @return never */ public function retry_submit_comment_form_locally() { // We are not doing any valiodation here since all the validation will be done again by pre_comment_on_post(). From cff1767856f8fd159a32e7cfd511aa0143aadb15 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Mon, 29 Jul 2024 07:33:51 -0700 Subject: [PATCH 4/5] Update projects/plugins/jetpack/modules/comments/comments.php Fix wording Co-authored-by: Karen Attfield --- projects/plugins/jetpack/modules/comments/comments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/modules/comments/comments.php b/projects/plugins/jetpack/modules/comments/comments.php index 8e66ac9b2d1f5..56075fc3a624e 100644 --- a/projects/plugins/jetpack/modules/comments/comments.php +++ b/projects/plugins/jetpack/modules/comments/comments.php @@ -661,7 +661,7 @@ public function pre_comment_on_post() { * Handle Jetpack Comments POST requests: process the comment form, then client-side POST the results to the self-hosted blog * * This function exists because when we submit the form via the jetpack.wordpress.com iframe - * in Chrome the request comes in to jetpack but for some reason the request doesn't hace access to cookies yet. + * in Chrome the request comes in to Jetpack but for some reason the request doesn't have access to cookies yet. * By submitting the form again locally with the same data the process works as expected. * * @return never From 7e95abd5bf537208eced6dd7fdc61f5b07beba76 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Mon, 29 Jul 2024 10:19:21 -0700 Subject: [PATCH 5/5] Fix comment --- projects/plugins/jetpack/modules/comments/comments.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/modules/comments/comments.php b/projects/plugins/jetpack/modules/comments/comments.php index 56075fc3a624e..4a40011a86952 100644 --- a/projects/plugins/jetpack/modules/comments/comments.php +++ b/projects/plugins/jetpack/modules/comments/comments.php @@ -667,9 +667,9 @@ public function pre_comment_on_post() { * @return never */ public function retry_submit_comment_form_locally() { - // We are not doing any valiodation here since all the validation will be done again by pre_comment_on_post(). - // if the comment has been posted, this is where we do our service verification checks - $comment_data = stripslashes_deep( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing + // We are not doing any validation here since all the validation will be done again by pre_comment_on_post(). + // phpcs:ignore WordPress.Security.NonceVerification.Missing + $comment_data = stripslashes_deep( $_POST ); ?>