-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do redirect if amp comments_live_list support is not declared; vary comment success message by approval status #1029
Changes from 2 commits
fb649cc
6f00f20
a0fce3f
1e32d6c
5c96324
8da1a36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,10 +324,30 @@ public static function handle_xhr_request() { | |
|
||
if ( isset( $pagenow ) && 'wp-comments-post.php' === $pagenow ) { | ||
// We don't need any data, so just send a success. | ||
add_filter( 'comment_post_redirect', function() { | ||
add_filter( 'comment_post_redirect', function( $url, $comment ) { | ||
// Get theme support. | ||
$theme_support = get_theme_support( 'amp' ); | ||
|
||
// Add the comment ID to the URL to force AMP to refresh the page. | ||
$url = add_query_arg( 'comment', $comment->comment_ID, $url ); | ||
|
||
// Send redirect header if amp-live-list has been opted-out. | ||
if ( empty( $theme_support['comments_live_list'] ) ) { | ||
header( 'AMP-Redirect-To: ' . $url, true ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary because |
||
} | ||
// Create a success message to display to the user. | ||
if ( '1' === (string) $comment->comment_approved ) { | ||
$message = __( 'Your comment has been posted and has been approved.', 'amp' ); | ||
} else { | ||
$message = __( 'Your comment has been posted, and is awaiting moderation.', 'default' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This string has the We need it to keep it the same for it to re-use core translations. |
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing phpdoc. |
||
$message = apply_filters( 'amp_comment_submitted_message', $message, $comment ); | ||
|
||
// We don't need any data, so just send a success. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is no longer true. |
||
wp_send_json_success(); | ||
}, PHP_INT_MAX ); | ||
wp_send_json_success( $message ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably apply kses to this to only allow the allowed amp-mustache markup. |
||
|
||
}, PHP_INT_MAX, 2 ); | ||
self::handle_xhr_headers_output(); | ||
} elseif ( ! empty( self::$purged_amp_query_vars['_wp_amp_action_xhr_converted'] ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized that we're now not properly looking at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On further thought, I don't think the logic this function cares if |
||
add_filter( 'wp_redirect', array( __CLASS__, 'intercept_post_request_redirect' ), PHP_INT_MAX ); | ||
|
@@ -516,7 +536,7 @@ public static function add_amp_comment_form_templates() { | |
?> | ||
<div submit-success> | ||
<template type="amp-mustache"> | ||
<?php esc_html_e( 'Your comment has been posted, but may be subject to moderation.', 'amp' ); ?> | ||
{{{data}}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have a paragraph wrapping it, like for the error message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handler sends back an object with an |
||
</template> | ||
</div> | ||
<div submit-error> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work because
$theme_support
is an array of the args so it needs to be looking at$theme_support[0]['comments_live_list']